246 lines
5.4 KiB
C++
246 lines
5.4 KiB
C++
#include "WN_GameLogic.h"
|
|
#include "PlatformHeader.h"
|
|
|
|
using namespace WNMJ_SPACE;
|
|
|
|
WN_CGameLogic* WN_CGameLogic::s_configInstance = nullptr;
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//静态变量
|
|
|
|
//扑克数据
|
|
const uint8 WN_CGameLogic::m_cbCardDataArray[MAX_REPERTORY]=
|
|
{
|
|
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, //万子
|
|
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, //万子
|
|
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, //万子
|
|
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, //万子
|
|
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19, //索子
|
|
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19, //索子
|
|
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19, //索子
|
|
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19, //索子
|
|
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29, //同子
|
|
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29, //同子
|
|
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29, //同子
|
|
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29, //同子
|
|
0x31,0x32,0x33,0x34,0x35,0x36,0x37, //番子
|
|
0x31,0x32,0x33,0x34,0x35,0x36,0x37, //番子
|
|
0x31,0x32,0x33,0x34,0x35,0x36,0x37, //番子
|
|
0x31,0x32,0x33,0x34,0x35,0x36,0x37, //番子
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//构造函数
|
|
void WN_CGameLogic::init()
|
|
{
|
|
memset(m_cbKingCardIndex, 0xFF, sizeof(m_cbKingCardIndex));
|
|
}
|
|
|
|
//析构函数
|
|
void WN_CGameLogic::clear()
|
|
{
|
|
}
|
|
|
|
//有效判断
|
|
bool WN_CGameLogic::IsValidCard(uint8 cbCardData)
|
|
{
|
|
uint8 cbValue = (cbCardData&MASK_WN_VALUE);
|
|
uint8 cbColor = (cbCardData&MASK_WN_COLOR) >> 4;
|
|
return (((cbValue>=1)&&(cbValue<=9)&&(cbColor<=2))||((cbValue>=1)&&(cbValue<=7)&&(cbColor==3)));
|
|
}
|
|
|
|
//扑克数目
|
|
uint8 WN_CGameLogic::GetCardCount(uint8 cbCardIndex[MAX_INDEX])
|
|
{
|
|
//数目统计
|
|
uint8 cbCardCount=0;
|
|
for (uint8 i=0;i<MAX_INDEX;i++)
|
|
cbCardCount+=cbCardIndex[i];
|
|
|
|
return cbCardCount;
|
|
}
|
|
|
|
//获取组合
|
|
uint8 WN_CGameLogic::GetWeaveCard(WORD cbWeaveKind, uint8 cbCenterCard, uint8 cbCardBuffer[4])
|
|
{
|
|
//组合扑克
|
|
switch (cbWeaveKind)
|
|
{
|
|
case WIK_WN_PENG: //碰牌操作
|
|
{
|
|
//设置变量
|
|
cbCardBuffer[0]=cbCenterCard;
|
|
cbCardBuffer[1]=cbCenterCard;
|
|
cbCardBuffer[2]=cbCenterCard;
|
|
|
|
return 3;
|
|
}
|
|
case WIK_WN_GANG: //杠牌操作
|
|
{
|
|
//设置变量
|
|
cbCardBuffer[0]=cbCenterCard;
|
|
cbCardBuffer[1]=cbCenterCard;
|
|
cbCardBuffer[2]=cbCenterCard;
|
|
cbCardBuffer[3]=cbCenterCard;
|
|
|
|
return 4;
|
|
}
|
|
default:
|
|
{
|
|
ASSERT(FALSE);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
//获取胡牌类型
|
|
std::string WN_CGameLogic::GetHuKind(WORD wChiHuKind)
|
|
{
|
|
std::string strHuKind = "";
|
|
if ((wChiHuKind&CHK_JI_HU)!= 0)
|
|
{
|
|
strHuKind = "平胡";
|
|
}
|
|
else if ((wChiHuKind&CHK_QI_DUI) && (wChiHuKind&CHK_HUNYISE))
|
|
{
|
|
strHuKind = "混七对";
|
|
}
|
|
else if ((wChiHuKind&CHK_QI_DUI) && (wChiHuKind&CHK_QINYISE))
|
|
{
|
|
strHuKind = "清七对";
|
|
}
|
|
else if ((wChiHuKind&CHK_QI_DUI) && (wChiHuKind&CHK_ZIYISE))
|
|
{
|
|
strHuKind = "字七对";
|
|
}
|
|
else if ((wChiHuKind&CHK_QI_DUI) != 0)
|
|
{
|
|
strHuKind = "七对";
|
|
}
|
|
else if ((wChiHuKind&CHK_THIRTEEN) != 0)
|
|
{
|
|
strHuKind = "打烂";
|
|
}
|
|
else if ((wChiHuKind&CHK_SERVEN) != 0)
|
|
{
|
|
strHuKind = "七星";
|
|
}
|
|
else if ((wChiHuKind&CHK_PENG_PENG) && (wChiHuKind&CHK_HUNYISE))
|
|
{
|
|
strHuKind = "混碰";
|
|
}
|
|
else if ((wChiHuKind&CHK_PENG_PENG) && (wChiHuKind&CHK_QINYISE))
|
|
{
|
|
strHuKind = "清碰";
|
|
}
|
|
else if ((wChiHuKind&CHK_PENG_PENG) && (wChiHuKind&CHK_ZIYISE))
|
|
{
|
|
strHuKind = "字碰";
|
|
}
|
|
else if ((wChiHuKind&CHK_PENG_PENG) != 0)
|
|
{
|
|
strHuKind = "碰碰胡";
|
|
}
|
|
else if ((wChiHuKind&CHK_QINYISE) != 0)
|
|
{
|
|
strHuKind = "清一色";
|
|
}
|
|
else if ((wChiHuKind&CHK_HUNYISE) != 0)
|
|
{
|
|
strHuKind = "混一色";
|
|
}
|
|
else if ((wChiHuKind&CHK_ZIYISE) != 0)
|
|
{
|
|
strHuKind = "字一色";
|
|
}
|
|
|
|
return strHuKind;
|
|
}
|
|
|
|
//获取胡牌维权
|
|
std::string WN_CGameLogic::GetHuRight(WORD wChiHuRight)
|
|
{
|
|
std::string strHuRight = "";
|
|
if ((wChiHuRight&CHR_ZI_MO) != 0)
|
|
{
|
|
strHuRight = "自摸";
|
|
}
|
|
else if ((wChiHuRight&CHR_QIANG_GANG) != 0)
|
|
{
|
|
strHuRight = "抢杠";
|
|
}
|
|
else if ((wChiHuRight&CHR_GANG_FLOWER) != 0)
|
|
{
|
|
strHuRight = "开杠";
|
|
}
|
|
else if ((wChiHuRight&CHR_TIAN) != 0)
|
|
{
|
|
strHuRight = "天胡";
|
|
}
|
|
else if ((wChiHuRight&CHR_DI) != 0)
|
|
{
|
|
strHuRight = "地胡";
|
|
}
|
|
else if ((wChiHuRight&CHR_LIAN_GANG_FLOWER) != 0)
|
|
{
|
|
strHuRight = "连杠胡";
|
|
}
|
|
else if ((wChiHuRight&CHR_QIANG_LIAN_GANG) != 0)
|
|
{
|
|
strHuRight = "抢连杠";
|
|
}
|
|
|
|
return strHuRight;
|
|
}
|
|
|
|
//扑克转换
|
|
uint8 WN_CGameLogic::SwitchToCardData(uint8 cbCardIndex)
|
|
{
|
|
ASSERT(cbCardIndex<MAX_INDEX);
|
|
|
|
ASSERT(cbCardIndex<34);
|
|
return ((cbCardIndex/9)<<4)|(cbCardIndex%9+1);
|
|
}
|
|
|
|
//扑克转换
|
|
uint8 WN_CGameLogic::SwitchToCardIndex(uint8 cbCardData)
|
|
{
|
|
ASSERT(IsValidCard(cbCardData));
|
|
|
|
return ((cbCardData&MASK_WN_COLOR)>>4)*9+(cbCardData&MASK_WN_VALUE)-1;
|
|
}
|
|
|
|
//杠牌分析
|
|
WORD WN_CGameLogic::AnalyseGangCard(uint8 cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], uint8 cbWeaveCount, tagGangCardResult & GangCardResult)
|
|
{
|
|
//设置变量
|
|
WORD wActionMask = WIK_WN_NULL;
|
|
zeromemory(&GangCardResult, sizeof(GangCardResult));
|
|
|
|
//手上杠牌
|
|
for (uint8 i = 0; i < MAX_INDEX - 1; i++)
|
|
{
|
|
if (cbCardIndex[i] == 4)
|
|
{
|
|
wActionMask |= WIK_WN_GANG;
|
|
GangCardResult.cbCardData[GangCardResult.cbCardCount++] = SwitchToCardData(i);
|
|
}
|
|
}
|
|
|
|
//组合杠牌
|
|
for (uint8 i = 0; i < cbWeaveCount; i++)
|
|
{
|
|
if (WeaveItem[i].wWeaveKind == WIK_WN_PENG)
|
|
{
|
|
if (cbCardIndex[SwitchToCardIndex(WeaveItem[i].cbCenterCard)] == 1)
|
|
{
|
|
wActionMask |= WIK_WN_GANG;
|
|
GangCardResult.cbCardData[GangCardResult.cbCardCount++] = WeaveItem[i].cbCenterCard;
|
|
}
|
|
}
|
|
}
|
|
|
|
return wActionMask;
|
|
} |