麻将游戏算法深入解析及实现代码
发布时间:2020-12-31 18:25:35 所属栏目:经验 来源:网络整理
导读:麻将游戏算法深入解析及实现代码 这两天为了工具箱的完善,整理了这些年引擎开发的一些资料,无意中发现06年写的一个麻将算法,编译运行了一下,还是有点意思的,拿出来整理一下分享给大家。 麻将是一种大家最喜爱的娱乐活动之一,相信所有人都有接触过。我
OUTPai2:
cout<<"请打牌(输入牌序号)";
int PaiIndex;
cin>>PaiIndex;
if(t_MyPlayer.DelPai(PaiIndex)==false)
{
cout<<"没有此牌"<<endl;
goto OUTPai2;
}
//=================================牌面刷新=============================================
cout<<"牌面刷新============================"<<endl;
t_MyPlayer.PrintAllPai();
cout<<endl;
//==============================================================================
//======================包听========================================================
if(t_MyPlayer.CheckAllPai(MJPAI_PUTPAI))
{
char t_BTing;
cout<<"要包听吗?:(Y/N)";
cin>>t_BTing;
if(t_BTing=='y'||t_BTing=='Y')
{
t_Ting = true;
}
}
//==============================================================================
//该我下家
j = -1;
}
else if(t_Result =='2')//碰牌
{
t_MyPlayer.PrintPengChosePai();
t_MyPlayer.DoPengPai(t_Pai2.m_NewPai.m_Type,t_Pai2.m_NewPai.m_Value);
//==============================================================================
cout<<"牌面刷新============================"<<endl;
t_MyPlayer.PrintAllPai();
cout<<endl;
//==============================================================================
OUTPai3:
cout<<"请打牌(输入牌序号)";
int PaiIndex;
cin>>PaiIndex;
if(t_MyPlayer.DelPai(PaiIndex)==false)
{
cout<<"没有此牌"<<endl;
goto OUTPai3;
}
//==========================牌面刷新====================================================
cout<<"牌面刷新============================"<<endl;
t_MyPlayer.PrintAllPai();
cout<<endl;
//==============================================================================
//======================包听========================================================
if(t_MyPlayer.CheckAllPai(MJPAI_PUTPAI))
{
char t_BTing;
cout<<"要包听吗?:(Y/N)";
cin>>t_BTing;
if(t_BTing=='y'||t_BTing=='Y')
{
t_Ting = true;
}
}
//==============================================================================
j = -1;
}
else if(t_Result =='3')//杠牌
{
t_MyPlayer.PrintGangChosePai();
t_MyPlayer.DoGangPai(t_Pai2.m_NewPai.m_Type,t_Pai2.m_NewPai.m_Value);
cout<<"起杠底牌"<<endl;
t_MyPlayer.AddPai(t_Pai2.m_NewPai.m_Type,t_Pai2.m_NewPai.m_Value);
//==============================================================================
cout<<"牌面刷新============================"<<endl;
t_MyPlayer.PrintAllPai();
cout<<endl;
//==============================================================================
stPAIEx t_Pai2 = t_MJManage.GetAPai();
//起牌后胡牌判断
t_Finish = t_MyPlayer.CheckAllPai(MJPAI_GETPAI);
if(t_Finish)
{
cout<<"杠底花吗?(Y/N)"<<endl;
char t_Result;
cin>>t_Result;
if(t_Result =='Y'||t_Result=='y')
{
cout<<endl;
printf("胡啦!!!:%s-%d",t_MyPlayer.GetInfo()->m_GoodValue);
t_Score += t_MyPlayer.GetInfo()->m_GoodValue;
::_sleep(1000);
break;
}
}
if(t_Pai2.m_IsHZ)//如果起牌数已达到上限
{
cout<<"黄庄了!!!!!!!!!!!!!"<<endl;
t_Finish = true;
break;
}
OUTPai4:
cout<<"请打牌(输入牌序号)";
int PaiIndex;
cin>>PaiIndex;
if(t_MyPlayer.DelPai(PaiIndex)==false)
{
cout<<"没有此牌"<<endl;
goto OUTPai4;
}
//===========================牌面刷新===================================================
cout<<"牌面刷新============================"<<endl;
t_MyPlayer.PrintAllPai();
cout<<endl;
//==============================================================================
//======================包听========================================================
if(t_MyPlayer.CheckAllPai(MJPAI_PUTPAI))
{
char t_BTing;
cout<<"要包听吗?:(Y/N)";
cin>>t_BTing;
if(t_BTing=='y'||t_BTing=='Y')
{
t_Ting = true;
}
}
//==============================================================================
//该我下家
j = -1;
}
else if(t_Result =='4')//胡牌
{
//起牌
t_MyPlayer.AddPai(t_Pai2.m_NewPai.m_Type,t_Pai2.m_NewPai.m_Value);
//起牌后胡牌判断
t_Finish = t_MyPlayer.CheckAllPai(MJPAI_GETPAI);
if(t_Finish)
{
printf("胡啦!!!:%s-合计%d番",t_MyPlayer.GetInfo()->m_GoodValue);
t_Score += t_MyPlayer.GetInfo()->m_GoodValue;
::_sleep(1000);
break;
}
else
{
if(t_Pai2.m_IsHZ)//如果起牌数已达到上限
{
cout<<"黄庄了!!!!!!!!!!!!!"<<endl;
t_Finish = true;
break;
}
//起牌
int iPaiIndex = t_MyPlayer.GetPaiIndex(t_Pai2.m_NewPai.m_Type,t_Pai2.m_NewPai.m_Value);
cout<<endl;
t_MyPlayer.DelPai(iPaiIndex);
}
}
}
}
cout<<"我的分数:"<<t_Score<<endl;
::_sleep(3000);
goto GameStart;//重新开始一局
return 0;
}
OK,麻将就这样实现了,你可以将其任意修改一下变形成你喜欢的麻将游戏,我很开心这个代码能再次焕发青春,在此谢谢你。 (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |

