java语言麻将游戏代码_麻将游戏算法深入解析及实现代码

麻将游戏算法深入解析及实现代码

这两天为了工具箱的完善,整理了这些年引擎开发的一些资料,无意中发现06年写的一个麻将算法,编译运行了一下,还是有点意思的,拿出来整理一下分享给大家。

麻将是一种大家最喜爱的娱乐活动之一,相信所有人都有接触过。我写的这版算法,是可以吃,碰,杠,还有把牌摸完没有人胡时的皇庄和包听。是用控制台方式来表现的,什么?控制台?

对,因为是算法的设计,所以用控制台来表现当然最简单了。

16e05c5cf868d54d887b1db9a71043fa.png

当然,在交互时要用文字输入会有少许不便,不过这种形式的游戏可是图形游戏的鼻祖哦~

好,废话不多说了,来说一下设计思路:

对于麻将的一个玩家,都有一个牌墙的管理,这里封装了一副牌墙的各种算法,这个类我命名为CMJ。

另外还有一个洗牌类,负责洗牌和发牌。这个类为CMJManage。

我们先来看一下CMJ类。

CMJ.h:

#ifndef _CMJ_H

#define _CMJ_H

//============================================

//Author:Honghaier

//Date:2006-12-20

//QQ:285421210

//============================================

#include

#include

#include

#include

using namespace std;

#define MJPAI_ZFB 0 //中,发,白

#define MJPAI_FENG 1 //东西南北风

#define MJPAI_WAN 2 //万

#define MJPAI_TIAO 3 //条

#define MJPAI_BING 4 //饼

#define MJPAI_HUA 5 //花

#define MJPAI_GETPAI true //起牌

#define MJPAI_PUTPAI false //打牌

//节点信息

struct stPAI

{

int m_Type; //牌类型

int m_Value; //牌字

}

;

//吃牌顺

struct stCHI

{

int m_Type; //牌类型

int m_Value1; //牌字

int m_Value2; //牌字

int m_Value3; //牌字

}

;

// m_Type m_Value

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-//

// 0 | 中 1 发2 白

// |

// 1 | 东 1 西2 南 北

// |

// 2 | 一万 二万 …… 九万

// |

// 3 | 一条 二条 …… 九条

// |

// 4 | 一饼 二饼 …… 九饼

// |

// 5 | 春 夏 秋 东 竹 兰 梅 菊

// |

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-//

//胡牌信息

struct stGoodInfo

{

char m_GoodName[100]; //胡牌术语

int m_GoodValue; //胡牌番数

}

;

//牌

class CMJ

{

vector< int > m_MyPAIVec[6]; //起的种牌型

vector< int > m_ChiPAIVec[6]; //吃的种牌型

vector< int > m_PengPAIVec[6]; //碰的种牌型

vector< int > m_GangPAIVec[6]; //杠的种牌型

stPAI m_LastPAI; //最后起的牌

stGoodInfo m_GoodInfo; //胡牌信息

bool m_9LBD; //是否听连宝灯牌型

bool m_13Y; //是否听十三幺

int m_MKNum; //明刻数

int m_AKNum; //暗刻数

bool m_4AK; //是否是听四暗刻

vector< stCHI > m_TempChiPAIVec; //吃的可选组合

vector< stPAI > m_TempPengPAIVec; //碰的可选组合

vector< stPAI > m_TempGangPAIVec; //杠的可选组合

public:

//构造

CMJ();

//析构

~CMJ();

//初始化

void Init();

//起牌

bool AddPai(int p_Type,int p_Value);

//取得对应的牌在牌墙的索引

int GetPaiIndex(int p_Type,int p_Value);

//打牌(参数为对应的牌在牌墙的索引)

bool DelPai(int PaiIndex);

//删除牌

bool DelPai(int p_Type,int p_Value);

//清空牌

void CleanUp();

//取得胡牌信息

stGoodInfo *GetInfo();

//检测是否胡牌

bool CheckAllPai(bool GetOrPut);

//对所有的牌进行输出

void PrintAllPai();

//对一张牌进行输出

void PrintPai(int p_Type,int p_Value);

//吃牌

bool CheckChiPai(int p_Type,int p_Value);

//吃牌

bool DoChiPai(int p_iIndex,int p_Type,int p_Value);

//碰牌

bool CheckPengPai(int p_Type,int p_Value);

//碰牌

bool DoPengPai(int p_Type,int p_Value);

//杠牌

bool CheckGangPai(int p_Type,int p_Value);

//杠牌

bool DoGangPai(int p_Type,int p_Value);

//对可吃的组合进行输出

void PrintChiChosePai();

//对可碰的组合进行输出

void PrintPengChosePai();

//对可杠的组合进行输出

void PrintGangChosePai();

//取得吃牌组合数

UINT GetChiChoseNum();

private:

//检测是否胡牌(张)

bool CheckAAPai(int iValue1,int iValue2);

//检测是否三连张

bool CheckABCPai(int iValue1,int iValue2,int iValu3);

//检测是否三重张

bool CheckAAAPai(int iValue1,int iValue2,int iValu3);

//检测是否四重张

bool CheckAAAAPai(int iValue1,int iValue2,int iValu3,int iValue4);

//检测是否三连对

bool CheckAABBCCPai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6);

//检测是否三连高压

bool CheckAAABBBCCCPai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6,int iValue7,int iValue8,int iValue9);

//检测是否三连刻

bool CheckAAAABBBBCCCCPai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6,int iValue7,int iValue8,int iValue9,int iValue10,int iValue11,int iValue12);

//检测是否六连对

bool CheckAABBCCDDEEFFPai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6,int iValue7,int iValue8,int iValue9,int iValue10,int iValue11,int iValue12);

//带将牌检测=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

//检测是否胡牌(张)

bool Check5Pai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5);

//检测是否胡牌(张)

bool Check8Pai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6,int iValue7,int iValue8);

//检测是否胡牌(张)

bool Check11Pai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6,int iValue7,int iValue8,int iValue9,int iValue10,int iValue11);

//检测是否胡牌(张)

bool Check14Pai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6,int iValue7,int iValue8,int iValue9,int iValue10,int iValue11,int iValue12,int iValue13,int iValue14);

//不带将牌检测-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

//检测是否胡牌(张)

bool Check3Pai(int iValue1,int iValue2,int iValue3);

//检测是否胡牌(张)

bool Check6Pai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6);

//检测是否胡牌(张)

bool Check9Pai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6,int iValue7,int iValue8,int iValue9);

//检测是否胡牌(张)

bool Check12Pai(int iValue1,int iValue2,int iValue3,int iValue4,int iValue5,int iValue6,int iValue7,int iValue8,int iValue9,int iValue10,int iValue11,int iValue12);

private:

//胡牌判断

//检测是否胡大四喜

bool CheckD4X_HU();

//检则是否胡大三元

bool CheckD3Y_HU();

//检测是否胡绿一色

bool CheckL1S_HU();

//检测是否胡九莲宝灯

bool Check9LBD_HU();

//检测是否胡四杠

bool Check4Gang_HU();

//检测是否胡连七对

bool CheckL7D_HU();

//检测是否胡十三幺

bool Chekc13Y_HU();

//检测是否胡清幺九

bool CheckQY9_HU();

//检测是否胡小四喜

bool CheckX4X_HU();

//检测是否胡小三元

bool CheckX3Y_HU();

//检测是否胡字一色

bool CheckZ1S_HU();

//检测是否四暗刻

bool Check4AK_HU();

//检测是否一色双龙会

bool Check1S2LH_HU();

//检测是否一色四同顺

bool Check1S4TS_HU();

//检测是否一色四节高?

bool Check1S4JG_HU();

//检测是否一色四步高?

bool Check1S4BG_HU();

//检测是否三杠

bool Check3Gang_HU();

//检测是否混幺九

bool CheckHY9_HU();

//检测是否七对

bool Check7D_HU();

//检测是否七星不靠

bool Check7XBK_HU();

//检测是否全双刻?

bool CheckQSK_HU();

//清一色

bool CheckQ1S_HU();

//检测是否一色三同顺

bool Check1S3TS_HU();

//检测是否一色三节高

bool Check1S3JG_HU();

//检测是否全大

bool CheckQD_HU();

//检测是否全中

bool CheckQZ_HU();

//检测是否全小

bool CheckQX_HU();

//检测是否青龙

bool CheckQL_HU();

//检测是否三色双龙会

bool Check3S2LH_HU();

//检测是否一色三步高

bool Check1S3BG_HU();

//全带五

bool CheckQD5_HU();

//三同刻

bool Check3TK_HU();

//三暗刻

bool Check3AK_HU();

//单钓将

bool CheckDDJ_HU();

//检测胡

bool CheckHU();

private:

//听牌判断

//检测是否听九莲宝灯

bool Check9LBD_TING();

//检测是否听十三幺

bool Check13Y_TING();

//检测是否听四暗刻

bool Check4AK_TING();

//检测是否听牌

bool CheckTING();

}

;

#endif

其对应的CPP :

#include "CMJ.h"

//构造

CMJ::CMJ()

{

m_9LBD = false;

m_13Y = false;

m_4AK = false;

m_AKNum = 0;

m_MKNum = 0;

}

//析构

CMJ::~CMJ()

{

}

//初始化

void CMJ::Init()

{

m_9LBD = false;

m_13Y = false;

m_4AK = false;

m_AKNum = 0;

m_MKNum = 0;

}

//加入新牌,并排序

bool CMJ::AddPai(int p_Type,int p_Value)

{

int iSize = m_MyPAIVec[p_Type].size();

bool t_Find = false;

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[p_Type].begin();Iter !=m_MyPAIVec[p_Type].end(); Iter++)

{

if((*Iter)>p_Value)

{

m_MyPAIVec[p_Type].insert(Iter,p_Value);

t_Find = true;

break;

}

}

if(t_Find==false)

{

m_MyPAIVec[p_Type].push_back(p_Value);

}

m_LastPAI.m_Type = p_Type;

m_LastPAI.m_Value = p_Value;

return true;

}

//取得对应的牌在牌墙的索引

int CMJ::GetPaiIndex(int p_Type,int p_Value)

{

int count = 0;

for(UINT i = 0 ; i < 6 ; i++ )

{

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[i].begin();Iter !=m_MyPAIVec[i].end(); Iter++)

{

if(p_Type==i&&(*Iter)==p_Value)

{

return count;

}

count++;

}

}

return -1;

}

//打牌

bool CMJ::DelPai(int PaiIndex)

{

int count = 0;

for(UINT i = 0 ; i < 6 ; i++ )

{

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[i].begin();Iter !=m_MyPAIVec[i].end(); Iter++)

{

if(count==PaiIndex)

{

m_MyPAIVec[i].erase(Iter);

return true;

}

count++;

}

}

return false;

}

//删除牌

bool CMJ::DelPai(int p_Type,int p_Value)

{

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[p_Type].begin();Iter !=m_MyPAIVec[p_Type].end(); Iter++)

{

if((*Iter)==p_Value)

{

m_MyPAIVec[p_Type].erase(Iter);

return true;

}

}

return false;

}

//清空牌

void CMJ::CleanUp()

{

for(UINT i = 0 ; i < 6 ; i++ )

{

m_MyPAIVec[i].clear();

m_ChiPAIVec[i].clear();

m_PengPAIVec[i].clear();

m_GangPAIVec[i].clear();

}

}

//取得胡牌信息

stGoodInfo *CMJ::GetInfo()

{

return &m_GoodInfo;

}

//对所有的牌进行函数调用

void CMJ::PrintAllPai()

{

cout<

for(UINT i = 0 ; i < 13 ; i++ )

{

cout<

}

cout<

int icount = 0;

//箭牌

if(m_MyPAIVec[0].empty()==false)

{

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[0].begin();Iter !=m_MyPAIVec[0].end(); Iter++)

{

switch(*Iter)

{

case 1:

cout<

break;

case 2:

cout<

break;

case 3:

cout<

break;

}

icount++;

}

}

cout<

for(UINT i =0 ; i < icount; i++ )

{

cout<

}

//风牌

if(m_MyPAIVec[1].empty()==false)

{

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[1].begin();Iter !=m_MyPAIVec[1].end(); Iter++)

{

switch(*Iter)

{

case 1:

cout<

break;

case 2:

cout<

break;

case 3:

cout<

break;

case 4:

cout<

break;

}

icount++;

}

}

cout<

for(UINT i =0 ; i < icount; i++ )

{

cout<

}

//万

if(m_MyPAIVec[2].empty()==false)

{

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[2].begin();Iter !=m_MyPAIVec[2].end(); Iter++)

{

cout<

icount++;

}

}

cout<

for(UINT i =0 ; i < icount; i++ )

{

cout<

}

//条

if(m_MyPAIVec[3].empty()==false)

{

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[3].begin();Iter !=m_MyPAIVec[3].end(); Iter++)

{

cout<

icount++;

}

}

cout<

for(UINT i =0 ; i < icount; i++ )

{

cout<

}

//饼

if(m_MyPAIVec[4].empty()==false)

{

vector< int >::iterator Iter;

for(Iter = m_MyPAIVec[4].begin();Iter !=m_MyPAIVec[4].end(); Iter++)

{

cout<

icount++;

}

}

cout<

for(UINT i =0 ; i < icount; i++ )

{

cout<

}

}

//对一张牌进行输出

void CMJ::PrintPai(int p_Type,int p_Value)

{

//箭牌

if(p_Type==0)

{

switch(p_Value)

{

case 1:

cout<

break;

case 2:

cout<

break;

case 3:

cout<

break;

}

}

//风牌

if(p_Type==1)

{

switch(p_Value)

{

case 1:

cout<

break;

case 2:

cout<

break;

case 3:

cout<

break;

case 4:

cout<

break;

}

}

//万

if(p_Type==2)

{

cout<

}

//条

if(p_Type==3)

{

cout<

}

//饼

if(p_Type==4)

{

cout<

}

}

//吃牌

bool CMJ::CheckChiPai(int p_Type,int p_Value)

{

m_TempChiPAIVec.clear();

//饼

if(m_MyPAIVec[p_Type].empty()==false)

{

int iSize = m_MyPAIVec[p_Type].size();

if( iSize >= 2)

{

for(UINT i = 0 ; i < iSize-1 ; i++ )

{

if((m_MyPAIVec[p_Type][i]==(p_Value-2))&&(m_MyPAIVec[p_Type][i+1]==(p_Value-1)))

{

stCHI t_Chi;

t_Chi.m_Type = p_Type;

t_Chi.m_Value1 = p_Value-2;

t_Chi.m_Value2 = p_Value-1;

t_Chi.m_Value3 = p_Value;

m_TempChiPAIVec.push_back(t_Chi);

}

if((m_MyPAIVec[p_Type][i]==(p_Value-1))&&(m_MyPAIVec[p_Type][i+1]==(p_Value+1)))

{

stCHI t_Chi;

t_Chi.m_Type = p_Type;

t_Chi.m_Value1 = p_Value-1;

t_Chi.m_Value2 = p_Value;

t_Chi.m_Value3 = p_Value+1;

m_TempChiPAIVec.push_back(t_Chi);

}

if((m_MyPAIVec[p_Type][i]==(p_Value+1))&&(m_MyPAIVec[p_Type][i+1]==(p_Value+2)))

{

stCHI t_Chi;

t_Chi.m_Type = p_Type;

t_Chi.m_Value1 = p_Value;

t_Chi.m_Value2 = p_Value+1;

t_Chi.m_Value3 = p_Value+2;

m_TempChiPAIVec.push_back(t_Chi);

}

}

}

//假设吃B,已有ABC

if( iSize >= 3)

{

for(UINT i = 1 ; i < iSize-1 ; i++ )

{

if((m_MyPAIVec[p_Type][i-1]==(p_Value-1))&&(m_MyPAIVec[p_Type][i]==p_Value)&&(m_MyPAIVec[p_Type][i+1]==(p_Value+1)))

{

stCHI t_Chi;

t_Chi.m_Type = p_Type;

t_Chi.m_Value1 = p_Value-1;

t_Chi.m_Value2 = p_Value;

t_Chi.m_Value3 = p_Value+1;

m_TempChiPAIVec.push_back(t_Chi);

}

}

}

//假设吃B,已有ABBC

if( iSize >= 4)

{

for(UINT i = 1 ; i < iSize-2 ; i++ )

{

if((m_MyPAIVec[p_Type][i-1]==(p_Value-1))&&(m_MyPAIVec[p_Type][i]==p_Value)&&(m_MyPAIVec[p_Type][i+2]==(p_Value+1)))

{

stCHI t_Chi;

t_Chi.m_Type = p_Type;

t_Chi.m_Value1 = p_Value-1;

t_Chi.m_Value2 = p_Value;

t_Chi.m_Value3 = p_Value+1;

m_TempChiPAIVec.push_back(t_Chi);

}

}

}

//假设吃B,已有ABBBC

if( iSize >= 5)

{

for(UINT i = 1 ; i < iSize-3 ; i++ )

{

if((m_MyPAIVec[p_Type][i-1]==(p_Value-1))&&(m_MyPAIVec[p_Type][i]==p_Value)&&(m_MyPAIVec[p_Type][i+3]==(p_Value+1)))

{

stCHI t_Chi;

t_Chi.m_Type = p_Type;

t_Chi.m_Value1 = p_Value-1;

t_Chi.m_Value2 = p_Value;

t_Chi.m_Value3 = p_Value+1;

m_TempChiPAIVec.push_back(t_Chi);

}

}

}

//假设吃B,已有ABBBBC

if( iSize >= 6)

{

for(UINT i = 1 ; i < iSize-4 ; i++ )

{

if((m_MyPAIVec[p_Type][i-1]==(p_Value-1))&&(m_MyPAIVec[p_Type][i]==p_Value)&&(m_MyPAIVec[p_Type][i+4]==(p_Value+1)))

{

stCHI t_Chi;

t_Chi.m_Type = p_Type;

t_Chi.m_Value1 = p_Value-1;

t_Chi.m_Value2 = p_Value;

t_Chi.m_Value3 = p_Value+1;

m_TempChiPAIVec.push_back(t_Chi);

}

}

}

if(m_TempChiPAIVec.size() > 0)

{

return true;

}

}

return false;

}

//吃牌

bool CMJ::DoChiPai(int p_iIndex,int p_Type,int p_Value)

{

AddPai(p_Type,p_Value);

vector::iterator Iter;

int icount = 0;

for(Iter = m_TempChiPAIVec.begin(); Iter != m_TempChiPAIVec.end(); Iter++ )

{

if(icount == p_iIndex)

{

DelPai((*Iter).m_Type,(*Iter).m_Value1);

DelPai((*Iter).m_Type,(*Iter).m_Value2);

DelPai((*Iter).m_Type,(*Iter).m_Value3);

m_ChiPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value1);

m_ChiPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value2);

m_ChiPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value3);

return true;

}

icount++;

}

return false;

}

//对可吃的组合进行输出

void CMJ::PrintChiChosePai()

{

cout<

vector::iterator Iter;

for(Iter = m_TempChiPAIVec.begin(); Iter != m_TempChiPAIVec.end();Iter++)

{

//万

if((*Iter).m_Type==2)

{

cout<

cout<

cout<

}

//条

if((*Iter).m_Type==3)

{

cout<

cout<

cout<

}

//饼

if((*Iter).m_Type==4)

{

cout<

cout<

cout<

}

}

cout<

}

//对可碰的组合进行输出

void CMJ::PrintPengChosePai()

{

cout<

vector::iterator Iter;

for(Iter = m_TempPengPAIVec.begin(); Iter != m_TempPengPAIVec.end();Iter++)

{

//万

if((*Iter).m_Type==2)

{

cout<

cout<

cout<

}

//条

if((*Iter).m_Type==3)

{

cout<

cout<

cout<

}

//饼

if((*Iter).m_Type==4)

{

cout<

cout<

cout<

}

}

cout<

}

//对可杠的组合进行输出

void CMJ::PrintGangChosePai()

{

cout<

vector::iterator Iter;

for(Iter = m_TempGangPAIVec.begin(); Iter != m_TempGangPAIVec.end();Iter++)

{

//万

if((*Iter).m_Type==2)

{

cout<

cout<

cout<

cout<

}

//条

if((*Iter).m_Type==3)

{

cout<

cout<

cout<

cout<

}

//饼

if((*Iter).m_Type==4)

{

cout<

cout<

cout<

cout<

}

}

cout<

}

//取得吃牌组合数

UINT CMJ::GetChiChoseNum()

{

return m_TempChiPAIVec.size();

}

//碰牌

bool CMJ::CheckPengPai(int p_Type,int p_Value)

{

m_TempPengPAIVec.clear();

//饼

if(m_MyPAIVec[p_Type].empty()==false)

{

int iSize = m_MyPAIVec[p_Type].size();

if( iSize >= 2)

{

for(UINT i = 0 ; i < iSize-1 ; i++ )

{

if((m_MyPAIVec[p_Type][i]==p_Value)&&(m_MyPAIVec[p_Type][i+1]==p_Value))

{

stPAI t_Peng;

t_Peng.m_Type = p_Type;

t_Peng.m_Value = p_Value;

m_TempPengPAIVec.push_back(t_Peng);

break;

}

}

}

if(m_TempPengPAIVec.size() > 0)

{

return true;

}

}

return false;

}

//碰牌

bool CMJ::DoPengPai(int p_Type,int p_Value)

{

AddPai(p_Type,p_Value);

vector::iterator Iter;

for(Iter = m_TempPengPAIVec.begin(); Iter != m_TempPengPAIVec.end(); Iter++ )

{

DelPai((*Iter).m_Type,(*Iter).m_Value);

DelPai((*Iter).m_Type,(*Iter).m_Value);

DelPai((*Iter).m_Type,(*Iter).m_Value);

m_PengPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value);

m_PengPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value);

m_PengPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value);

return true;

}

return false;

}

//杠牌

bool CMJ::CheckGangPai(int p_Type,int p_Value)

{

m_TempGangPAIVec.clear();

//饼

if(m_MyPAIVec[p_Type].empty()==false)

{

int iSize = m_MyPAIVec[p_Type].size();

if( iSize >= 3)

{

for(UINT i = 0 ; i < iSize-2 ; i++ )

{

if((m_MyPAIVec[p_Type][i]==p_Value)&&(m_MyPAIVec[p_Type][i+1]==p_Value)&&(m_MyPAIVec[p_Type][i+2]==p_Value))

{

stPAI t_Gang;

t_Gang.m_Type = p_Type;

t_Gang.m_Value = p_Value;

m_TempGangPAIVec.push_back(t_Gang);

break;

}

}

}

if(m_TempGangPAIVec.size() > 0)

{

return true;

}

}

return false;

}

//杠牌

bool CMJ::DoGangPai(int p_Type,int p_Value)

{

AddPai(p_Type,p_Value);

vector::iterator Iter;

for(Iter = m_TempGangPAIVec.begin(); Iter != m_TempGangPAIVec.end(); Iter++ )

{

DelPai((*Iter).m_Type,(*Iter).m_Value);

DelPai((*Iter).m_Type,(*Iter).m_Value);

DelPai((*Iter).m_Type,(*Iter).m_Value);

DelPai((*Iter).m_Type,(*Iter).m_Value);

//排序放入

if(m_GangPAIVec[(*Iter).m_Type].empty())

{

m_GangPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value);

m_GangPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value);

m_GangPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value);

m_GangPAIVec[(*Iter).m_Type].push_back((*Iter).m_Value);

}

else

{

vector::iterator Iter2;

for(Iter2 = m_GangPAIVec[(*Iter).m_Type].begin(); Iter2 != m_GangPAIVec[(*Iter).m_Type].end(); Iter2++ )

{

if((*Iter2)>(*Iter).m_Value)

{

m_GangPAIVec[(*Iter).m_Type].insert(Iter2,(*Iter).m_Value);

m_GangPAIVec[(*Iter).m_Type].insert(Iter2,(*Iter).m_Value);

m_GangPAIVec[(*Iter).m_Type].insert(Iter2,(*Iter).m_Value);

m_GangPAIVec[(*Iter).m_Type].insert(Iter2,(*Iter).m_Value);

break;

}

}

}

return true;

}

return false;

}

//检测是否胡牌

bool CMJ::CheckAllPai(bool GetOrPut)

{

if(GetOrPut == MJPAI_GETPAI)

{

//检查大四喜

if(CheckD4X_HU())

{

strcpy(m_GoodInfo.m_GoodName,"大四喜");

m_GoodInfo.m_GoodValue = 88;

return true;

}

//检查大三元

if(CheckD3Y_HU())

{

strcpy(m_GoodInfo.m_GoodName,"大三元");

m_GoodInfo.m_GoodValue = 88;

return true;

}

//检查绿一色

if(CheckL1S_HU())

{

strcpy(m_GoodInfo.m_GoodName,"绿一色");

m_GoodInfo.m_GoodValue = 88;

return true;

}

//检查九莲宝灯

if(Check9LBD_HU())

{

strcpy(m_GoodInfo.m_GoodName,"九莲宝灯");

m_GoodInfo.m_GoodValue = 88;

return true;

}

//检查四杠

if(Check4Gang_HU())

{

strcpy(m_GoodInfo.m_GoodName,"四杠");

m_GoodInfo.m_GoodValue = 88;

return true;

}

//检查连七对

if(CheckL7D_HU())

{

strcpy(m_GoodInfo.m_GoodName,"连七对");

m_GoodInfo.m_GoodValue = 88;

return true;

}

//检查十三幺

if(Chekc13Y_HU())

{

strcpy(m_GoodInfo.m_GoodName,"十三幺");

m_GoodInfo.m_GoodValue = 88;

return true;

}

//检查清幺九

if(CheckQY9_HU())

{

strcpy(m_GoodInfo.m_GoodName,"清幺九");

m_GoodInfo.m_GoodValue = 64;

return true;

}

//检查小四喜

if(CheckX4X_HU())

{

strcpy(m_GoodInfo.m_GoodName,"小四喜");

m_GoodInfo.m_GoodValue = 64;

return true;

}

//检查小三元

if(CheckX3Y_HU())

{

strcpy(m_GoodInfo.m_GoodName,"小三元");

m_GoodInfo.m_GoodValue = 64;

return true;

}

//检测是否四暗刻

if(Check4AK_HU())

{

strcpy(m_GoodInfo.m_GoodName,"四暗刻");

m_GoodInfo.m_GoodValue = 64;

return true;

}

//检测是否一色双龙会

if(Check1S2LH_HU())

{

strcpy(m_GoodInfo.m_GoodName,"一色双龙会");

m_GoodInfo.m_GoodValue = 64;

return true;

}

//检测是否一色四同顺

if(Check1S4TS_HU())

{

strcpy(m_GoodInfo.m_GoodName,"一色四同顺");

m_GoodInfo.m_GoodValue = 48;

return true;

}

//检测是否一色四节高

if(Check1S4JG_HU())

{

strcpy(m_GoodInfo.m_GoodName,"一色四节高");

m_GoodInfo.m_GoodValue = 48;

return true;

}

//检测是否一色四步高

if(Check1S4BG_HU())

{

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值