1191 lines
31 KiB
C++
1191 lines
31 KiB
C++
#include "StdAfx.h"
|
||
#include "GameLogic.h"
|
||
|
||
#define IS_BOME_TYPE(x,y) (((x)>>(y))>0)
|
||
|
||
//////////////////////////////////////////////////////////////////////////
|
||
//静态变量
|
||
|
||
//扑克数据
|
||
const BYTE CGameLogic::m_cbCardData[FULL_COUNT] =
|
||
{
|
||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, //方块 A - K
|
||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, //梅花 A - K
|
||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, //红桃 A - K
|
||
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, //黑桃 A - K
|
||
0x4E, 0x4F,
|
||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, //方块 A - K
|
||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, //梅花 A - K
|
||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, //红桃 A - K
|
||
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, //黑桃 A - K
|
||
0x4E, 0x4F,
|
||
};
|
||
|
||
//扑克数据
|
||
const BYTE CGameLogic::m_cbNoJokerCardData[NO_JOKER_COUNT] =
|
||
{
|
||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, //方块 A - K
|
||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, //梅花 A - K
|
||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, //红桃 A - K
|
||
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, //黑桃 A - K
|
||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, //方块 A - K
|
||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, //梅花 A - K
|
||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, //红桃 A - K
|
||
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, //黑桃 A - K
|
||
};
|
||
|
||
//////////////////////////////////////////////////////////////////////////
|
||
|
||
//构造函数
|
||
CGameLogic::CGameLogic()
|
||
{
|
||
|
||
}
|
||
|
||
//析构函数
|
||
CGameLogic::~CGameLogic()
|
||
{
|
||
|
||
}
|
||
|
||
int CGameLogic::GetCardType(const BYTE cbCardData[], BYTE cbCardCount, bool isLastCard)
|
||
{
|
||
//简单牌型
|
||
switch (cbCardCount)
|
||
{
|
||
case 0: //空牌
|
||
{
|
||
return CT_ERROR;
|
||
}
|
||
case 1: //单牌
|
||
{
|
||
return TransListToInt(0,CT_SINGLE);
|
||
}
|
||
case 2: //对牌火箭
|
||
{
|
||
//牌型判断
|
||
//if ((cbCardData[0]==0x4F)&&(cbCardData[1]==0x4E)) return TransListToInt(0,CT_MISSILE_CARD);
|
||
if (GetCardLogicValue(cbCardData[0])==GetCardLogicValue(cbCardData[1])) return TransListToInt(0,CT_DOUBLE);
|
||
|
||
//赖子判断
|
||
if(GetCardLogicValue(cbCardData[0])!=GetCardLogicValue(cbCardData[1]))
|
||
{
|
||
if (IsLaiZiCard(cbCardData[0]) && !IsLaiZiCard(cbCardData[1]))
|
||
{
|
||
return TransListToInt(0, CT_DOUBLE);
|
||
}
|
||
else if (!IsLaiZiCard(cbCardData[0]) && IsLaiZiCard(cbCardData[1]))
|
||
{
|
||
return TransListToInt(0, CT_DOUBLE);
|
||
}
|
||
|
||
//if (IsLaiZiCard(cbCardData[0]) || IsLaiZiCard(cbCardData[1]))
|
||
//{
|
||
// if((cbCardData[0]!=0x4F) && (cbCardData[0]!=0x4E) && (cbCardData[0]!=0x4F) && (cbCardData[1]!=0x4E))
|
||
// {
|
||
// return TransListToInt(0,CT_DOUBLE);
|
||
// }
|
||
//}
|
||
}
|
||
|
||
return CT_ERROR;
|
||
}
|
||
case 4: //王炸;
|
||
{
|
||
if ((cbCardData[0] == 0x4F) && (cbCardData[1] == 0x4F) && (cbCardData[2] == 0x4E) && (cbCardData[3] == 0x4E))
|
||
{
|
||
return TransListToInt(0, CT_BOMB_8);
|
||
}
|
||
}
|
||
}
|
||
|
||
int dCardType = CT_ERROR;
|
||
|
||
// 炸弹分析;
|
||
if (cbCardCount >= 4 && cbCardCount <= 12)
|
||
{
|
||
bool isSameCard = true;
|
||
|
||
// 大小排序王在最前面;
|
||
BYTE cbValue = GetCardValue(cbCardData[cbCardCount - 1]);
|
||
for (BYTE i = 0; i < cbCardCount; i++)
|
||
{
|
||
ASSERT(IsValidCard(cbCardData[i]));
|
||
if (cbValue != GetCardValue(cbCardData[i]) && !IsLaiZiCard(cbCardData[i]))
|
||
{
|
||
isSameCard = false;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 同牌判断
|
||
if (isSameCard)
|
||
{
|
||
// 4张炸弹做三带一特殊处理;
|
||
if (isLastCard && (cbCardCount == 4))
|
||
{
|
||
dCardType = TransListToInt(dCardType, CT_THREE_TAKE_TWO);
|
||
}
|
||
|
||
BYTE cbCardType = CT_BOMB_4 + cbCardCount - 4;
|
||
cbCardType = (cbCardType > CT_BOMB_10) ? CT_BOMB_10 : cbCardType;
|
||
dCardType = TransListToInt(dCardType, cbCardType);
|
||
|
||
return dCardType;// TransListToInt(0, cbCardType);
|
||
}
|
||
}
|
||
|
||
// 癞子分析;
|
||
BYTE cbNormalCard[MAX_COUNT] = {0};
|
||
BYTE cbMagicCardCount = 0; // 大小王数量;
|
||
BYTE cbNormalCardCount = 0; // 正常牌数量;
|
||
|
||
//变幻准备
|
||
for (BYTE i = 0; i < cbCardCount; i++)
|
||
{
|
||
if (IsLaiZiCard(cbCardData[i]))
|
||
{
|
||
cbMagicCardCount++;
|
||
}
|
||
else
|
||
{
|
||
cbNormalCard[cbNormalCardCount++] = cbCardData[i];
|
||
}
|
||
}
|
||
|
||
// 没有癞子;
|
||
if (cbMagicCardCount == 0)
|
||
{
|
||
BYTE bCardDataTemp[MAX_COUNT] = { 0 };
|
||
CopyMemory(bCardDataTemp, cbCardData, sizeof(BYTE)*cbCardCount);
|
||
|
||
//分析扑克
|
||
tagAnalyseResult AnalyseResult;
|
||
ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
|
||
BYTE cbMaxCardData = 0, cbBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, cbMaxCardData, cbBlockCount, isLastCard);
|
||
|
||
// 不存在该类型时候,增加该类型;
|
||
if ((dCardType&(1 << iCardType)) == 0)
|
||
{
|
||
dCardType = TransListToInt(dCardType, iCardType);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (cbMagicCardCount >= 1)
|
||
{
|
||
tagAnalyseResult AnalyseResult;
|
||
ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
|
||
|
||
BYTE bCardDataTemp[MAX_COUNT] = { 0 };
|
||
CopyMemory(&bCardDataTemp[cbMagicCardCount], cbNormalCard, sizeof(BYTE)*cbNormalCardCount);
|
||
|
||
for (BYTE i = 0; i < 13; i++)
|
||
{
|
||
bCardDataTemp[0] = m_cbCardData[i];
|
||
|
||
//两张赖子
|
||
if (cbMagicCardCount >= 2)
|
||
{
|
||
for (BYTE z = 0; z < 13; z++)
|
||
{
|
||
bCardDataTemp[1] = m_cbCardData[z];
|
||
|
||
//三张赖子
|
||
if (cbMagicCardCount >= 3)
|
||
{
|
||
for (BYTE f = 0; f < 13; f++)
|
||
{
|
||
bCardDataTemp[2] = m_cbCardData[f];
|
||
|
||
//四张赖子
|
||
if (cbMagicCardCount == 4)
|
||
{
|
||
for (BYTE l = 0; l < 13; l++)
|
||
{
|
||
bCardDataTemp[3] = m_cbCardData[l];
|
||
|
||
ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
|
||
//int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbMaxCardData = 0, cbBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, cbMaxCardData, cbBlockCount, isLastCard);
|
||
|
||
if (iCardType == 0) continue;
|
||
|
||
if ((dCardType&(1 << iCardType)) == 0)
|
||
{
|
||
dCardType = TransListToInt(dCardType, iCardType);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
|
||
//int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbMaxCardData = 0, cbBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, cbMaxCardData, cbBlockCount, isLastCard);
|
||
|
||
if (iCardType == 0) continue;
|
||
|
||
if ((dCardType&(1 << iCardType)) == 0)
|
||
{
|
||
dCardType = TransListToInt(dCardType, iCardType);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
|
||
//int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbMaxCardData = 0, cbBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, cbMaxCardData, cbBlockCount, isLastCard);
|
||
|
||
if (iCardType == 0) continue;
|
||
|
||
if ((dCardType&(1 << iCardType)) == 0)
|
||
{
|
||
dCardType = TransListToInt(dCardType, iCardType);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
|
||
//int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbMaxCardData = 0, cbBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResult, bCardDataTemp, cbCardCount, cbMaxCardData, cbBlockCount, isLastCard);
|
||
|
||
if (iCardType == 0) continue;
|
||
|
||
if ((dCardType&(1 << iCardType)) == 0)
|
||
{
|
||
dCardType = TransListToInt(dCardType, iCardType);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return dCardType;
|
||
}
|
||
|
||
//获取类型结果
|
||
int CGameLogic::GetType(tagAnalyseResult& AnalyseResult, const BYTE cbCardData[], BYTE cbCardCount, BYTE& cbMaxCardData, BYTE &cbBlockCount, bool isLastCard)
|
||
{
|
||
// 重置牌值;
|
||
cbMaxCardData = 0x0;
|
||
cbBlockCount = 0x0;
|
||
|
||
//简单牌型
|
||
switch (cbCardCount)
|
||
{
|
||
case 0: //空牌
|
||
{
|
||
return CT_ERROR;
|
||
}
|
||
case 1: //单牌
|
||
{
|
||
cbMaxCardData = cbCardData[0];
|
||
return CT_SINGLE;
|
||
}
|
||
case 2: //对牌火箭
|
||
{
|
||
//牌型判断
|
||
//if ((cbCardData[0]==0x4F)&&(cbCardData[1]==0x4E)) return TransListToInt(0,CT_MISSILE_CARD);
|
||
if (GetCardLogicValue(cbCardData[0]) == GetCardLogicValue(cbCardData[1]))
|
||
{
|
||
cbMaxCardData = cbCardData[0];
|
||
return CT_DOUBLE;
|
||
}
|
||
|
||
//赖子判断
|
||
if (GetCardLogicValue(cbCardData[0]) != GetCardLogicValue(cbCardData[1]))
|
||
{
|
||
if (IsLaiZiCard(cbCardData[0]) || IsLaiZiCard(cbCardData[1]))
|
||
{
|
||
if ((cbCardData[0] != 0x4F) && (cbCardData[0] != 0x4E) && (cbCardData[0] != 0x4F) && (cbCardData[1] != 0x4E))
|
||
{
|
||
cbMaxCardData = cbCardData[cbCardCount - 1];
|
||
return CT_DOUBLE;
|
||
}
|
||
}
|
||
}
|
||
|
||
return CT_ERROR;
|
||
}
|
||
case 4: //王炸;
|
||
{
|
||
if ((cbCardData[0] == 0x4F) && (cbCardData[1] == 0x4F) && (cbCardData[2] == 0x4E) && (cbCardData[3] == 0x4E))
|
||
{
|
||
cbMaxCardData = cbCardData[0];
|
||
return CT_BOMB_8;
|
||
}
|
||
}
|
||
}
|
||
|
||
//单张判断
|
||
if ((AnalyseResult.cbBlockCount[BLOCK_ONE] >= 5) && (AnalyseResult.cbBlockCount[BLOCK_ONE] == cbCardCount))
|
||
{
|
||
//变量定义
|
||
BYTE cbFirstLogicValue = GetCardLogicValue(AnalyseResult.cbCardData[BLOCK_ONE][0]);
|
||
|
||
//错误过虑
|
||
if (cbFirstLogicValue > 14) return CT_ERROR;
|
||
|
||
//连牌判断
|
||
for (BYTE i = 1; i < AnalyseResult.cbBlockCount[BLOCK_ONE]; i++)
|
||
{
|
||
BYTE cbTmpCardData = AnalyseResult.cbCardData[BLOCK_ONE][i];
|
||
if (cbFirstLogicValue != (GetCardLogicValue(cbTmpCardData) + i))
|
||
return CT_ERROR;
|
||
}
|
||
|
||
cbMaxCardData = cbCardData[0];
|
||
|
||
return CT_SINGLE_LINE;
|
||
}
|
||
|
||
//两张类型
|
||
if ((AnalyseResult.cbBlockCount[BLOCK_TWO] >= 2) && (AnalyseResult.cbBlockCount[BLOCK_TWO] * 2 == cbCardCount))
|
||
{
|
||
//变量定义
|
||
BYTE cbFirstLogicValue = GetCardLogicValue(AnalyseResult.cbCardData[BLOCK_TWO][0]);
|
||
|
||
//错误过虑
|
||
if (cbFirstLogicValue > 14) return CT_ERROR;
|
||
|
||
//连牌判断
|
||
for (BYTE i = 1; i < AnalyseResult.cbBlockCount[BLOCK_TWO]; i++)
|
||
{
|
||
BYTE cbTmpCardData = AnalyseResult.cbCardData[BLOCK_TWO][i * 2];
|
||
if (cbFirstLogicValue != (GetCardLogicValue(cbTmpCardData) + i))
|
||
return CT_ERROR;
|
||
}
|
||
|
||
//二连判断
|
||
if ((AnalyseResult.cbBlockCount[BLOCK_TWO] * 2) == cbCardCount)
|
||
{
|
||
cbMaxCardData = cbCardData[0];
|
||
return CT_DOUBLE_LINE;
|
||
}
|
||
|
||
return CT_ERROR;
|
||
}
|
||
|
||
// 其他牌型都判断完了,如果还有5张以上牌直接返回CT_ERROR;
|
||
for (int i = BLOCK_FIVE; i <= BLOCK_TWELVE; i++)
|
||
{
|
||
if (AnalyseResult.cbBlockCount[i] > 0)
|
||
{
|
||
return CT_ERROR;
|
||
}
|
||
}
|
||
|
||
//三带二
|
||
if (AnalyseResult.cbBlockCount[BLOCK_THREE] == 1 && cbCardCount == 5)
|
||
{
|
||
cbMaxCardData = AnalyseResult.cbCardData[BLOCK_THREE][0];
|
||
return CT_THREE_TAKE_TWO;
|
||
}
|
||
|
||
//三带二
|
||
if (isLastCard && AnalyseResult.cbBlockCount[BLOCK_THREE] == 1 && cbCardCount <= 5)
|
||
{
|
||
cbMaxCardData = AnalyseResult.cbCardData[BLOCK_THREE][0];
|
||
return CT_THREE_TAKE_TWO;
|
||
}
|
||
|
||
//三带二
|
||
if ((AnalyseResult.cbBlockCount[BLOCK_FOUR] == 1) && (cbCardCount == 5))
|
||
{
|
||
cbMaxCardData = AnalyseResult.cbCardData[BLOCK_FOUR][0];
|
||
return CT_THREE_TAKE_TWO;
|
||
}
|
||
|
||
//三带二
|
||
if (isLastCard && AnalyseResult.cbBlockCount[BLOCK_FOUR] == 1 && cbCardCount <= 5)
|
||
{
|
||
cbMaxCardData = AnalyseResult.cbCardData[BLOCK_FOUR][0];
|
||
return CT_THREE_TAKE_TWO;
|
||
}
|
||
|
||
//三连判断;
|
||
if (AnalyseResult.cbBlockCount[BLOCK_THREE] + AnalyseResult.cbBlockCount[BLOCK_FOUR] > 1)
|
||
{
|
||
// 不是最后一手牌,三连必须是5的倍数;
|
||
if (!isLastCard && (cbCardCount % 5 != 0)) return CT_ERROR;
|
||
|
||
BYTE cbCardType = CT_ERROR;
|
||
|
||
BYTE cbLineCardData[MAX_COUNT] = { 0 };
|
||
BYTE cbLineLength = 0;
|
||
|
||
// 目前只从3取到5张相同牌(将3到5张相同的牌放到同一个数组,用来检测是不是连牌);
|
||
for (BYTE i = BLOCK_THREE; i <= BLOCK_FOUR; i++)
|
||
{
|
||
if (AnalyseResult.cbBlockCount[i] > 0)
|
||
{
|
||
for (BYTE j = 0; j < AnalyseResult.cbBlockCount[i]; j++)
|
||
{
|
||
BYTE cbTmpCardDate = AnalyseResult.cbCardData[i][j*(i + 1)];
|
||
// 连牌不带2;
|
||
if (GetCardLogicValue(cbTmpCardDate) > 14) continue;
|
||
|
||
cbLineCardData[cbLineLength] = cbTmpCardDate;
|
||
cbLineLength++;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 重新排序;
|
||
SortCardList(cbLineCardData, cbLineLength, ST_ORDER);
|
||
|
||
BYTE cbLastValue = GetCardLogicValue(cbLineCardData[0]);
|
||
//错误过虑(3~A)
|
||
if (cbLastValue > 14) return CT_ERROR;
|
||
|
||
// 查找三连数量;
|
||
BYTE cbMaxThreeLength = 1;
|
||
BYTE cbThreeLength = 1;
|
||
BYTE cbMaxThreeCardData = cbLineCardData[0];
|
||
|
||
for (BYTE i = 1; i < cbLineLength; i++)
|
||
{
|
||
BYTE cbTmpValue = GetCardLogicValue(cbLineCardData[i]);
|
||
|
||
// 不连续
|
||
if (cbLastValue != (cbTmpValue + 1))
|
||
{
|
||
if (cbMaxThreeLength < cbThreeLength)
|
||
{
|
||
cbMaxThreeLength = cbThreeLength;
|
||
cbMaxThreeCardData = cbLineCardData[i - cbMaxThreeLength];
|
||
}
|
||
|
||
cbThreeLength = 1;
|
||
}
|
||
else
|
||
{
|
||
cbThreeLength++;
|
||
}
|
||
|
||
cbLastValue = cbTmpValue;
|
||
}
|
||
|
||
// 最后一个
|
||
if (cbMaxThreeLength < cbThreeLength)
|
||
{
|
||
cbMaxThreeLength = cbThreeLength;
|
||
cbMaxThreeCardData = cbLineCardData[cbLineLength - cbMaxThreeLength];
|
||
}
|
||
|
||
// 最后一手牌;
|
||
if (isLastCard && (cbMaxThreeLength * 5 >= cbCardCount))
|
||
{
|
||
cbBlockCount = cbMaxThreeLength;
|
||
cbMaxCardData = cbMaxThreeCardData;
|
||
cbCardType = CT_THREE_LINE;
|
||
}
|
||
else if (!isLastCard)
|
||
{
|
||
// 计算几个三带二
|
||
BYTE cbTmpBlockCount = cbCardCount / 5;
|
||
//if (cbMaxThreeLength == cbTmpBlockCount)
|
||
if ((cbTmpBlockCount * 5 == cbCardCount) && (cbMaxThreeLength >= cbTmpBlockCount))
|
||
{
|
||
cbBlockCount = cbTmpBlockCount;
|
||
cbMaxCardData = cbMaxThreeCardData;
|
||
cbCardType = CT_THREE_LINE;
|
||
}
|
||
}
|
||
|
||
return cbCardType;
|
||
}
|
||
|
||
return CT_ERROR;
|
||
}
|
||
//排列扑克
|
||
void CGameLogic::SortCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbSortType)
|
||
{
|
||
//数目过虑
|
||
if (cbCardCount == 0) return;
|
||
|
||
if (cbSortType == ST_ORDER)
|
||
{
|
||
//转换数值
|
||
BYTE cbSortValue[MAX_COUNT];
|
||
for (BYTE i = 0; i < cbCardCount; i++)
|
||
{
|
||
cbSortValue[i] = GetCardLogicValue(cbCardData[i]);
|
||
}
|
||
|
||
//排序操作
|
||
bool bSorted = true;
|
||
BYTE cbSwitchData = 0, cbLast = cbCardCount - 1;
|
||
do
|
||
{
|
||
bSorted = true;
|
||
for (BYTE i = 0; i < cbLast; i++)
|
||
{
|
||
if ((cbSortValue[i] < cbSortValue[i + 1]) ||
|
||
((cbSortValue[i] == cbSortValue[i + 1]) && (cbCardData[i] < cbCardData[i + 1])))
|
||
{
|
||
//设置标志
|
||
bSorted = false;
|
||
|
||
//扑克数据
|
||
cbSwitchData = cbCardData[i];
|
||
cbCardData[i] = cbCardData[i + 1];
|
||
cbCardData[i + 1] = cbSwitchData;
|
||
|
||
//排序权位
|
||
cbSwitchData = cbSortValue[i];
|
||
cbSortValue[i] = cbSortValue[i + 1];
|
||
cbSortValue[i + 1] = cbSwitchData;
|
||
}
|
||
}
|
||
cbLast--;
|
||
} while (bSorted == false);
|
||
}
|
||
//数目排序
|
||
else if (cbSortType == ST_COUNT)
|
||
{
|
||
//变量定义
|
||
BYTE cbCardIndex = 0;
|
||
|
||
//分析扑克
|
||
tagAnalyseResult AnalyseResult;
|
||
ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
|
||
AnalysebCardData(&cbCardData[cbCardIndex], cbCardCount - cbCardIndex, AnalyseResult);
|
||
|
||
//提取扑克
|
||
for (BYTE i = 0; i < CountArray(AnalyseResult.cbBlockCount); i++)
|
||
{
|
||
//拷贝扑克
|
||
BYTE cbIndex = CountArray(AnalyseResult.cbBlockCount) - i - 1;
|
||
CopyMemory(&cbCardData[cbCardIndex], AnalyseResult.cbCardData[cbIndex], AnalyseResult.cbBlockCount[cbIndex] * (cbIndex + 1)*sizeof(BYTE));
|
||
|
||
//设置索引
|
||
cbCardIndex += AnalyseResult.cbBlockCount[cbIndex] * (cbIndex + 1)*sizeof(BYTE);
|
||
}
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//混乱扑克
|
||
void CGameLogic::RandCardList(BYTE cbCardBuffer[], BYTE cbBufferCount)
|
||
{
|
||
//混乱准备
|
||
BYTE cbCardData[CountArray(m_cbCardData)];
|
||
CopyMemory(cbCardData,m_cbCardData,sizeof(m_cbCardData));
|
||
|
||
//混乱扑克
|
||
BYTE cbRandCount=0,cbPosition=0;
|
||
do
|
||
{
|
||
cbPosition=rand()%(cbBufferCount-cbRandCount);
|
||
cbCardBuffer[cbRandCount++]=cbCardData[cbPosition];
|
||
cbCardData[cbPosition]=cbCardData[cbBufferCount-cbRandCount];
|
||
} while (cbRandCount<cbBufferCount);
|
||
|
||
return;
|
||
}
|
||
|
||
//混乱扑克
|
||
void CGameLogic::RandNoJokerCardList(BYTE cbCardBuffer[], BYTE cbBufferCount)
|
||
{
|
||
//混乱准备
|
||
BYTE cbCardData[CountArray(m_cbNoJokerCardData)];
|
||
CopyMemory(cbCardData, m_cbNoJokerCardData, sizeof(m_cbNoJokerCardData));
|
||
|
||
//混乱扑克
|
||
BYTE cbRandCount = 0, cbPosition = 0;
|
||
do
|
||
{
|
||
cbPosition = rand() % (cbBufferCount - cbRandCount);
|
||
cbCardBuffer[cbRandCount++] = cbCardData[cbPosition];
|
||
cbCardData[cbPosition] = cbCardData[cbBufferCount - cbRandCount];
|
||
} while (cbRandCount < cbBufferCount);
|
||
|
||
return;
|
||
}
|
||
|
||
//删除扑克
|
||
bool CGameLogic::RemoveCard(const BYTE cbRemoveCard[], BYTE cbRemoveCount, BYTE cbCardData[], BYTE cbCardCount)
|
||
{
|
||
//检验数据
|
||
ASSERT(cbRemoveCount<=cbCardCount);
|
||
if(cbRemoveCount>cbCardCount)
|
||
return false ;
|
||
|
||
//定义变量
|
||
BYTE cbDeleteCount=0,cbTempCardData[MAX_COUNT];
|
||
if (cbCardCount>CountArray(cbTempCardData)) return false;
|
||
CopyMemory(cbTempCardData,cbCardData,cbCardCount*sizeof(cbCardData[0]));
|
||
|
||
//置零扑克
|
||
for (BYTE i=0;i<cbRemoveCount;i++)
|
||
{
|
||
for (BYTE j=0;j<cbCardCount;j++)
|
||
{
|
||
if (cbRemoveCard[i]==cbTempCardData[j])
|
||
{
|
||
cbDeleteCount++;
|
||
cbTempCardData[j]=0;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (cbDeleteCount!=cbRemoveCount) return false;
|
||
|
||
//清理扑克
|
||
BYTE cbCardPos=0;
|
||
for (BYTE i=0;i<cbCardCount;i++)
|
||
{
|
||
if (cbTempCardData[i]!=0) cbCardData[cbCardPos++]=cbTempCardData[i];
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
//有效判断
|
||
bool CGameLogic::IsValidCard(BYTE cbCardData)
|
||
{
|
||
//获取属性
|
||
BYTE cbCardColor=GetCardColor(cbCardData);
|
||
BYTE cbCardValue=GetCardValue(cbCardData);
|
||
|
||
//有效判断
|
||
if ((cbCardData==0x4E)||(cbCardData==0x4F)) return true;
|
||
if ((cbCardColor<=0x30)&&(cbCardValue>=0x01)&&(cbCardValue<=0x0D)) return true;
|
||
|
||
return false;
|
||
}
|
||
|
||
//逻辑数值
|
||
BYTE CGameLogic::GetCardLogicValue(BYTE cbCardData)
|
||
{
|
||
if (!IsValidCard(cbCardData)) return 0;
|
||
|
||
//扑克属性
|
||
BYTE cbCardColor=GetCardColor(cbCardData);
|
||
BYTE cbCardValue=GetCardValue(cbCardData);
|
||
|
||
//#ifdef _DEBUG
|
||
// if(cbCardValue<=0 || cbCardValue>(MASK_VALUE&0x4f))
|
||
// return 0 ;
|
||
//#endif
|
||
|
||
ASSERT(cbCardValue>0 && cbCardValue<=(MASK_VALUE&0x4f)) ;
|
||
|
||
//转换数值
|
||
if (cbCardColor==0x40) return cbCardValue+2;
|
||
return (cbCardValue<=2)?(cbCardValue+13):cbCardValue;
|
||
}
|
||
|
||
//对比扑克
|
||
bool CGameLogic::CompareCard(const CMD_C_OutCard* pFirstOutCard, CMD_C_OutCard* pNextOutCard)
|
||
{
|
||
if (pFirstOutCard == nullptr || pNextOutCard == nullptr) return false;
|
||
|
||
//获取类型
|
||
int cbFirstType = pFirstOutCard->cbCardType;
|
||
int cbNextType = pNextOutCard->cbCardType;
|
||
|
||
//类型判断
|
||
if (cbNextType == CT_ERROR) return false;
|
||
|
||
BYTE cbFirstCount = pFirstOutCard->cbCardCount;
|
||
BYTE cbNextCount = pNextOutCard->cbCardCount;
|
||
bool isFirstLastCard = pFirstOutCard->isLastCard;
|
||
bool isNextLastCard = pNextOutCard->isLastCard;
|
||
|
||
BYTE cbFirstCard[MAX_COUNT] = { 0 };
|
||
BYTE cbNextCard[MAX_COUNT] = { 0 };
|
||
CopyMemory(cbFirstCard, pFirstOutCard->cbCardData, sizeof(BYTE)*cbFirstCount);
|
||
CopyMemory(cbNextCard, pNextOutCard->cbCardData, sizeof(BYTE)*cbNextCount);
|
||
|
||
//炸弹过虑
|
||
int cbTmpFirstType = (cbFirstType >> CT_BOMB_4);
|
||
int cbTmpNextType = (cbNextType >> CT_BOMB_4);
|
||
|
||
if (cbTmpFirstType > 0 || cbTmpNextType > 0)
|
||
{
|
||
// 当前牌不是炸弹则打不到上一手炸弹牌;
|
||
if (cbTmpNextType < 0) return false;
|
||
//if (cbTmpFirstType > 0) return true;
|
||
|
||
//星级比较
|
||
if (cbTmpFirstType != cbTmpNextType)
|
||
{
|
||
if (cbTmpNextType > cbTmpFirstType)
|
||
{
|
||
// 重置牌型;
|
||
pNextOutCard->cbCardType = (cbTmpNextType << CT_BOMB_4);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 取最后一张,一定不是癞子;如果还是癞子,那就是4王炸;
|
||
BYTE cbConsultNext = GetCardLogicValue(cbNextCard[cbNextCount - 1]);
|
||
BYTE cbConsultFirst = GetCardLogicValue(cbFirstCard[cbFirstCount - 1]);
|
||
|
||
if (cbConsultNext > cbConsultFirst)
|
||
{
|
||
// 重置牌型;
|
||
pNextOutCard->cbCardType = (cbTmpNextType << CT_BOMB_4);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
|
||
//return cbConsultNext > cbConsultFirst;
|
||
}
|
||
}
|
||
|
||
//不同类型
|
||
if (cbFirstType != cbNextType) return false;
|
||
|
||
//获取数值
|
||
BYTE cbNextLogicValue = 0;
|
||
BYTE cbFirstLogicValue = 0;
|
||
|
||
//分析扑克
|
||
BYTE NextResult[CT_COUNT] = {0};
|
||
BYTE FirstResult[CT_COUNT] = { 0 };
|
||
|
||
// 单牌;
|
||
if ((cbNextType&(1 << CT_SINGLE)) != 0 && cbFirstCount == cbNextCount)
|
||
{
|
||
if (cbFirstCount != 1) return false;
|
||
|
||
//获取数值
|
||
cbNextLogicValue = GetCardLogicValue(cbNextCard[0]);
|
||
cbFirstLogicValue = GetCardLogicValue(cbFirstCard[0]);
|
||
|
||
if (cbNextLogicValue > cbFirstLogicValue)
|
||
{
|
||
// 重置牌型;
|
||
pNextOutCard->cbCardType = (1 << CT_SINGLE);
|
||
return true;
|
||
}
|
||
}
|
||
else if ((cbNextType&(1 << CT_DOUBLE)) != 0 && cbFirstCount == cbNextCount)
|
||
{
|
||
if (cbFirstCount != 2) return false;
|
||
|
||
//获取数值
|
||
cbNextLogicValue = GetCardLogicValue(cbNextCard[1]);
|
||
cbFirstLogicValue = GetCardLogicValue(cbFirstCard[1]);
|
||
|
||
if (cbNextLogicValue > cbFirstLogicValue)
|
||
{
|
||
// 重置牌型;
|
||
pNextOutCard->cbCardType = (1 << CT_DOUBLE);
|
||
return true;
|
||
}
|
||
}
|
||
else if ((cbNextType&(1 << CT_THREE_TAKE_TWO)) != 0)
|
||
{
|
||
// 三带二牌数判断;
|
||
if (cbFirstCount < 3 || cbFirstCount > 5) return false;
|
||
if (cbNextCount < 3 || cbNextCount > 5) return false;
|
||
|
||
// 不是最后一手牌必须是5张;
|
||
if (!isFirstLastCard && cbFirstCount != 5) return false;
|
||
if (!isNextLastCard && cbNextCount != 5) return false;
|
||
|
||
BYTE cbNextBlockCount = 0, cbFirstBlockCount = 0;
|
||
if (!AnalysebCompare(cbNextCard, cbNextCount, NextResult, cbNextBlockCount, CT_THREE_TAKE_TWO, isNextLastCard))return false;
|
||
if (!AnalysebCompare(cbFirstCard, cbFirstCount, FirstResult, cbFirstBlockCount, CT_THREE_TAKE_TWO, isFirstLastCard))return false;
|
||
|
||
//获取数值
|
||
cbNextLogicValue = GetCardLogicValue(NextResult[CT_THREE_TAKE_TWO]);
|
||
cbFirstLogicValue = GetCardLogicValue(FirstResult[CT_THREE_TAKE_TWO]);
|
||
|
||
//if (cbNextLogicValue > cbFirstLogicValue) return true;
|
||
if (cbNextLogicValue > cbFirstLogicValue)
|
||
{
|
||
// 重置牌型;
|
||
pNextOutCard->cbCardType = (1 << CT_THREE_TAKE_TWO);
|
||
return true;
|
||
}
|
||
}
|
||
else if ((cbNextType&(1 << CT_SINGLE_LINE)) != 0 && cbFirstCount == cbNextCount)
|
||
{
|
||
if (cbFirstCount < 5) return false;
|
||
|
||
//获取数值
|
||
cbNextLogicValue = GetCardLogicValue(cbNextCard[cbNextCount - 1]);
|
||
cbFirstLogicValue = GetCardLogicValue(cbFirstCard[cbFirstCount - 1]);
|
||
|
||
//if (cbNextLogicValue > cbFirstLogicValue) return true;
|
||
if (cbNextLogicValue > cbFirstLogicValue)
|
||
{
|
||
// 重置牌型;
|
||
pNextOutCard->cbCardType = (1 << CT_SINGLE_LINE);
|
||
return true;
|
||
}
|
||
|
||
}
|
||
else if ((cbNextType&(1 << CT_DOUBLE_LINE)) != 0 && cbFirstCount == cbNextCount)
|
||
{
|
||
if ((cbFirstCount < 4) || (cbFirstCount%2)!=0) return false;
|
||
|
||
//获取数值
|
||
cbNextLogicValue = GetCardLogicValue(cbNextCard[cbNextCount - 1]);
|
||
cbFirstLogicValue = GetCardLogicValue(cbFirstCard[cbFirstCount - 1]);
|
||
|
||
//if (cbNextLogicValue > cbFirstLogicValue) return true;
|
||
if (cbNextLogicValue > cbFirstLogicValue)
|
||
{
|
||
// 重置牌型;
|
||
pNextOutCard->cbCardType = (1 << CT_DOUBLE_LINE);
|
||
return true;
|
||
}
|
||
|
||
}
|
||
else if ((cbNextType&(1 << CT_THREE_LINE)) != 0)
|
||
{
|
||
// 三带二牌数判断;
|
||
if (cbFirstCount < 6 || cbNextCount < 6) return false;
|
||
|
||
// 不是最后一手牌必须是5的倍数;
|
||
if (!isFirstLastCard && (cbFirstCount%5) != 0) return false;
|
||
if (!isNextLastCard && (cbNextCount%5) != 0) return false;
|
||
|
||
// 都不是最后一手牌,两个牌数必须相同;
|
||
if (!isFirstLastCard &&!isNextLastCard && (cbNextCount != cbFirstCount)) return false;
|
||
|
||
BYTE cbNextBlockCount = 0, cbFirstBlockCount = 0;
|
||
if (!AnalysebCompare(cbNextCard, cbNextCount, NextResult, cbNextBlockCount, CT_THREE_LINE, isNextLastCard))return false;
|
||
if (!AnalysebCompare(cbFirstCard, cbFirstCount, FirstResult, cbFirstBlockCount, CT_THREE_LINE, isFirstLastCard))return false;
|
||
|
||
if (cbNextBlockCount != cbFirstBlockCount) return false;
|
||
|
||
//获取数值
|
||
cbNextLogicValue = GetCardLogicValue(NextResult[CT_THREE_LINE]);
|
||
cbFirstLogicValue = GetCardLogicValue(FirstResult[CT_THREE_LINE]);
|
||
|
||
//if (cbNextLogicValue > cbFirstLogicValue) return true;
|
||
if (cbNextLogicValue > cbFirstLogicValue)
|
||
{
|
||
// 重置牌型;
|
||
pNextOutCard->cbCardType = (1 << CT_THREE_LINE);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
//赖子数目
|
||
BYTE CGameLogic::GetLaiZiCount(const BYTE cbHandCardData[], BYTE cbHandCardCount)
|
||
{
|
||
BYTE bLaiZiCount=0;
|
||
for(BYTE i=0;i<cbHandCardCount;i++)
|
||
{
|
||
if (IsLaiZiCard(cbHandCardData[i]))
|
||
bLaiZiCount++;
|
||
}
|
||
|
||
return bLaiZiCount;
|
||
}
|
||
|
||
//是否癞子牌
|
||
bool CGameLogic::IsLaiZiCard(BYTE cbCard)
|
||
{
|
||
ASSERT(IsValidCard(cbCard));
|
||
|
||
if (0x40 == GetCardColor(cbCard))
|
||
{
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
//分析扑克
|
||
void CGameLogic::AnalysebCardData(const BYTE cbCardData[], BYTE cbCardCount, tagAnalyseResult & AnalyseResult)
|
||
{
|
||
//设置变量
|
||
BYTE cbTmpCardData[MAX_COUNT] = { 0 };
|
||
CopyMemory(cbTmpCardData, cbCardData, sizeof(BYTE)*cbCardCount);
|
||
|
||
SortCardList(cbTmpCardData, cbCardCount, ST_ORDER);
|
||
|
||
//扑克分析
|
||
for (BYTE i = 0; i < cbCardCount; i++)
|
||
{
|
||
//变量定义
|
||
BYTE cbSameCount = 1, cbCardValueTemp = 0;
|
||
BYTE cbLogicValue = GetCardLogicValue(cbTmpCardData[i]);
|
||
|
||
//搜索同牌
|
||
for (BYTE j = i + 1; j < cbCardCount; j++)
|
||
{
|
||
//获取扑克
|
||
if (GetCardLogicValue(cbTmpCardData[j]) != cbLogicValue) break;
|
||
|
||
//设置变量
|
||
cbSameCount++;
|
||
}
|
||
|
||
//设置结果
|
||
BYTE cbIndex = AnalyseResult.cbBlockCount[cbSameCount - 1]++;
|
||
for (BYTE j = 0; j < cbSameCount; j++)
|
||
{
|
||
AnalyseResult.cbCardData[cbSameCount - 1][cbIndex*cbSameCount + j] = cbTmpCardData[i + j];
|
||
}
|
||
|
||
//设置索引
|
||
i += cbSameCount - 1;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//分析比较
|
||
bool CGameLogic::AnalysebCompare(const BYTE cbCardData[], BYTE cbCardCount, BYTE cbMaxCardData[CT_COUNT], BYTE &cbBlockCount, int dCardType, bool isLastCard)
|
||
{
|
||
// 重置;
|
||
cbBlockCount = 0;
|
||
ZeroMemory(cbMaxCardData, sizeof(cbMaxCardData));
|
||
|
||
// 癞子分析;
|
||
BYTE cbNormalCard[MAX_COUNT] = { 0 };
|
||
BYTE cbMagicCardCount = 0; // 大小王数量;
|
||
BYTE cbNormalCardCount = 0; // 正常牌数量;
|
||
|
||
//变幻准备
|
||
for (BYTE i = 0; i < cbCardCount; i++)
|
||
{
|
||
if (IsLaiZiCard(cbCardData[i]))
|
||
{
|
||
cbMagicCardCount++;
|
||
}
|
||
else
|
||
{
|
||
cbNormalCard[cbNormalCardCount++] = cbCardData[i];
|
||
}
|
||
}
|
||
|
||
int dCardTypeTemp = CT_ERROR;
|
||
dCardTypeTemp = 1 << dCardType;
|
||
|
||
// 没有癞子;
|
||
if (cbMagicCardCount == 0)
|
||
{
|
||
BYTE bCardDataTemp[MAX_COUNT] = { 0 };
|
||
CopyMemory(bCardDataTemp, cbCardData, sizeof(BYTE)*cbCardCount);
|
||
|
||
//分析扑克
|
||
tagAnalyseResult AnalyseResultTemp;
|
||
ZeroMemory(&AnalyseResultTemp, sizeof(AnalyseResultTemp));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResultTemp);
|
||
|
||
//int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbTmpMaxCardData = 0, cbTmpBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, cbTmpMaxCardData, cbTmpBlockCount, isLastCard);
|
||
|
||
if ((dCardTypeTemp&(1 << iCardType)) != 0)
|
||
{
|
||
//AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
if (cbMaxCardData[iCardType] < cbTmpMaxCardData)
|
||
{
|
||
cbBlockCount = cbTmpBlockCount;
|
||
cbMaxCardData[iCardType] = cbTmpMaxCardData;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (cbMagicCardCount >= 1)
|
||
{
|
||
tagAnalyseResult AnalyseResultTemp;
|
||
ZeroMemory(&AnalyseResultTemp, sizeof(AnalyseResultTemp));
|
||
|
||
BYTE bCardDataTemp[MAX_COUNT] = { 0 };
|
||
CopyMemory(&bCardDataTemp[cbMagicCardCount], cbNormalCard, sizeof(BYTE)*cbNormalCardCount);
|
||
|
||
for (BYTE i = 0; i < 13; i++)
|
||
{
|
||
bCardDataTemp[0] = m_cbCardData[i];
|
||
|
||
//两张赖子
|
||
if (cbMagicCardCount >= 2)
|
||
{
|
||
for (BYTE z = 0; z < 13; z++)
|
||
{
|
||
bCardDataTemp[1] = m_cbCardData[z];
|
||
|
||
//三张赖子
|
||
if (cbMagicCardCount >= 3)
|
||
{
|
||
for (BYTE f = 0; f < 13; f++)
|
||
{
|
||
bCardDataTemp[2] = m_cbCardData[f];
|
||
|
||
//四张赖子
|
||
if (cbMagicCardCount == 4)
|
||
{
|
||
for (BYTE l = 0; l < 13; l++)
|
||
{
|
||
bCardDataTemp[3] = m_cbCardData[l];
|
||
|
||
ZeroMemory(&AnalyseResultTemp, sizeof(AnalyseResultTemp));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResultTemp);
|
||
|
||
//int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbTmpMaxCardData = 0, cbTmpBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, cbTmpMaxCardData, cbTmpBlockCount,isLastCard);
|
||
|
||
if ((dCardTypeTemp&(1 << iCardType)) != 0)
|
||
{
|
||
//AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
//if (cbMaxCardData[iCardType] < cbTmpMaxCardData)
|
||
if (GetCardLogicValue(cbMaxCardData[iCardType]) < GetCardLogicValue(cbTmpMaxCardData))
|
||
{
|
||
cbBlockCount = cbTmpBlockCount;
|
||
cbMaxCardData[iCardType] = cbTmpMaxCardData;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ZeroMemory(&AnalyseResultTemp, sizeof(AnalyseResultTemp));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResultTemp);
|
||
|
||
//int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbTmpMaxCardData = 0, cbTmpBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, cbTmpMaxCardData, cbTmpBlockCount, isLastCard);
|
||
|
||
if ((dCardTypeTemp&(1 << iCardType)) != 0)
|
||
{
|
||
//AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
//if (cbMaxCardData[iCardType] < cbTmpMaxCardData)
|
||
if (GetCardLogicValue(cbMaxCardData[iCardType]) < GetCardLogicValue(cbTmpMaxCardData))
|
||
{
|
||
cbBlockCount = cbTmpBlockCount;
|
||
cbMaxCardData[iCardType] = cbTmpMaxCardData;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ZeroMemory(&AnalyseResultTemp, sizeof(AnalyseResultTemp));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResultTemp);
|
||
|
||
//int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbTmpMaxCardData = 0, cbTmpBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, cbTmpMaxCardData, cbTmpBlockCount, isLastCard);
|
||
|
||
if ((dCardTypeTemp&(1 << iCardType)) != 0)
|
||
{
|
||
//AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
//if (cbMaxCardData[iCardType] < cbTmpMaxCardData)
|
||
if (GetCardLogicValue(cbMaxCardData[iCardType]) < GetCardLogicValue(cbTmpMaxCardData))
|
||
{
|
||
cbBlockCount = cbTmpBlockCount;
|
||
cbMaxCardData[iCardType] = cbTmpMaxCardData;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ZeroMemory(&AnalyseResultTemp, sizeof(AnalyseResultTemp));
|
||
|
||
AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResultTemp);
|
||
|
||
//int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, isLastCard);
|
||
BYTE cbTmpMaxCardData = 0, cbTmpBlockCount = 0;
|
||
int iCardType = GetType(AnalyseResultTemp, bCardDataTemp, cbCardCount, cbTmpMaxCardData, cbTmpBlockCount, isLastCard);
|
||
|
||
if ((dCardTypeTemp&(1 << iCardType)) != 0)
|
||
{
|
||
//AnalysebCardData(bCardDataTemp, cbCardCount, AnalyseResult);
|
||
//if (cbMaxCardData[iCardType] < cbTmpMaxCardData)
|
||
if (GetCardLogicValue(cbMaxCardData[iCardType]) < GetCardLogicValue(cbTmpMaxCardData))
|
||
{
|
||
cbBlockCount = cbTmpBlockCount;
|
||
cbMaxCardData[iCardType] = cbTmpMaxCardData;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
//随机扑克
|
||
BYTE CGameLogic::GetRandomCard(void)
|
||
{
|
||
size_t cbIndex = rand()%(sizeof(m_cbCardData)) ;
|
||
return m_cbCardData[cbIndex] ;
|
||
}
|
||
|
||
//排列扑克
|
||
void CGameLogic::SortOutCardList(BYTE cbCardData[], BYTE cbCardCount, int nCardType, bool isLastCard)
|
||
{
|
||
return;
|
||
}
|
||
|
||
//牌组转换 (将32张牌的使用情况转化为一个32位整型)
|
||
int CGameLogic::TransListToInt(int iOldType,int iNewType)
|
||
{
|
||
//数据校验
|
||
if(iNewType == 0) return 0;
|
||
|
||
//变量定义
|
||
int nList = 0;
|
||
ASSERT(iNewType != -1);
|
||
nList |= (1<<iNewType);
|
||
|
||
return iOldType|nList;
|
||
}
|
||
|
||
//是否包含牌型
|
||
bool CGameLogic::IsHasCardType(int iCardType, CART_TYPE ct_value)
|
||
{
|
||
if (iCardType == CT_ERROR) return false;
|
||
|
||
return ((iCardType&(1 << ct_value)) != 0);
|
||
}
|
||
|