1885 lines
48 KiB
C++
1885 lines
48 KiB
C++
#include "PDK_GameLogic.h"
|
||
#include <assert.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//静态变量
|
||
|
||
//索引变量
|
||
const uint8 cbIndexCount = 5;
|
||
|
||
//16张玩法:去掉大小王,3个2,1个A
|
||
const uint8 CPDKGameLogic::m_cbCardData16[PDK_FULL_COUNT] =
|
||
{
|
||
0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, //方块 A - K
|
||
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, //梅花 A - K
|
||
0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, //红桃 A - K
|
||
0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, //黑桃 A - K
|
||
0x01, 0x11, 0x21, 0x22
|
||
};
|
||
|
||
//15张玩法:去掉大小王,3个2,3个A,1个K
|
||
const uint8 CPDKGameLogic::m_cbCardData15[PDK_FULL_COUNT_15] =
|
||
{
|
||
0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, //方块 A - K
|
||
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, //梅花 A - K
|
||
0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, //红桃 A - K
|
||
0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, //黑桃 A - K
|
||
0x21, 0x22
|
||
};
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
//构造函数
|
||
CPDKGameLogic::CPDKGameLogic()
|
||
{
|
||
}
|
||
|
||
//析构函数
|
||
CPDKGameLogic::~CPDKGameLogic()
|
||
{
|
||
}
|
||
|
||
//获取类型
|
||
uint8 CPDKGameLogic::GetCardType(const uint8 cbCardData[], uint8 cbCardCount, bool isLastCard)
|
||
{
|
||
//简单牌型
|
||
switch (cbCardCount)
|
||
{
|
||
case 0: //空牌
|
||
{
|
||
return PDK_CT_ERROR;
|
||
}
|
||
case 1: //单牌
|
||
{
|
||
return PDK_CT_SINGLE;
|
||
}
|
||
case 2: //对牌
|
||
{
|
||
//牌型判断
|
||
if (GetCardLogicValue(cbCardData[0]) == GetCardLogicValue(cbCardData[1])) return PDK_CT_DOUBLE;
|
||
|
||
return PDK_CT_ERROR;
|
||
}
|
||
}
|
||
|
||
//分析扑克
|
||
tagPDKAnalyseResult AnalyseResult;
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
//四牌判断
|
||
if (AnalyseResult.cbBlockCount[3] == 1)
|
||
{
|
||
//牌型判断
|
||
if ((AnalyseResult.cbBlockCount[3] == 1) && (cbCardCount == 4)) return PDK_CT_BOMB_CARD;
|
||
|
||
// 四带一算三带二;
|
||
if ((AnalyseResult.cbBlockCount[3] == 1) && (cbCardCount == 5)) return PDK_CT_THREE_TAKE_TWO;
|
||
|
||
// 允许四带三;
|
||
if (IsHasGameRule(ePDKRuleEnum_FOUR_TAKE_THREE))
|
||
{
|
||
// 最后一手牌,四炸可以带一或二张;
|
||
if (isLastCard)
|
||
{
|
||
if ((AnalyseResult.cbBlockCount[3] == 1) && (cbCardCount <= 7) && (cbCardCount > 5)) return PDK_CT_FOUR_TAKE_THREE;
|
||
}
|
||
else
|
||
{
|
||
if ((AnalyseResult.cbBlockCount[3] == 1) && (cbCardCount == 7)) return PDK_CT_FOUR_TAKE_THREE;
|
||
}
|
||
}
|
||
|
||
//return PDK_CT_ERROR;
|
||
}
|
||
|
||
// 3A炸弹;
|
||
if ((3 == cbCardCount) && IsHasGameRule(ePDKRuleEnum_3ABomb) && (1 == AnalyseResult.cbBlockCount[2]))
|
||
{
|
||
uint8 cbCardData = AnalyseResult.cbCardData[2][0];
|
||
uint8 cbCardValue = GetCardValue(cbCardData);
|
||
if (0x01 == cbCardValue) // 是A;
|
||
{
|
||
return PDK_CT_3A_BOMB_CARD;
|
||
}
|
||
}
|
||
|
||
//三带二(只有一个3条);
|
||
if (1 == AnalyseResult.cbBlockCount[2])
|
||
{
|
||
//牌形判断
|
||
if (isLastCard)
|
||
{
|
||
// 三带二;
|
||
if (5 >= cbCardCount) return PDK_CT_THREE_TAKE_TWO;
|
||
}
|
||
else
|
||
{
|
||
// 三带二;
|
||
if (5 == cbCardCount) return PDK_CT_THREE_TAKE_TWO;
|
||
}
|
||
}
|
||
|
||
//两张类型(全是对子);
|
||
if ((AnalyseResult.cbBlockCount[1] >= 2) && (AnalyseResult.cbBlockCount[1] * 2 == cbCardCount))
|
||
{
|
||
//变量定义
|
||
uint8 cbCardData = AnalyseResult.cbCardData[1][0];
|
||
uint8 cbFirstLogicValue = GetCardLogicValue(cbCardData);
|
||
|
||
// 连牌不能带2;
|
||
if (cbFirstLogicValue >= GetCardLogicValue(0x02)) return PDK_CT_ERROR;
|
||
|
||
//连牌判断
|
||
for (uint8 i = 1; i < AnalyseResult.cbBlockCount[1]; i++)
|
||
{
|
||
uint8 cbCardData = AnalyseResult.cbCardData[1][i * 2];
|
||
if (cbFirstLogicValue != (GetCardLogicValue(cbCardData) + i)) return PDK_CT_ERROR;
|
||
}
|
||
|
||
//二连判断
|
||
if ((AnalyseResult.cbBlockCount[1] * 2) == cbCardCount) return PDK_CT_DOUBLE_LINE;
|
||
|
||
return PDK_CT_ERROR;
|
||
}
|
||
|
||
//单张判断(全是单牌只可能是顺子);
|
||
if ((AnalyseResult.cbBlockCount[0] >= 5) && (AnalyseResult.cbBlockCount[0] == cbCardCount))
|
||
{
|
||
//变量定义
|
||
uint8 cbCardData = AnalyseResult.cbCardData[0][0];
|
||
uint8 cbFirstLogicValue = GetCardLogicValue(cbCardData);
|
||
|
||
// 连牌不能带2;
|
||
if (cbFirstLogicValue >= GetCardLogicValue(0x02)) return PDK_CT_ERROR;
|
||
|
||
//连牌判断
|
||
for (uint8 i = 1; i < AnalyseResult.cbBlockCount[0]; i++)
|
||
{
|
||
uint8 cbCardData = AnalyseResult.cbCardData[0][i];
|
||
if (cbFirstLogicValue != (GetCardLogicValue(cbCardData) + i)) return PDK_CT_ERROR;
|
||
}
|
||
|
||
return PDK_CT_SINGLE_LINE;
|
||
}
|
||
|
||
//三连判断;
|
||
if (AnalyseResult.cbBlockCount[2] + AnalyseResult.cbBlockCount[3] > 1)
|
||
{
|
||
// 不是最后一手牌,三连必须是5的倍数;
|
||
if (!isLastCard && (cbCardCount % 5 != 0)) return PDK_CT_ERROR;
|
||
uint8 cbCardType = PDK_CT_ERROR;
|
||
|
||
uint8 cbLineCardData[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbLineLength = 0;
|
||
|
||
// 目前只从3取到5张相同牌(将3到5张相同的牌放到同一个数组,用来检测是不是连牌);
|
||
for (uint8 i = 2; i <= 3; i++)
|
||
{
|
||
for (uint8 j = 0; j < AnalyseResult.cbBlockCount[i]; j++)
|
||
{
|
||
uint8 cbTmpCardDate = AnalyseResult.cbCardData[i][j*(i + 1)];
|
||
|
||
// 连牌不带2;
|
||
if (GetCardLogicValue(cbTmpCardDate) >= GetCardLogicValue(0x02)) continue;
|
||
|
||
cbLineCardData[cbLineLength] = cbTmpCardDate;
|
||
cbLineLength++;
|
||
}
|
||
}
|
||
|
||
// 重新排序;
|
||
SortCardList(cbLineCardData, cbLineLength, PDK_ST_ORDER);
|
||
|
||
uint8 cbLastValue = GetCardLogicValue(cbLineCardData[0]);
|
||
//错误过虑(3~A)
|
||
if (cbLastValue > GetCardLogicValue(0x01)) return PDK_CT_ERROR;
|
||
|
||
// 查找三连数量;
|
||
uint8 cbMaxThreeLength = 1;
|
||
uint8 cbThreeLength = 1;
|
||
uint8 cbMaxThreeCardData = cbLineCardData[0];
|
||
|
||
for (uint8 i = 1; i < cbLineLength; i++)
|
||
{
|
||
uint8 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))
|
||
{
|
||
cbCardType = PDK_CT_THREE_LINE;
|
||
}
|
||
else if (!isLastCard)
|
||
{
|
||
// 计算几个三带二
|
||
uint8 cbTmpBlockCount = cbCardCount / 5;
|
||
if (cbMaxThreeLength == cbTmpBlockCount)
|
||
{
|
||
cbCardType = PDK_CT_THREE_LINE;
|
||
}
|
||
}
|
||
|
||
return cbCardType;
|
||
}
|
||
|
||
return PDK_CT_ERROR;
|
||
}
|
||
|
||
//排列扑克
|
||
void CPDKGameLogic::SortCardList(uint8 cbCardData[], uint8 cbCardCount, uint8 cbSortType)
|
||
{
|
||
//数目过虑
|
||
if (cbCardCount == 0) return;
|
||
if (cbSortType == PDK_ST_CUSTOM) return;
|
||
|
||
//转换数值
|
||
uint8 cbSortValue[PDK_MAX_COUNT];
|
||
for (uint8 i = 0; i < cbCardCount; i++)
|
||
{
|
||
cbSortValue[i] = GetCardLogicValue(cbCardData[i]);
|
||
}
|
||
|
||
//排序操作
|
||
bool bSorted = true;
|
||
uint8 cbSwitchData = 0, cbLast = cbCardCount - 1;
|
||
do
|
||
{
|
||
bSorted = true;
|
||
for (uint8 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);
|
||
|
||
//数目排序
|
||
if (cbSortType == PDK_ST_COUNT)
|
||
{
|
||
//变量定义
|
||
uint8 cbCardIndex = 0;
|
||
|
||
//分析扑克
|
||
tagPDKAnalyseResult AnalyseResult;
|
||
AnalysebCardData(&cbCardData[cbCardIndex], cbCardCount - cbCardIndex, AnalyseResult);
|
||
|
||
//提取扑克
|
||
for (uint8 i = 0; i < CountArray(AnalyseResult.cbBlockCount); i++)
|
||
{
|
||
//拷贝扑克
|
||
uint8 cbIndex = CountArray(AnalyseResult.cbBlockCount) - i - 1;
|
||
memcpy(&cbCardData[cbCardIndex], AnalyseResult.cbCardData[cbIndex], AnalyseResult.cbBlockCount[cbIndex] * (cbIndex + 1)*sizeof(uint8));
|
||
|
||
//设置索引
|
||
cbCardIndex += AnalyseResult.cbBlockCount[cbIndex] * (cbIndex + 1)*sizeof(uint8);
|
||
}
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//删除扑克
|
||
bool CPDKGameLogic::RemoveCardList(const uint8 cbRemoveCard[], uint8 cbRemoveCount, uint8 cbCardData[], uint8 cbCardCount)
|
||
{
|
||
//检验数据
|
||
assert(cbRemoveCount <= cbCardCount);
|
||
|
||
//定义变量
|
||
uint8 cbDeleteCount = 0, cbTempCardData[PDK_MAX_COUNT];
|
||
if (cbCardCount > CountArray(cbTempCardData)) return false;
|
||
memcpy(cbTempCardData, cbCardData, cbCardCount*sizeof(cbCardData[0]));
|
||
|
||
//置零扑克
|
||
for (uint8 i = 0; i < cbRemoveCount; i++)
|
||
{
|
||
for (uint8 j = 0; j < cbCardCount; j++)
|
||
{
|
||
if (cbRemoveCard[i] == cbTempCardData[j])
|
||
{
|
||
cbDeleteCount++;
|
||
cbTempCardData[j] = 0;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (cbDeleteCount != cbRemoveCount) return false;
|
||
|
||
//清理扑克
|
||
uint8 cbCardPos = 0;
|
||
for (uint8 i = 0; i < cbCardCount; i++)
|
||
{
|
||
if (cbTempCardData[i] != 0) cbCardData[cbCardPos++] = cbTempCardData[i];
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
//删除扑克
|
||
bool CPDKGameLogic::RemoveCard(const uint8 cbRemoveCard[], uint8 cbRemoveCount, uint8 cbCardData[], uint8 cbCardCount)
|
||
{
|
||
//检验数据
|
||
assert(cbRemoveCount <= cbCardCount);
|
||
|
||
//定义变量
|
||
uint8 cbDeleteCount = 0, cbTempCardData[PDK_MAX_COUNT];
|
||
if (cbCardCount > CountArray(cbTempCardData)) return false;
|
||
memcpy(cbTempCardData, cbCardData, cbCardCount*sizeof(cbCardData[0]));
|
||
|
||
//置零扑克
|
||
for (uint8 i = 0; i < cbRemoveCount; i++)
|
||
{
|
||
for (uint8 j = 0; j < cbCardCount; j++)
|
||
{
|
||
if (cbRemoveCard[i] == cbTempCardData[j])
|
||
{
|
||
cbDeleteCount++;
|
||
cbTempCardData[j] = 0;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (cbDeleteCount != cbRemoveCount) return false;
|
||
|
||
//清理扑克
|
||
uint8 cbCardPos = 0;
|
||
for (uint8 i = 0; i < cbCardCount; i++)
|
||
{
|
||
if (cbTempCardData[i] != 0) cbCardData[cbCardPos++] = cbTempCardData[i];
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
//排列扑克
|
||
void CPDKGameLogic::SortOutCardList(uint8 cbCardData[], uint8 cbCardCount, bool isLastCard)
|
||
{
|
||
//获取牌型
|
||
uint8 cbCardType = GetCardType(cbCardData, cbCardCount, isLastCard);
|
||
|
||
// AAA+BB 结构;
|
||
if (cbCardType == PDK_CT_THREE_TAKE_TWO)
|
||
{
|
||
//分析牌
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
// 三张数量;
|
||
uint8 cbTmpCardCount = 3;
|
||
//CopyMemory(cbCardData, AnalyseResult.cbCardData[2], sizeof(uint8)*cbTmpCardCount);
|
||
|
||
if (AnalyseResult.cbBlockCount[2] == 1)
|
||
{
|
||
for (uint8 i = 0; i < cbTmpCardCount; i++)
|
||
{
|
||
cbCardData[i] = AnalyseResult.cbCardData[2][i];
|
||
AnalyseResult.cbCardData[2][i] = 0x0;
|
||
}
|
||
}
|
||
else if (AnalyseResult.cbBlockCount[3] == 1)
|
||
{
|
||
uint8 i = 0;
|
||
for (i = 0; i < cbTmpCardCount; i++)
|
||
{
|
||
cbCardData[i] = AnalyseResult.cbCardData[3][i];
|
||
AnalyseResult.cbCardData[3][i] = 0x0;
|
||
}
|
||
|
||
// 第三张牌;
|
||
cbCardData[i] = AnalyseResult.cbCardData[3][i];
|
||
AnalyseResult.cbCardData[3][i] = 0x0;
|
||
cbTmpCardCount++;
|
||
}
|
||
|
||
for (int i = CountArray(AnalyseResult.cbBlockCount) - 1; i >= 0; i--)
|
||
{
|
||
if (i >= 2) continue;
|
||
|
||
if (AnalyseResult.cbBlockCount[i] > 0)
|
||
{
|
||
CopyMemory(&cbCardData[cbTmpCardCount], AnalyseResult.cbCardData[i], sizeof(uint8)*(i + 1)*AnalyseResult.cbBlockCount[i]);
|
||
|
||
cbTmpCardCount += (i + 1)*AnalyseResult.cbBlockCount[i];
|
||
}
|
||
}
|
||
}
|
||
else if (cbCardType == PDK_CT_FOUR_TAKE_THREE)
|
||
{
|
||
//分析牌
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
uint8 cbTmpCardCount = 4;
|
||
CopyMemory(cbCardData, AnalyseResult.cbCardData[3], sizeof(uint8)*cbTmpCardCount);
|
||
|
||
for (int i = CountArray(AnalyseResult.cbBlockCount) - 1; i >= 0; i--)
|
||
{
|
||
if (i == 3) continue;
|
||
|
||
if (AnalyseResult.cbBlockCount[i] > 0)
|
||
{
|
||
CopyMemory(&cbCardData[cbTmpCardCount], AnalyseResult.cbCardData[i], sizeof(uint8)*(i + 1)*AnalyseResult.cbBlockCount[i]);
|
||
|
||
cbTmpCardCount += (i + 1)*AnalyseResult.cbBlockCount[i];
|
||
}
|
||
}
|
||
}
|
||
else if (cbCardType == PDK_CT_THREE_LINE)
|
||
{
|
||
//分析牌
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
//三连判断;
|
||
if (AnalyseResult.cbBlockCount[2] + AnalyseResult.cbBlockCount[3] > 1)
|
||
{
|
||
uint8 cbLineCardData[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbLineLength = 0;
|
||
|
||
// 目前只从3取到5张相同牌(将3到5张相同的牌放到同一个数组,用来检测是不是连牌);
|
||
for (uint8 i = 2; i <= 3; i++)
|
||
{
|
||
if (AnalyseResult.cbBlockCount[i] > 0)
|
||
{
|
||
for (uint8 j = 0; j < AnalyseResult.cbBlockCount[i]; j++)
|
||
{
|
||
uint8 cbTmpCardDate = AnalyseResult.cbCardData[i][j*(i + 1)];
|
||
|
||
// 连牌不带2;
|
||
if (GetCardLogicValue(cbTmpCardDate) > GetCardLogicValue(0x02)) continue;
|
||
|
||
cbLineCardData[cbLineLength] = cbTmpCardDate;
|
||
cbLineLength++;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 重新排序;
|
||
SortCardList(cbLineCardData, cbLineLength, PDK_ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagPDKDistributing Distributing = {};
|
||
AnalysebDistributing(cbCardData, cbCardCount, Distributing);
|
||
|
||
uint8 cbLastValue = GetCardLogicValue(cbLineCardData[0]);
|
||
|
||
// 查找三连数量;
|
||
uint8 cbMaxThreeLength = 1;
|
||
uint8 cbThreeLength = 1;
|
||
uint8 cbMaxThreeCardData = cbLineCardData[0];
|
||
|
||
for (uint8 i = 1; i < cbLineLength; i++)
|
||
{
|
||
uint8 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];
|
||
}
|
||
|
||
// 计算几个三带二
|
||
uint8 cbTmpBlockCount = cbCardCount / 5;
|
||
if (isLastCard || (cbMaxThreeLength == cbTmpBlockCount))
|
||
{
|
||
// 根据最大值和块长度重新分配;
|
||
uint8 cbTmpCard[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbMaxIndex = GetCardLogicValue(cbMaxThreeCardData);
|
||
|
||
uint8 cbCount = 0;
|
||
for (uint8 cbIndex = cbMaxIndex; cbIndex > (cbMaxIndex - cbTmpBlockCount); cbIndex--)
|
||
{
|
||
uint8 cbTmpCount = 0;
|
||
for (uint8 cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (uint8 cbColorCount = 0; cbColorCount < Distributing.cbDistributing[cbIndex][3 - cbColorIndex]; cbColorCount++)
|
||
{
|
||
cbTmpCard[cbCount++] = MakeCardData(cbIndex, 3 - cbColorIndex);
|
||
|
||
Distributing.cbDistributing[cbIndex][3 - cbColorIndex]--;
|
||
|
||
if (++cbTmpCount == 3) break;
|
||
}
|
||
|
||
if (cbTmpCount == 3) break;
|
||
}
|
||
}
|
||
|
||
// 带牌;
|
||
for (uint8 i = 0; i <= GetCardLogicValue(0x02); i++)
|
||
{
|
||
for (uint8 cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (uint8 cbColorCount = 0; cbColorCount < Distributing.cbDistributing[i][3 - cbColorIndex]; cbColorCount++)
|
||
{
|
||
cbTmpCard[cbCount++] = MakeCardData(i, 3 - cbColorIndex);
|
||
|
||
Distributing.cbDistributing[i][3 - cbColorIndex]--;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (cbCardCount == cbCount)
|
||
{
|
||
CopyMemory(cbCardData, cbTmpCard, cbCount);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//排列扑克
|
||
BYTE CPDKGameLogic::SortOutCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbCardType, BYTE cbBlockCount)
|
||
{
|
||
BYTE cbMaxCardData = 0x0;
|
||
|
||
// AAA+BB 结构;
|
||
if (cbCardType == PDK_CT_THREE_TAKE_TWO)
|
||
{
|
||
//分析牌
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
if (AnalyseResult.cbBlockCount[2] == 1)
|
||
{
|
||
cbMaxCardData = AnalyseResult.cbCardData[2][0];
|
||
}
|
||
else if (AnalyseResult.cbBlockCount[3] == 1)
|
||
{
|
||
cbMaxCardData = AnalyseResult.cbCardData[3][0];
|
||
}
|
||
}
|
||
else if (cbCardType == PDK_CT_FOUR_TAKE_THREE)
|
||
{
|
||
//分析牌
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
if (AnalyseResult.cbBlockCount[3] == 1)
|
||
{
|
||
cbMaxCardData = AnalyseResult.cbCardData[3][0];
|
||
}
|
||
}
|
||
else if (cbCardType == PDK_CT_THREE_LINE)
|
||
{
|
||
//分析牌
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
//三连判断;
|
||
if (AnalyseResult.cbBlockCount[2] + AnalyseResult.cbBlockCount[3] > 1)
|
||
{
|
||
BYTE cbLineCardData[PDK_MAX_COUNT] = { 0 };
|
||
BYTE cbLineLength = 0;
|
||
|
||
// 目前只从3取到4张相同牌(将3到4张相同的牌放到同一个数组,用来检测是不是连牌);
|
||
for (BYTE i = 2; i <= 3; 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) >= GetCardLogicValue(0x02)) continue;
|
||
|
||
cbLineCardData[cbLineLength] = cbTmpCardDate;
|
||
cbLineLength++;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 重新排序;
|
||
SortCardList(cbLineCardData, cbLineLength, PDK_ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagPDKDistributing Distributing = {};
|
||
AnalysebDistributing(cbCardData, cbCardCount, Distributing);
|
||
|
||
BYTE cbLastValue = GetCardLogicValue(cbLineCardData[0]);
|
||
|
||
// 查找三连数量;
|
||
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 (cbMaxThreeLength >= cbBlockCount)
|
||
{
|
||
cbMaxCardData = cbMaxThreeCardData;
|
||
}
|
||
}
|
||
}
|
||
|
||
return cbMaxCardData;
|
||
}
|
||
|
||
//有效判断
|
||
bool CPDKGameLogic::IsValidCard(uint8 cbCardData)
|
||
{
|
||
//获取属性
|
||
uint8 cbCardColor = GetCardColor(cbCardData);
|
||
uint8 cbCardValue = GetCardValue(cbCardData);
|
||
|
||
//有效判断
|
||
//if ((cbCardData == 0x4E) || (cbCardData == 0x4F)) return true;
|
||
if ((cbCardColor <= 0x30) && (cbCardValue >= 0x01) && (cbCardValue <= 0x0D)) return true;
|
||
|
||
return false;
|
||
}
|
||
|
||
//逻辑数值
|
||
uint8 CPDKGameLogic::GetCardLogicValue(uint8 cbCardData)
|
||
{
|
||
if (!IsValidCard(cbCardData)) return 0;
|
||
|
||
//扑克属性
|
||
uint8 cbCardColor = GetCardColor(cbCardData);
|
||
uint8 cbCardValue = GetCardValue(cbCardData);
|
||
|
||
//转换数值
|
||
if (cbCardColor == 0x40) return cbCardValue + 2;
|
||
return (cbCardValue <= 2) ? (cbCardValue + 13) : cbCardValue;
|
||
}
|
||
|
||
//获取最大牌;
|
||
uint8 CPDKGameLogic::GetMaxLogicValue(const uint8 cbHandCardData[], uint8 cbHandCardCount)
|
||
{
|
||
if (cbHandCardCount <= 0) return 0;
|
||
|
||
uint8 cbCardData[PDK_MAX_COUNT] = { 0 };
|
||
CopyMemory(cbCardData, cbHandCardData, cbHandCardCount);
|
||
|
||
// 重新排序;
|
||
SortCardList(cbCardData, cbHandCardCount, PDK_ST_ORDER);
|
||
|
||
return GetCardLogicValue(cbCardData[0]);
|
||
}
|
||
|
||
//获取最大牌;
|
||
uint8 CPDKGameLogic::GetMaxCardData(const uint8 cbHandCardData[], uint8 cbHandCardCount)
|
||
{
|
||
if (cbHandCardCount <= 0) return 0;
|
||
|
||
uint8 cbCardData[PDK_MAX_COUNT] = { 0 };
|
||
CopyMemory(cbCardData, cbHandCardData, cbHandCardCount);
|
||
|
||
// 重新排序;
|
||
SortCardList(cbCardData, cbHandCardCount, PDK_ST_ORDER);
|
||
|
||
return (cbCardData[0]);
|
||
}
|
||
|
||
//对比扑克
|
||
bool CPDKGameLogic::CompareCard(const uint8 cbFirstCard[], const uint8 cbNextCard[], uint8 cbFirstCount, uint8 cbNextCount, bool isLastCard)
|
||
{
|
||
//获取类型
|
||
uint8 cbNextType = GetCardType(cbNextCard, cbNextCount, isLastCard);
|
||
uint8 cbFirstType = GetCardType(cbFirstCard, cbFirstCount, false);
|
||
|
||
//类型判断
|
||
if (cbNextType == PDK_CT_ERROR) return false;
|
||
if (cbNextType == PDK_CT_3A_BOMB_CARD) return true;
|
||
|
||
//炸弹判断
|
||
if ((cbFirstType != PDK_CT_BOMB_CARD) && (cbNextType == PDK_CT_BOMB_CARD)) return true;
|
||
if ((cbFirstType == PDK_CT_BOMB_CARD) && (cbNextType != PDK_CT_BOMB_CARD)) return false;
|
||
|
||
//规则判断
|
||
if (cbFirstType != cbNextType) return false;
|
||
|
||
//开始对比
|
||
switch (cbNextType)
|
||
{
|
||
case PDK_CT_SINGLE:
|
||
case PDK_CT_DOUBLE:
|
||
case PDK_CT_SINGLE_LINE:
|
||
case PDK_CT_DOUBLE_LINE:
|
||
case PDK_CT_BOMB_CARD:
|
||
{
|
||
// 牌数必须相同;
|
||
if (cbFirstCount != cbNextCount) return false;
|
||
|
||
//获取数值
|
||
uint8 cbNextLogicValue = GetCardLogicValue(cbNextCard[0]);
|
||
uint8 cbFirstLogicValue = GetCardLogicValue(cbFirstCard[0]);
|
||
|
||
//对比扑克
|
||
return cbNextLogicValue > cbFirstLogicValue;
|
||
}
|
||
case PDK_CT_THREE_TAKE_TWO:
|
||
{
|
||
// 三带二牌数判断;
|
||
if (cbFirstCount < 3 || cbFirstCount > 5) return false;
|
||
if (cbNextCount < 3 || cbNextCount > 5) return false;
|
||
|
||
// 不是最后一手牌必须是5张;
|
||
if (cbFirstCount != 5) return false;
|
||
if (!isLastCard && cbNextCount != 5) return false;
|
||
|
||
//分析扑克
|
||
tagPDKAnalyseResult NextResult;
|
||
tagPDKAnalyseResult FirstResult;
|
||
AnalysebCardData(cbNextCard, cbNextCount, NextResult);
|
||
AnalysebCardData(cbFirstCard, cbFirstCount, FirstResult);
|
||
|
||
//获取数值
|
||
//uint8 cbFirstLogicValue = GetCardLogicValue(FirstResult.cbCardData[2][0]);
|
||
uint8 cbFirstLogicValue = 0x0;
|
||
uint8 cbNextLogicValue = 0x0;
|
||
|
||
// 四带一算三带二;
|
||
if (1 == FirstResult.cbBlockCount[2])
|
||
{
|
||
cbFirstLogicValue = GetCardLogicValue(FirstResult.cbCardData[2][0]);
|
||
}
|
||
else if (1 == FirstResult.cbBlockCount[3])
|
||
{
|
||
cbFirstLogicValue = GetCardLogicValue(FirstResult.cbCardData[3][0]);
|
||
}
|
||
if (1 == NextResult.cbBlockCount[2])
|
||
{
|
||
cbNextLogicValue = GetCardLogicValue(NextResult.cbCardData[2][0]);
|
||
}
|
||
else if (1 == NextResult.cbBlockCount[3])
|
||
{
|
||
cbNextLogicValue = GetCardLogicValue(NextResult.cbCardData[3][0]);
|
||
}
|
||
|
||
//对比扑克
|
||
return cbNextLogicValue > cbFirstLogicValue;
|
||
}
|
||
case PDK_CT_FOUR_TAKE_THREE:
|
||
{
|
||
// 四带三牌数判断;
|
||
if (cbFirstCount < 5 || cbFirstCount > 7) return false;
|
||
if (cbNextCount < 5 || cbNextCount > 7) return false;
|
||
|
||
// 不是最后一手牌必须是7张;
|
||
if (cbFirstCount != 7) return false;
|
||
if (!isLastCard && cbNextCount != 7) return false;
|
||
|
||
//分析扑克
|
||
tagPDKAnalyseResult NextResult;
|
||
tagPDKAnalyseResult FirstResult;
|
||
AnalysebCardData(cbNextCard, cbNextCount, NextResult);
|
||
AnalysebCardData(cbFirstCard, cbFirstCount, FirstResult);
|
||
|
||
//获取数值
|
||
uint8 cbNextLogicValue = GetCardLogicValue(NextResult.cbCardData[3][0]);
|
||
uint8 cbFirstLogicValue = GetCardLogicValue(FirstResult.cbCardData[3][0]);
|
||
|
||
//对比扑克
|
||
return cbNextLogicValue > cbFirstLogicValue;
|
||
}
|
||
case PDK_CT_THREE_LINE:
|
||
{
|
||
// 飞机至少牌数是3*2;
|
||
if (cbFirstCount < 6 || cbNextCount < 6) return false;
|
||
|
||
// 不是最后一手牌必须是5的倍数;
|
||
if ((cbFirstCount % 5) != 0) return false;
|
||
if (!isLastCard && (cbNextCount % 5) != 0) return false;
|
||
|
||
// 不是最后一手牌,两个牌数必须相同;
|
||
if (!isLastCard && (cbNextCount != cbFirstCount)) return false;
|
||
|
||
// 是最后一手,必须不大于于上家出牌数;
|
||
if (isLastCard && (cbNextCount > cbFirstCount)) return false;
|
||
|
||
// 获取三连长度;
|
||
BYTE cbFirstBlockCount = cbFirstCount / 5;
|
||
BYTE cbFirstCardData = SortOutCardList((BYTE*)cbFirstCard, cbFirstCount, PDK_CT_THREE_LINE, cbFirstBlockCount);
|
||
BYTE cbNextCardData = SortOutCardList((BYTE*)cbNextCard, cbNextCount, PDK_CT_THREE_LINE, cbFirstBlockCount);
|
||
|
||
//获取数值
|
||
BYTE cbNextLogicValue = GetCardLogicValue(cbNextCardData);
|
||
BYTE cbFirstLogicValue = GetCardLogicValue(cbFirstCardData);
|
||
|
||
//// 获取三连长度;
|
||
//uint8 cbFirstBlockCount = GetThreeLineBlockCount(cbFirstCard, cbFirstCount, false);
|
||
//uint8 cbNextBlockCount = GetThreeLineBlockCount(cbNextCard, cbNextCount, isLastCard);
|
||
|
||
//// 三连长度必须一样;
|
||
//if (cbNextBlockCount >= cbFirstBlockCount) return false;
|
||
|
||
//uint8 cbFirstTurnCard[PDK_MAX_COUNT] = {};
|
||
//CopyMemory(cbFirstTurnCard, cbFirstCard, sizeof(uint8)*cbFirstCount);
|
||
//SortOutCardList(cbFirstTurnCard, cbFirstCount, false);
|
||
|
||
//uint8 cbNextTurnCard[PDK_MAX_COUNT] = {};
|
||
//CopyMemory(cbNextTurnCard, cbNextCard, sizeof(uint8)*cbNextCount);
|
||
//SortOutCardList(cbNextTurnCard, cbNextCount, isLastCard);
|
||
|
||
////获取数值
|
||
//uint8 cbNextLogicValue = GetCardLogicValue(cbNextTurnCard[0]);
|
||
//uint8 cbFirstLogicValue = GetCardLogicValue(cbFirstTurnCard[0]);
|
||
|
||
//对比扑克
|
||
return cbNextLogicValue > cbFirstLogicValue;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
//构造扑克
|
||
uint8 CPDKGameLogic::MakeCardData(uint8 cbLogicValue, uint8 cbColorIndex)
|
||
{
|
||
//return (cbColorIndex << 4) | (cbValueIndex + 1);
|
||
|
||
uint8 cbCardColor = (cbColorIndex << 4);
|
||
|
||
//转换数值
|
||
if (cbLogicValue > 0x0D)
|
||
{
|
||
cbLogicValue -= 0x0D;
|
||
}
|
||
|
||
return (cbCardColor | cbLogicValue);
|
||
}
|
||
|
||
//分析扑克
|
||
void CPDKGameLogic::AnalysebCardData(const uint8 cbCardData[], uint8 cbCardCount, tagPDKAnalyseResult & AnalyseResult)
|
||
{
|
||
//设置结果
|
||
zeromemory(&AnalyseResult, sizeof(tagPDKAnalyseResult));
|
||
|
||
//扑克分析
|
||
for (uint8 i = 0; i < cbCardCount; i++)
|
||
{
|
||
//变量定义
|
||
uint8 cbSameCount = 1;
|
||
uint8 cbLogicValue = GetCardLogicValue(cbCardData[i]);
|
||
|
||
//搜索同牌
|
||
for (uint8 j = i + 1; j < cbCardCount; j++)
|
||
{
|
||
//获取扑克
|
||
if (GetCardLogicValue(cbCardData[j]) != cbLogicValue) break;
|
||
|
||
//设置变量
|
||
cbSameCount++;
|
||
}
|
||
|
||
//设置结果
|
||
uint8 cbIndex = AnalyseResult.cbBlockCount[cbSameCount - 1]++;
|
||
for (uint8 j = 0; j < cbSameCount; j++) AnalyseResult.cbCardData[cbSameCount - 1][cbIndex*cbSameCount + j] = cbCardData[i + j];
|
||
|
||
//设置索引
|
||
i += cbSameCount - 1;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//分析分布
|
||
void CPDKGameLogic::AnalysebDistributing(const uint8 cbCardData[], uint8 cbCardCount, tagPDKDistributing & Distributing)
|
||
{
|
||
//设置变量
|
||
zeromemory(&Distributing, sizeof(tagPDKDistributing));
|
||
|
||
//设置变量
|
||
for (uint8 i = 0; i < cbCardCount; i++)
|
||
{
|
||
if (cbCardData[i] == 0) continue;
|
||
|
||
////获取属性
|
||
//uint8 cbCardColor = GetCardColor(cbCardData[i]);
|
||
//uint8 cbCardValue = GetCardValue(cbCardData[i]);
|
||
|
||
////分布信息
|
||
//Distributing.cbCardCount++;
|
||
//Distributing.cbDistributing[cbCardValue - 1][cbIndexCount]++;
|
||
//Distributing.cbDistributing[cbCardValue - 1][cbCardColor >> 4]++;
|
||
|
||
|
||
//获取属性
|
||
uint8 cbCardColor = GetCardColor(cbCardData[i]);
|
||
uint8 cbCardValue = GetCardLogicValue(cbCardData[i]);
|
||
|
||
//分布信息
|
||
Distributing.cbCardCount++;
|
||
Distributing.cbDistributing[cbCardValue][cbIndexCount]++;
|
||
Distributing.cbDistributing[cbCardValue][cbCardColor >> 4]++;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//出牌搜索
|
||
uint8 CPDKGameLogic::SearchOutCard(const uint8 cbHandCardData[], uint8 cbHandCardCount, const uint8 cbTurnCardData[], uint8 cbTurnCardCount,
|
||
tagPDKSearchCardResult *pSearchCardResult)
|
||
{
|
||
//设置结果
|
||
ASSERT(pSearchCardResult != NULL);
|
||
if (pSearchCardResult == NULL) return 0;
|
||
zeromemory(pSearchCardResult, sizeof(tagPDKSearchCardResult));
|
||
|
||
//变量定义
|
||
uint8 cbResultCount = 0;
|
||
tagPDKSearchCardResult tmpSearchCardResult = {};
|
||
|
||
//构造扑克
|
||
uint8 cbCardData[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbCardCount = cbHandCardCount;
|
||
CopyMemory(cbCardData, cbHandCardData, sizeof(uint8)*cbHandCardCount);
|
||
|
||
//排列扑克
|
||
SortCardList(cbCardData, cbCardCount, PDK_ST_ORDER);
|
||
|
||
//获取类型(必然不是最后一手牌);
|
||
uint8 cbTurnOutType = GetCardType(cbTurnCardData, cbTurnCardCount, false);
|
||
|
||
if (PDK_CT_ERROR == cbTurnOutType) return 0;
|
||
|
||
|
||
// 先当做最后一首牌处理;
|
||
if (CompareCard(cbTurnCardData, cbCardData, cbTurnCardCount, cbCardCount, true) == true)
|
||
{
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbCardCount;
|
||
memcpy(pSearchCardResult->cbResultCard[cbResultCount], cbCardData, sizeof(uint8)*cbCardCount);
|
||
cbResultCount++;
|
||
}
|
||
else
|
||
{
|
||
//出牌分析
|
||
switch (cbTurnOutType)
|
||
{
|
||
case PDK_CT_SINGLE: //单牌类型
|
||
case PDK_CT_DOUBLE: //对牌类型
|
||
{
|
||
//变量定义
|
||
uint8 cbReferCard = cbTurnCardData[0];
|
||
uint8 cbSameCount = 1;
|
||
if (cbTurnOutType == PDK_CT_DOUBLE) cbSameCount = 2;
|
||
|
||
//搜索相同牌
|
||
cbResultCount = SearchSameCard(cbCardData, cbCardCount, cbReferCard, cbSameCount, pSearchCardResult);
|
||
|
||
break;
|
||
}
|
||
case PDK_CT_SINGLE_LINE: //单连类型
|
||
{
|
||
//变量定义
|
||
uint8 cbReferCard = cbTurnCardData[cbTurnCardCount - 1];
|
||
cbResultCount = SearchSingleLine(cbCardData, cbCardCount, cbReferCard, cbTurnCardCount, pSearchCardResult);
|
||
break;
|
||
}
|
||
case PDK_CT_DOUBLE_LINE: //对连类型
|
||
{
|
||
//变量定义
|
||
uint8 cbReferCard = cbTurnCardData[cbTurnCardCount - 1];
|
||
uint8 cbLineCount = cbTurnCardCount / 2;
|
||
cbResultCount = SearchDoubleLine(cbCardData, cbCardCount, cbReferCard, cbLineCount, pSearchCardResult);
|
||
break;
|
||
}
|
||
case PDK_CT_THREE_LINE: //三连类型
|
||
{
|
||
//效验牌数
|
||
if (cbCardCount < cbTurnCardCount) break;
|
||
|
||
uint8 cbBlockCount = cbTurnCardCount / 5;
|
||
|
||
//uint8 cbTmpTurnCard[PDK_MAX_COUNT] = { 0 };
|
||
//CopyMemory(cbTmpTurnCard, cbTurnCardData, sizeof(uint8)*cbTurnCardCount);
|
||
//SortOutCardList(cbTmpTurnCard, cbTurnCardCount, false);
|
||
|
||
BYTE cbTmpTurnCard = SortOutCardList((BYTE*)cbTurnCardData, cbTurnCardCount, PDK_CT_THREE_LINE, cbBlockCount);
|
||
cbResultCount = SearchThreeLineTakeTwo(cbCardData, cbCardCount, cbTmpTurnCard, cbBlockCount, pSearchCardResult);
|
||
|
||
break;
|
||
}
|
||
case PDK_CT_THREE_TAKE_TWO: //三带一对
|
||
{
|
||
//效验牌数
|
||
if (cbCardCount < cbTurnCardCount) break;
|
||
|
||
//uint8 cbTmpTurnCard[PDK_MAX_COUNT] = { 0 };
|
||
//CopyMemory(cbTmpTurnCard, cbTurnCardData, sizeof(uint8)*cbTurnCardCount);
|
||
//SortOutCardList(cbTmpTurnCard, cbTurnCardCount, false);
|
||
|
||
//搜索三带牌型
|
||
BYTE cbTmpTurnCard = SortOutCardList((BYTE*)cbTurnCardData, cbTurnCardCount, PDK_CT_THREE_TAKE_TWO, 1);
|
||
cbResultCount = SearchThreeTakeTwo(cbCardData, cbCardCount, cbTmpTurnCard, pSearchCardResult);
|
||
|
||
break;
|
||
}
|
||
case PDK_CT_FOUR_TAKE_THREE: //四带三
|
||
{
|
||
//效验牌数
|
||
if (!IsHasGameRule(ePDKRuleEnum_FOUR_TAKE_THREE)) break;
|
||
if (cbCardCount < cbTurnCardCount) break;
|
||
|
||
//uint8 cbTmpTurnCard[PDK_MAX_COUNT] = { 0 };
|
||
//CopyMemory(cbTmpTurnCard, cbTurnCardData, sizeof(uint8)*cbTurnCardCount);
|
||
//SortOutCardList(cbTmpTurnCard, cbTurnCardCount, false);
|
||
|
||
//搜索带牌
|
||
BYTE cbTmpTurnCard = SortOutCardList((BYTE*)cbTurnCardData, cbTurnCardCount, PDK_CT_FOUR_TAKE_THREE, 1);
|
||
cbResultCount = SearchFourTakeThree(cbCardData, cbCardCount, cbTmpTurnCard, pSearchCardResult);
|
||
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
|
||
//搜索炸弹
|
||
if ((cbCardCount >= 4) && (cbTurnOutType != PDK_CT_3A_BOMB_CARD))
|
||
{
|
||
//变量定义
|
||
uint8 cbReferCard = 0;
|
||
if (cbTurnOutType == PDK_CT_BOMB_CARD) cbReferCard = cbTurnCardData[0];
|
||
|
||
//搜索炸弹
|
||
uint8 cbTmpResultCount = SearchSameCard(cbCardData, cbCardCount, cbReferCard, 4, &tmpSearchCardResult);
|
||
for (uint8 i = 0; i < cbTmpResultCount; i++)
|
||
{
|
||
pSearchCardResult->cbCardCount[cbResultCount] = tmpSearchCardResult.cbCardCount[i];
|
||
CopyMemory(pSearchCardResult->cbResultCard[cbResultCount], tmpSearchCardResult.cbResultCard[i],
|
||
sizeof(uint8)*tmpSearchCardResult.cbCardCount[i]);
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
|
||
//搜索火箭(0x01,0x11,0x21)
|
||
if (cbTurnOutType != PDK_CT_3A_BOMB_CARD && (cbCardCount >= 3) && (IsHasGameRule(ePDKRuleEnum_3ABomb)))
|
||
{
|
||
uint8 cbACard[3] = { 0 };
|
||
uint8 cbACardCount = 0;
|
||
|
||
//有三张A;
|
||
for (uint8 i = 0; i < cbCardCount; i++)
|
||
{
|
||
if (GetCardValue(cbCardData[i]) == 0x01)
|
||
{
|
||
cbACard[cbACardCount] = cbCardData[i];
|
||
cbACardCount++;
|
||
}
|
||
}
|
||
|
||
// 3A炸弹
|
||
if (3 == cbACardCount)
|
||
{
|
||
//设置结果
|
||
pSearchCardResult->cbCardCount[cbResultCount] = 3;
|
||
pSearchCardResult->cbResultCard[cbResultCount][0] = cbACard[0];
|
||
pSearchCardResult->cbResultCard[cbResultCount][1] = cbACard[1];
|
||
pSearchCardResult->cbResultCard[cbResultCount][2] = cbACard[2];
|
||
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
return cbResultCount;
|
||
}
|
||
|
||
//同牌搜索
|
||
uint8 CPDKGameLogic::SearchSameCard(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbSameCardCount,
|
||
tagPDKSearchCardResult *pSearchCardResult)
|
||
{
|
||
//设置结果
|
||
if (pSearchCardResult)
|
||
{
|
||
zeromemory(pSearchCardResult, sizeof(tagPDKSearchCardResult));
|
||
}
|
||
uint8 cbResultCount = 0;
|
||
|
||
//构造扑克
|
||
uint8 cbCardData[PDK_MAX_COUNT];
|
||
uint8 cbCardCount = cbHandCardCount;
|
||
memcpy(cbCardData, cbHandCardData, sizeof(uint8)*cbHandCardCount);
|
||
|
||
//排列扑克
|
||
SortCardList(cbCardData, cbCardCount, PDK_ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
uint8 cbReferLogicValue = (cbReferCard == 0) ? 0 : GetCardLogicValue(cbReferCard);
|
||
uint8 cbBlockIndex = cbSameCardCount - 1;
|
||
do
|
||
{
|
||
for (uint8 i = 0; i < AnalyseResult.cbBlockCount[cbBlockIndex]; i++)
|
||
{
|
||
uint8 cbIndex = (AnalyseResult.cbBlockCount[cbBlockIndex] - i - 1)*(cbBlockIndex + 1);
|
||
if (GetCardLogicValue(AnalyseResult.cbCardData[cbBlockIndex][cbIndex]) > cbReferLogicValue)
|
||
{
|
||
if (pSearchCardResult == NULL) return 1;
|
||
|
||
assert(cbResultCount < CountArray(pSearchCardResult->cbCardCount));
|
||
|
||
//复制扑克
|
||
memcpy(pSearchCardResult->cbResultCard[cbResultCount], &AnalyseResult.cbCardData[cbBlockIndex][cbIndex],
|
||
cbSameCardCount*sizeof(uint8));
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbSameCardCount;
|
||
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
|
||
cbBlockIndex++;
|
||
} while (cbBlockIndex < CountArray(AnalyseResult.cbBlockCount));
|
||
|
||
if (pSearchCardResult)
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
return cbResultCount;
|
||
}
|
||
|
||
//搜索比出牌;
|
||
bool CPDKGameLogic::SearchMustOutCard(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbMustOutCard)
|
||
{
|
||
if (!IsValidCard(cbMustOutCard)) return false;
|
||
|
||
for (uint8 i = 0; i < cbHandCardCount; i++)
|
||
{
|
||
if (cbHandCardData[i] == cbMustOutCard)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//搜索单顺;
|
||
uint8 CPDKGameLogic::SearchSingleLine(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbLineCount, tagPDKSearchCardResult *pSearchCardResult)
|
||
{
|
||
//设置结果
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
if (cbLineCount < 5) return 0;
|
||
|
||
//定义变量
|
||
uint8 cbResultCount = 0;
|
||
uint8 cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
zeromemory(pSearchCardResult, sizeof(tagPDKSearchCardResult));
|
||
|
||
//超过A
|
||
if (cbReferIndex + cbLineCount > GetCardLogicValue(0x01) + 1)
|
||
{
|
||
return cbResultCount;
|
||
}
|
||
|
||
//长度判断
|
||
if (cbHandCardCount < cbLineCount)
|
||
{
|
||
return cbResultCount;
|
||
}
|
||
|
||
// 癞子分析;
|
||
uint8 cbNormalCard[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbNormalCardCount = 0; // 正常牌数量;
|
||
|
||
//变幻准备
|
||
for (uint8 i = 0; i < cbHandCardCount; i++)
|
||
{
|
||
cbNormalCard[cbNormalCardCount++] = cbHandCardData[i];
|
||
}
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, PDK_ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagPDKDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//搜索顺子
|
||
uint8 cbMaxIndex = GetCardLogicValue(0x01) - cbLineCount + 1;
|
||
|
||
// 不带癞子;
|
||
for (uint8 i = cbReferIndex; i <= cbMaxIndex; i++)
|
||
{
|
||
if ((Distributing.cbDistributing[i][cbIndexCount] < 1) && (i != cbMaxIndex)) continue;
|
||
|
||
uint8 cbTmpLinkCount = 0; // 当前最大连牌数;
|
||
|
||
for (uint8 j = i; j <= GetCardLogicValue(0x01); j++)
|
||
{
|
||
//继续判断
|
||
if (Distributing.cbDistributing[j][cbIndexCount] < 1)
|
||
{
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
cbTmpLinkCount++;
|
||
}
|
||
|
||
// 找到足够大的连牌;
|
||
if (cbTmpLinkCount >= cbLineCount)
|
||
{
|
||
//复制扑克
|
||
uint8 cbCount = 0;
|
||
for (uint8 cbIndex = i; cbIndex <= j; cbIndex++)
|
||
{
|
||
uint8 cbTmpCount = 0;
|
||
for (uint8 cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (uint8 cbColorCount = 0; cbColorCount < Distributing.cbDistributing[cbIndex][3 - cbColorIndex]; cbColorCount++)
|
||
{
|
||
pSearchCardResult->cbResultCard[cbResultCount][cbCount++] = MakeCardData(cbIndex, 3 - cbColorIndex);
|
||
|
||
if (++cbTmpCount == 1) break;
|
||
}
|
||
|
||
if (cbTmpCount == 1) break;
|
||
}
|
||
}
|
||
|
||
//设置变量
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbCount;
|
||
cbResultCount++;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pSearchCardResult)
|
||
{
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
}
|
||
|
||
return cbResultCount;
|
||
}
|
||
|
||
//搜索双顺;
|
||
uint8 CPDKGameLogic::SearchDoubleLine(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbLineCount, tagPDKSearchCardResult *pSearchCardResult)
|
||
{
|
||
//设置结果
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
if (cbLineCount < 2) return 0;
|
||
|
||
//定义变量
|
||
uint8 cbResultCount = 0;
|
||
uint8 cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
zeromemory(pSearchCardResult, sizeof(tagPDKSearchCardResult));
|
||
|
||
//超过A
|
||
if (cbReferIndex + cbLineCount > GetCardLogicValue(0x01) + 1)
|
||
{
|
||
return cbResultCount;
|
||
}
|
||
|
||
//长度判断
|
||
if (cbHandCardCount < cbLineCount * 2)
|
||
{
|
||
return cbResultCount;
|
||
}
|
||
|
||
// 癞子分析;
|
||
uint8 cbNormalCard[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbNormalCardCount = 0; // 正常牌数量;
|
||
|
||
//变幻准备
|
||
for (uint8 i = 0; i < cbHandCardCount; i++)
|
||
{
|
||
cbNormalCard[cbNormalCardCount++] = cbHandCardData[i];
|
||
}
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, PDK_ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagPDKDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//搜索顺子
|
||
uint8 cbMaxIndex = GetCardLogicValue(0x01) - cbLineCount + 1;
|
||
|
||
// 不带癞子;
|
||
for (uint8 i = cbReferIndex; i <= cbMaxIndex; i++)
|
||
{
|
||
if ((Distributing.cbDistributing[i][cbIndexCount] < 1) && (i != cbMaxIndex)) continue;
|
||
|
||
uint8 cbTmpLinkCount = 0; // 当前最大连牌数;
|
||
uint8 cbUseMagicCount = 0; // 已经使用癞子数量;
|
||
|
||
for (uint8 j = i; j <= GetCardLogicValue(0x01); j++)
|
||
{
|
||
// 有2张牌;
|
||
if (Distributing.cbDistributing[j][cbIndexCount] >= 2)
|
||
{
|
||
cbTmpLinkCount++;
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
|
||
// 找到足够大的连牌;
|
||
if (cbTmpLinkCount >= cbLineCount)
|
||
{
|
||
//复制扑克
|
||
uint8 cbCount = 0;
|
||
for (uint8 cbIndex = i; cbIndex <= j; cbIndex++)
|
||
{
|
||
uint8 cbTmpCount = 0;
|
||
for (uint8 cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (uint8 cbColorCount = 0; cbColorCount < Distributing.cbDistributing[cbIndex][3 - cbColorIndex]; cbColorCount++)
|
||
{
|
||
pSearchCardResult->cbResultCard[cbResultCount][cbCount++] = MakeCardData(cbIndex, 3 - cbColorIndex);
|
||
|
||
if (++cbTmpCount == 2) break;
|
||
}
|
||
|
||
if (cbTmpCount == 2) break;
|
||
}
|
||
}
|
||
|
||
//设置变量
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbCount;
|
||
cbResultCount++;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pSearchCardResult)
|
||
{
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
}
|
||
|
||
return cbResultCount;
|
||
}
|
||
|
||
//搜索三带二;
|
||
uint8 CPDKGameLogic::SearchThreeTakeTwo(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, tagPDKSearchCardResult *pSearchCardResult)
|
||
{
|
||
if (cbHandCardCount < 5) return 0;
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
|
||
//定义变量
|
||
uint8 cbResultCount = 0;
|
||
uint8 cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
zeromemory(pSearchCardResult, sizeof(tagPDKSearchCardResult));
|
||
|
||
// 只有一张2,不可能存在2的三个头;
|
||
if (cbReferIndex > GetCardLogicValue(0x01)) return 0;
|
||
|
||
//构造扑克
|
||
uint8 cbNormalCard[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbNormalCardCount = cbHandCardCount;
|
||
memcpy(cbNormalCard, cbHandCardData, sizeof(uint8)*cbHandCardCount);
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, PDK_ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagPDKDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//分析扑克
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbNormalCard, cbNormalCardCount, AnalyseResult);
|
||
|
||
uint8 cbMaxIndex = GetCardLogicValue(0x01);
|
||
|
||
// 不带癞子搜索(下标是逻辑值-1);
|
||
for (uint8 i = cbReferIndex; i <= cbMaxIndex; i++)
|
||
{
|
||
// 没有不做变幻;
|
||
if (Distributing.cbDistributing[i][cbIndexCount] == 0) continue;
|
||
|
||
// 三带二
|
||
if (Distributing.cbDistributing[i][cbIndexCount] == 3)
|
||
{
|
||
// 先找带牌,如果找不到带牌,则牌型不成立;
|
||
uint8 cbTmpCount = 0;
|
||
uint8 cbTakeCard[5] = { 0 };
|
||
|
||
//复制扑克
|
||
for (uint8 cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (uint8 cbColorCount = 0; cbColorCount < Distributing.cbDistributing[i][cbColorIndex]; cbColorCount++)
|
||
{
|
||
cbTakeCard[cbTmpCount++] = MakeCardData(i, cbColorIndex);
|
||
|
||
if (cbTmpCount == 3) break;
|
||
}
|
||
|
||
if (cbTmpCount == 3) break;
|
||
}
|
||
|
||
for (uint8 j = 0; j < CountArray(AnalyseResult.cbBlockCount); j++)
|
||
{
|
||
for (uint8 k = 0; k < AnalyseResult.cbBlockCount[j]; k++)
|
||
{
|
||
// 带牌的起始位置;
|
||
uint8 cbIndex = (AnalyseResult.cbBlockCount[j] - k - 1)*(j + 1);
|
||
|
||
// 过滤相同牌;
|
||
if (i == GetCardLogicValue(AnalyseResult.cbCardData[j][cbIndex]))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
// 提取带牌;
|
||
for (uint8 n = 0; n < j + 1; n++)
|
||
{
|
||
cbTakeCard[cbTmpCount++] = AnalyseResult.cbCardData[j][cbIndex + n];
|
||
if (cbTmpCount == 5) break;
|
||
}
|
||
|
||
if (cbTmpCount == 5) break;
|
||
}
|
||
|
||
if (cbTmpCount == 5) break;
|
||
}
|
||
|
||
if (cbTmpCount == 5)
|
||
{
|
||
//设置变量
|
||
CopyMemory(pSearchCardResult->cbResultCard[cbResultCount], cbTakeCard, sizeof(uint8)*cbTmpCount);
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbTmpCount;
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pSearchCardResult)
|
||
{
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
}
|
||
|
||
return cbResultCount;
|
||
}
|
||
|
||
//搜索四带三;
|
||
uint8 CPDKGameLogic::SearchFourTakeThree(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, tagPDKSearchCardResult *pSearchCardResult)
|
||
{
|
||
if (cbHandCardCount < 7) return 0;
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
|
||
//定义变量
|
||
uint8 cbResultCount = 0;
|
||
uint8 cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 大过该牌型的最小牌型;
|
||
zeromemory(pSearchCardResult, sizeof(tagPDKSearchCardResult));
|
||
|
||
// 只有一张2,这里不可能;
|
||
if (cbReferIndex > GetCardLogicValue(0x01)) return 0;
|
||
|
||
//构造扑克
|
||
uint8 cbNormalCard[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbNormalCardCount = cbHandCardCount;
|
||
memcpy(cbNormalCard, cbHandCardData, sizeof(uint8)*cbHandCardCount);
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, PDK_ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagPDKDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//分析扑克
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbNormalCard, cbNormalCardCount, AnalyseResult);
|
||
|
||
//uint8 cbMinIndex = GetCardLogicValue(0x03);
|
||
uint8 cbMaxIndex = GetCardLogicValue(0x01);
|
||
|
||
// 不带癞子搜索;
|
||
for (uint8 i = cbReferIndex; i <= cbMaxIndex; i++)
|
||
{
|
||
// 没有不做变幻;
|
||
if (Distributing.cbDistributing[i][cbIndexCount] == 0) continue;
|
||
|
||
// 四带三;
|
||
if (Distributing.cbDistributing[i][cbIndexCount] == 4)
|
||
{
|
||
// 先找带牌,如果找不到带牌,则牌型不成立;
|
||
uint8 cbTmpCount = 0;
|
||
uint8 cbTakeCard[7] = { 0 };
|
||
|
||
//复制扑克
|
||
for (uint8 cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (uint8 cbColorCount = 0; cbColorCount < Distributing.cbDistributing[i][cbColorIndex]; cbColorCount++)
|
||
{
|
||
cbTakeCard[cbTmpCount++] = MakeCardData(i, cbColorIndex);
|
||
|
||
if (cbTmpCount == 4) break;
|
||
}
|
||
|
||
if (cbTmpCount == 4) break;
|
||
}
|
||
|
||
for (uint8 j = 0; j < CountArray(AnalyseResult.cbBlockCount); j++)
|
||
{
|
||
for (uint8 k = 0; k < AnalyseResult.cbBlockCount[j]; k++)
|
||
{
|
||
// 带牌的起始位置;
|
||
uint8 cbIndex = (AnalyseResult.cbBlockCount[j] - k - 1)*(j + 1);
|
||
|
||
// 过滤相同牌;
|
||
if (i == GetCardLogicValue(AnalyseResult.cbCardData[j][cbIndex]))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
// 提取带牌;
|
||
for (uint8 n = 0; n < j + 1; n++)
|
||
{
|
||
cbTakeCard[cbTmpCount++] = AnalyseResult.cbCardData[j][cbIndex + n];
|
||
if (cbTmpCount == 7) break;
|
||
}
|
||
|
||
if (cbTmpCount == 7) break;
|
||
}
|
||
|
||
if (cbTmpCount == 7) break;
|
||
}
|
||
|
||
if (cbTmpCount == 7)
|
||
{
|
||
//设置变量
|
||
CopyMemory(pSearchCardResult->cbResultCard[cbResultCount], cbTakeCard, sizeof(uint8)*cbTmpCount);
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbTmpCount;
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pSearchCardResult)
|
||
{
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
}
|
||
|
||
return cbResultCount;
|
||
}
|
||
|
||
//搜索飞机;
|
||
uint8 CPDKGameLogic::SearchThreeLineTakeTwo(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard,
|
||
uint8 cbBlockCount, tagPDKSearchCardResult *pSearchCardResult)
|
||
{
|
||
//设置结果
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
if (cbHandCardCount < cbBlockCount * 5) return 0;
|
||
|
||
uint8 cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
|
||
//超过A
|
||
if ((cbReferIndex + cbBlockCount) > GetCardLogicValue(0x01)) return 0;
|
||
|
||
zeromemory(pSearchCardResult, sizeof(tagPDKSearchCardResult));
|
||
|
||
// 癞子分析;
|
||
uint8 cbNormalCard[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbNormalCardCount = 0; // 正常牌数量;
|
||
|
||
//变幻准备
|
||
for (uint8 i = 0; i < cbHandCardCount; i++)
|
||
{
|
||
cbNormalCard[cbNormalCardCount++] = cbHandCardData[i];
|
||
}
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, PDK_ST_ORDER);
|
||
|
||
//定义变量
|
||
uint8 cbResultCount = 0;
|
||
|
||
//分析扑克
|
||
tagPDKDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//搜索顺子
|
||
uint8 cbMaxIndex = GetCardLogicValue(0x01) - cbBlockCount + 1; //
|
||
|
||
// 不考虑癞子;
|
||
for (uint8 i = cbReferIndex; i <= cbMaxIndex; i++)
|
||
{
|
||
if ((Distributing.cbDistributing[i][cbIndexCount] < 1) && (i != cbMaxIndex)) continue;
|
||
|
||
uint8 cbTmpLinkCount = 0; // 当前最大连牌数;
|
||
uint8 cbUseMagicCount = 0; // 已经使用癞子数量;
|
||
uint8 cbTmpCard[PDK_MAX_COUNT] = { 0 };
|
||
|
||
for (uint8 j = i; j <= GetCardLogicValue(0x01); j++)
|
||
{
|
||
// 有2张牌;
|
||
if (Distributing.cbDistributing[j][cbIndexCount] >= 3)
|
||
{
|
||
cbTmpLinkCount++;
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
|
||
// 找到足够大的连牌;
|
||
if (cbTmpLinkCount >= cbBlockCount)
|
||
{
|
||
//复制扑克
|
||
uint8 cbCount = 0;
|
||
for (uint8 cbIndex = i; cbIndex <= j; cbIndex++)
|
||
{
|
||
uint8 cbTmpCount = 0;
|
||
for (uint8 cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (uint8 cbColorCount = 0; cbColorCount < Distributing.cbDistributing[cbIndex][3 - cbColorIndex]; cbColorCount++)
|
||
{
|
||
cbTmpCard[cbCount++] = MakeCardData(cbIndex, 3 - cbColorIndex);
|
||
|
||
if (++cbTmpCount == 3) break;
|
||
}
|
||
|
||
if (cbTmpCount == 3) break;
|
||
}
|
||
}
|
||
|
||
// 加入尾巴;
|
||
uint8 cbTakeCard[PDK_MAX_COUNT] = { 0 };
|
||
uint8 cbTakeCardCount = cbNormalCardCount;
|
||
CopyMemory(cbTakeCard, cbNormalCard, sizeof(uint8)*cbNormalCardCount);
|
||
|
||
// 将已经取出的牌删除;
|
||
if (RemoveCard(cbTmpCard, cbCount, cbTakeCard, cbNormalCardCount))
|
||
{
|
||
cbTakeCardCount -= cbCount;
|
||
}
|
||
|
||
// 分析剩余牌;
|
||
tagPDKAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbTakeCard, cbTakeCardCount, AnalyseResult);
|
||
|
||
for (uint8 j = 0; j < CountArray(AnalyseResult.cbBlockCount); j++)
|
||
{
|
||
for (uint8 k = 0; k < AnalyseResult.cbBlockCount[j]; k++)
|
||
{
|
||
// 带牌的起始位置;
|
||
uint8 cbIndex = (AnalyseResult.cbBlockCount[j] - k - 1)*(j + 1);
|
||
|
||
// 提取带牌;
|
||
for (uint8 n = 0; n < j + 1; n++)
|
||
{
|
||
cbTmpCard[cbCount++] = AnalyseResult.cbCardData[j][cbIndex + n];
|
||
if (cbCount == cbBlockCount * 5) break;
|
||
}
|
||
|
||
if (cbCount == cbBlockCount * 5) break;
|
||
}
|
||
|
||
if (cbCount == cbBlockCount * 5) break;
|
||
}
|
||
|
||
// 牌数不对;
|
||
if (cbCount != cbBlockCount * 5) break;
|
||
|
||
int iCardType = GetCardType(cbTmpCard, cbCount, false);
|
||
if (iCardType != PDK_CT_THREE_LINE) break;
|
||
|
||
// 找到牌型;
|
||
if (cbCount == cbBlockCount * 5)
|
||
{
|
||
//设置变量
|
||
CopyMemory(pSearchCardResult->cbResultCard[cbResultCount], cbTmpCard, sizeof(uint8)*cbCount);
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbCount;
|
||
cbResultCount++;
|
||
}
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pSearchCardResult)
|
||
{
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
}
|
||
|
||
return cbResultCount;
|
||
}
|
||
//
|
||
////得到飞机的块大小;
|
||
//uint8 CPDKGameLogic::GetThreeLineBlockCount(const uint8 cbCardData[], uint8 cbCardCount, bool isLastCard)
|
||
//{
|
||
// // 非最后一手牌,必须是5的倍数;
|
||
// if (!isLastCard) return cbCardCount / 5;
|
||
//
|
||
// // 5的倍数;
|
||
// if ((cbCardCount % 5) == 0) return cbCardCount / 5;
|
||
//
|
||
// //分析牌
|
||
// tagPDKAnalyseResult AnalyseResult = {};
|
||
// AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
//
|
||
// //三连判断;
|
||
// if (AnalyseResult.cbBlockCount[2] + AnalyseResult.cbBlockCount[3] > 1)
|
||
// {
|
||
// uint8 cbLineCardData[PDK_MAX_COUNT] = { 0 };
|
||
// uint8 cbLineLength = 0;
|
||
//
|
||
// // 目前只从3取到4张相同牌(将3到4张相同的牌放到同一个数组,用来检测是不是连牌);
|
||
// for (uint8 i = 2; i <= 3; i++)
|
||
// {
|
||
// if (AnalyseResult.cbBlockCount[i] > 0)
|
||
// {
|
||
// for (uint8 j = 0; j < AnalyseResult.cbBlockCount[i]; j++)
|
||
// {
|
||
// uint8 cbTmpCardDate = AnalyseResult.cbCardData[i][j*(i + 1)];
|
||
//
|
||
// // 连牌不带2;
|
||
// if (GetCardLogicValue(cbTmpCardDate) >= GetCardLogicValue(0x02)) continue;
|
||
//
|
||
// cbLineCardData[cbLineLength] = cbTmpCardDate;
|
||
// cbLineLength++;
|
||
// }
|
||
// }
|
||
// }
|
||
//
|
||
// // 重新排序;
|
||
// SortCardList(cbLineCardData, cbLineLength, PDK_ST_ORDER);
|
||
//
|
||
// //分析扑克
|
||
// tagPDKDistributing Distributing = {};
|
||
// AnalysebDistributing(cbCardData, cbCardCount, Distributing);
|
||
//
|
||
// uint8 cbLastValue = GetCardLogicValue(cbLineCardData[0]);
|
||
//
|
||
// // 查找三连数量;
|
||
// uint8 cbMaxThreeLength = 1;
|
||
// uint8 cbThreeLength = 1;
|
||
// uint8 cbMaxThreeCardData = cbLineCardData[0];
|
||
//
|
||
// for (uint8 i = 1; i < cbLineLength; i++)
|
||
// {
|
||
// uint8 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];
|
||
// }
|
||
//
|
||
// return cbMaxThreeLength;
|
||
// }
|
||
//
|
||
// return 0;
|
||
//}
|