1941 lines
48 KiB
C++
1941 lines
48 KiB
C++
#include "StdAfx.h"
|
||
#include "GameLogic.h"
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//静态变量
|
||
|
||
//索引变量
|
||
const BYTE cbIndexCount=5;
|
||
|
||
//16张玩法:去掉大小王,3个2,1个A
|
||
const BYTE CGameLogic::m_cbCardData16[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 BYTE CGameLogic::m_cbCardData15[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
|
||
};
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
//构造函数
|
||
CGameLogic::CGameLogic()
|
||
{
|
||
}
|
||
|
||
//析构函数
|
||
CGameLogic::~CGameLogic()
|
||
{
|
||
}
|
||
|
||
//获取类型
|
||
BYTE CGameLogic::GetCardType(const BYTE cbCardData[], BYTE cbCardCount, bool isLastCard)
|
||
{
|
||
//简单牌型
|
||
switch (cbCardCount)
|
||
{
|
||
case 0: //空牌
|
||
{
|
||
return CT_ERROR;
|
||
}
|
||
case 1: //单牌
|
||
{
|
||
return CT_SINGLE;
|
||
}
|
||
case 2: //对牌
|
||
{
|
||
//牌型判断
|
||
if (GetCardLogicValue(cbCardData[0]) == GetCardLogicValue(cbCardData[1])) return CT_DOUBLE;
|
||
|
||
return CT_ERROR;
|
||
}
|
||
}
|
||
|
||
//分析扑克
|
||
tagAnalyseResult AnalyseResult;
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
//四牌判断
|
||
if (AnalyseResult.cbBlockCount[3] == 1)
|
||
{
|
||
//牌型判断
|
||
if ((AnalyseResult.cbBlockCount[3] == 1) && (cbCardCount == 4)) return CT_BOMB_CARD;
|
||
|
||
// 四带一算三带二;
|
||
if ((AnalyseResult.cbBlockCount[3] == 1) && (cbCardCount == 5)) return CT_THREE_TAKE_TWO;
|
||
|
||
// 允许四带三;
|
||
if (IsHasGameRule(ePDKRuleEnum_FOUR_TAKE_THREE))
|
||
{
|
||
// 最后一手牌,四炸可以带一或二张;
|
||
if (isLastCard)
|
||
{
|
||
if ((AnalyseResult.cbBlockCount[3] == 1) && (cbCardCount <= 7) && (cbCardCount > 5)) return CT_FOUR_TAKE_THREE;
|
||
}
|
||
else
|
||
{
|
||
if ((AnalyseResult.cbBlockCount[3] == 1) && (cbCardCount == 7)) return CT_FOUR_TAKE_THREE;
|
||
}
|
||
}
|
||
|
||
//return CT_ERROR;
|
||
}
|
||
|
||
// 3A炸弹;
|
||
if ((3 == cbCardCount) && IsHasGameRule(ePDKRuleEnum_3ABomb) && (1 == AnalyseResult.cbBlockCount[2]))
|
||
{
|
||
BYTE cbCardData = AnalyseResult.cbCardData[2][0];
|
||
BYTE cbCardValue = GetCardValue(cbCardData);
|
||
if (0x01 == cbCardValue) // 是A;
|
||
{
|
||
return CT_3A_BOMB_CARD;
|
||
}
|
||
}
|
||
|
||
//三带二(只有一个3条);
|
||
if (1 == AnalyseResult.cbBlockCount[2])
|
||
{
|
||
//牌形判断
|
||
if (isLastCard)
|
||
{
|
||
// 三带二;
|
||
if (5 >= cbCardCount) return CT_THREE_TAKE_TWO;
|
||
}
|
||
else
|
||
{
|
||
// 三带二;
|
||
if (5 == cbCardCount) return CT_THREE_TAKE_TWO;
|
||
}
|
||
}
|
||
|
||
//两张类型(全是对子);
|
||
if ((AnalyseResult.cbBlockCount[1] >= 2) && (AnalyseResult.cbBlockCount[1] * 2 == cbCardCount))
|
||
{
|
||
//变量定义
|
||
BYTE cbCardData = AnalyseResult.cbCardData[1][0];
|
||
BYTE cbFirstLogicValue = GetCardLogicValue(cbCardData);
|
||
|
||
// 连牌不能带2;
|
||
if (cbFirstLogicValue >= GetCardLogicValue(0x02)) return CT_ERROR;
|
||
|
||
//连牌判断
|
||
for (BYTE i = 1; i < AnalyseResult.cbBlockCount[1]; i++)
|
||
{
|
||
BYTE cbCardData = AnalyseResult.cbCardData[1][i * 2];
|
||
if (cbFirstLogicValue != (GetCardLogicValue(cbCardData) + i)) return CT_ERROR;
|
||
}
|
||
|
||
//二连判断
|
||
if ((AnalyseResult.cbBlockCount[1] * 2) == cbCardCount) return CT_DOUBLE_LINE;
|
||
|
||
return CT_ERROR;
|
||
}
|
||
|
||
//单张判断(全是单牌只可能是顺子);
|
||
if ((AnalyseResult.cbBlockCount[0] >= 5) && (AnalyseResult.cbBlockCount[0] == cbCardCount))
|
||
{
|
||
//变量定义
|
||
BYTE cbCardData = AnalyseResult.cbCardData[0][0];
|
||
BYTE cbFirstLogicValue = GetCardLogicValue(cbCardData);
|
||
|
||
// 连牌不能带2;
|
||
if (cbFirstLogicValue >= GetCardLogicValue(0x02)) return CT_ERROR;
|
||
|
||
//连牌判断
|
||
for (BYTE i = 1; i < AnalyseResult.cbBlockCount[0]; i++)
|
||
{
|
||
BYTE cbCardData = AnalyseResult.cbCardData[0][i];
|
||
if (cbFirstLogicValue != (GetCardLogicValue(cbCardData) + i)) return CT_ERROR;
|
||
}
|
||
|
||
return CT_SINGLE_LINE;
|
||
}
|
||
|
||
//三连判断;
|
||
if (AnalyseResult.cbBlockCount[2] + AnalyseResult.cbBlockCount[3] > 1)
|
||
{
|
||
// 不是最后一手牌,三连必须是5的倍数;
|
||
if (!isLastCard && (cbCardCount % 5 != 0)) return CT_ERROR;
|
||
BYTE cbCardType = CT_ERROR;
|
||
|
||
BYTE cbLineCardData[MAX_COUNT] = { 0 };
|
||
BYTE cbLineLength = 0;
|
||
|
||
// 目前只从3取到4张相同牌(将3到4张相同的牌放到同一个数组,用来检测是不是连牌);
|
||
for (BYTE i = 2; i <= 3; i++)
|
||
{
|
||
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, ST_ORDER);
|
||
|
||
BYTE cbLastValue = GetCardLogicValue(cbLineCardData[0]);
|
||
//错误过虑(3~A)
|
||
if (cbLastValue > GetCardLogicValue(0x01)) 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))
|
||
{
|
||
cbCardType = CT_THREE_LINE;
|
||
}
|
||
else if (!isLastCard)
|
||
{
|
||
// 计算几个三带二
|
||
BYTE cbTmpBlockCount = cbCardCount / 5;
|
||
if (cbMaxThreeLength == cbTmpBlockCount)
|
||
{
|
||
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_CUSTOM) return;
|
||
|
||
//转换数值
|
||
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);
|
||
|
||
//数目排序
|
||
if (cbSortType==ST_COUNT)
|
||
{
|
||
//变量定义
|
||
BYTE cbCardIndex=0;
|
||
|
||
//分析扑克
|
||
tagAnalyseResult 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::RandCard16List(BYTE cbCardBuffer[], BYTE cbBufferCount)
|
||
{
|
||
//混乱准备
|
||
BYTE cbCardData[CountArray(m_cbCardData16)];
|
||
CopyMemory(cbCardData, m_cbCardData16, sizeof(m_cbCardData16));
|
||
|
||
//混乱扑克
|
||
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::RandCard15List(BYTE cbCardBuffer[], BYTE cbBufferCount)
|
||
{
|
||
//混乱准备
|
||
BYTE cbCardData[CountArray(m_cbCardData15)];
|
||
CopyMemory(cbCardData, m_cbCardData15, sizeof(m_cbCardData15));
|
||
|
||
//混乱扑克
|
||
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::RemoveCardList(const BYTE cbRemoveCard[], BYTE cbRemoveCount, BYTE cbCardData[], BYTE cbCardCount)
|
||
{
|
||
//检验数据
|
||
ASSERT(cbRemoveCount<=cbCardCount);
|
||
|
||
//定义变量
|
||
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;
|
||
|
||
ZeroMemory(cbCardData,cbCardCount*sizeof(cbCardData[0]));
|
||
//清理扑克
|
||
BYTE cbCardPos=0;
|
||
for (BYTE i=0;i<cbCardCount;i++)
|
||
{
|
||
if (cbTempCardData[i]!=0) cbCardData[cbCardPos++]=cbTempCardData[i];
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
//删除扑克
|
||
bool CGameLogic::RemoveCard(const BYTE cbRemoveCard[], BYTE cbRemoveCount, BYTE cbCardData[], BYTE cbCardCount)
|
||
{
|
||
//检验数据
|
||
ASSERT(cbRemoveCount<=cbCardCount);
|
||
|
||
//定义变量
|
||
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::RemoveCardEx(const BYTE cbRemoveCard[], BYTE cbRemoveCount, BYTE cbCardData[], BYTE cbCardCount)
|
||
{
|
||
//检验数据
|
||
ASSERT(cbRemoveCount <= cbCardCount);
|
||
|
||
//定义变量
|
||
BYTE cbDeleteCount = 0;
|
||
BYTE cbTempCardData[FULL_COUNT] = {0};
|
||
|
||
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;
|
||
}
|
||
|
||
//排列扑克
|
||
VOID CGameLogic::SortOutCardList(BYTE cbCardData[], BYTE cbCardCount, bool isLastCard)
|
||
{
|
||
//获取牌型
|
||
BYTE cbCardType = GetCardType(cbCardData, cbCardCount, isLastCard);
|
||
|
||
// AAA+BB 结构;
|
||
if (cbCardType == CT_THREE_TAKE_TWO)
|
||
{
|
||
//分析牌
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
// 三张数量;
|
||
BYTE cbTmpCardCount = 3;
|
||
//CopyMemory(cbCardData, AnalyseResult.cbCardData[2], sizeof(BYTE)*cbTmpCardCount);
|
||
|
||
if (AnalyseResult.cbBlockCount[2] == 1)
|
||
{
|
||
for (BYTE i = 0; i < cbTmpCardCount; i++)
|
||
{
|
||
cbCardData[i] = AnalyseResult.cbCardData[2][i];
|
||
AnalyseResult.cbCardData[2][i] = 0x0;
|
||
}
|
||
}
|
||
else if (AnalyseResult.cbBlockCount[3] == 1)
|
||
{
|
||
BYTE 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(BYTE)*(i + 1)*AnalyseResult.cbBlockCount[i]);
|
||
|
||
cbTmpCardCount += (i + 1)*AnalyseResult.cbBlockCount[i];
|
||
}
|
||
}
|
||
}
|
||
else if (cbCardType == CT_FOUR_TAKE_THREE)
|
||
{
|
||
//分析牌
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData( cbCardData,cbCardCount,AnalyseResult );
|
||
|
||
BYTE cbTmpCardCount = 4;
|
||
CopyMemory(cbCardData, AnalyseResult.cbCardData[3], sizeof(BYTE)*cbTmpCardCount);
|
||
|
||
for( int i = CountArray(AnalyseResult.cbBlockCount)-1; i >= 0; i-- )
|
||
{
|
||
if( i == 3 ) continue;
|
||
|
||
if( AnalyseResult.cbBlockCount[i] > 0 )
|
||
{
|
||
CopyMemory(&cbCardData[cbCardCount], AnalyseResult.cbCardData[i], sizeof(BYTE)*(i + 1)*AnalyseResult.cbBlockCount[i]);
|
||
|
||
cbTmpCardCount += (i + 1)*AnalyseResult.cbBlockCount[i];
|
||
}
|
||
}
|
||
}
|
||
else if (cbCardType == CT_THREE_LINE)
|
||
{
|
||
//分析牌
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
//三连判断;
|
||
if (AnalyseResult.cbBlockCount[2] + AnalyseResult.cbBlockCount[3] > 1)
|
||
{
|
||
BYTE cbLineCardData[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, ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagDistributing 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];
|
||
}
|
||
|
||
// 计算几个三带二
|
||
BYTE cbTmpBlockCount = cbCardCount / 5;
|
||
if (cbMaxThreeLength == cbTmpBlockCount)
|
||
{
|
||
//cbCardData[0] = cbMaxThreeCardData;
|
||
|
||
// 根据最大值和块长度重新分配;
|
||
BYTE cbTmpCard[MAX_COUNT] = { 0 };
|
||
BYTE cbMaxIndex = GetCardLogicValue(cbMaxThreeCardData);
|
||
|
||
BYTE cbCount = 0;
|
||
for (BYTE cbIndex = cbMaxIndex; cbIndex > (cbMaxIndex - cbTmpBlockCount); cbIndex--)
|
||
{
|
||
BYTE cbTmpCount = 0;
|
||
for (BYTE cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (BYTE 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 (BYTE i = 0; i <= GetCardLogicValue(0x02); i++)
|
||
{
|
||
for (BYTE cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (BYTE 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 CGameLogic::SortOutCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbCardType, BYTE cbBlockCount)
|
||
{
|
||
BYTE cbMaxCardData = 0x0;
|
||
|
||
// AAA+BB 结构;
|
||
if (cbCardType == CT_THREE_TAKE_TWO)
|
||
{
|
||
//分析牌
|
||
tagAnalyseResult 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 == CT_FOUR_TAKE_THREE)
|
||
{
|
||
//分析牌
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
if (AnalyseResult.cbBlockCount[3] == 1)
|
||
{
|
||
cbMaxCardData = AnalyseResult.cbCardData[3][0];
|
||
}
|
||
}
|
||
else if (cbCardType == CT_THREE_LINE)
|
||
{
|
||
//分析牌
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
|
||
//三连判断;
|
||
if (AnalyseResult.cbBlockCount[2] + AnalyseResult.cbBlockCount[3] > 1)
|
||
{
|
||
BYTE cbLineCardData[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, ST_ORDER);
|
||
|
||
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 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);
|
||
|
||
if (cbCardValue <= 0 || cbCardValue > 0x0D) return 0;
|
||
|
||
ASSERT(cbCardValue>0 && cbCardValue <= 0x0D);
|
||
|
||
//转换数值
|
||
//if (cbCardColor==0x40) return cbCardValue+2;
|
||
return (cbCardValue <= 2) ? (cbCardValue + 13) : cbCardValue;
|
||
}
|
||
|
||
//获取最大牌;
|
||
BYTE CGameLogic::GetMaxLogicValue(const BYTE cbHandCardData[], BYTE cbHandCardCount)
|
||
{
|
||
if (cbHandCardCount <= 0) return 0;
|
||
|
||
BYTE cbCardData[MAX_COUNT] = {0};
|
||
CopyMemory(cbCardData, cbHandCardData, cbHandCardCount);
|
||
|
||
// 重新排序;
|
||
SortCardList(cbCardData, cbHandCardCount, ST_ORDER);
|
||
|
||
return GetCardLogicValue(cbCardData[0]);
|
||
}
|
||
|
||
//对比扑克
|
||
bool CGameLogic::CompareCard(const BYTE cbFirstCard[], const BYTE cbNextCard[], BYTE cbFirstCount, BYTE cbNextCount, bool isLastCard)
|
||
{
|
||
//获取类型
|
||
BYTE cbNextType=GetCardType(cbNextCard,cbNextCount, isLastCard);
|
||
BYTE cbFirstType=GetCardType(cbFirstCard,cbFirstCount, false);
|
||
|
||
//类型判断
|
||
if (cbNextType==CT_ERROR) return false;
|
||
if (cbNextType==CT_3A_BOMB_CARD) return true;
|
||
|
||
//炸弹判断
|
||
if ((cbFirstType!=CT_BOMB_CARD)&&(cbNextType==CT_BOMB_CARD)) return true;
|
||
if ((cbFirstType==CT_BOMB_CARD)&&(cbNextType!=CT_BOMB_CARD)) return false;
|
||
|
||
//规则判断
|
||
if (cbFirstType!=cbNextType) return false;
|
||
|
||
//开始对比
|
||
switch (cbNextType)
|
||
{
|
||
case CT_SINGLE:
|
||
case CT_DOUBLE:
|
||
case CT_SINGLE_LINE:
|
||
case CT_DOUBLE_LINE:
|
||
case CT_BOMB_CARD:
|
||
{
|
||
// 牌数必须相同;
|
||
if (cbFirstCount != cbNextCount) return false;
|
||
|
||
//获取数值
|
||
BYTE cbNextLogicValue=GetCardLogicValue(cbNextCard[0]);
|
||
BYTE cbFirstLogicValue=GetCardLogicValue(cbFirstCard[0]);
|
||
|
||
//对比扑克
|
||
return cbNextLogicValue>cbFirstLogicValue;
|
||
}
|
||
case 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;
|
||
|
||
//分析扑克
|
||
tagAnalyseResult NextResult;
|
||
tagAnalyseResult FirstResult;
|
||
AnalysebCardData(cbNextCard,cbNextCount,NextResult);
|
||
AnalysebCardData(cbFirstCard,cbFirstCount,FirstResult);
|
||
|
||
//获取数值
|
||
BYTE cbFirstLogicValue = 0x0;
|
||
BYTE 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 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;
|
||
|
||
//分析扑克
|
||
tagAnalyseResult NextResult;
|
||
tagAnalyseResult FirstResult;
|
||
AnalysebCardData(cbNextCard,cbNextCount,NextResult);
|
||
AnalysebCardData(cbFirstCard,cbFirstCount,FirstResult);
|
||
|
||
//获取数值
|
||
BYTE cbNextLogicValue=GetCardLogicValue(NextResult.cbCardData[3][0]);
|
||
BYTE cbFirstLogicValue=GetCardLogicValue(FirstResult.cbCardData[3][0]);
|
||
|
||
//对比扑克
|
||
return cbNextLogicValue>cbFirstLogicValue;
|
||
}
|
||
case 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 cbFirstTurnCard[MAX_COUNT] = {0};
|
||
BYTE cbNextTurnCard[MAX_COUNT] = {0};
|
||
CopyMemory(cbFirstTurnCard, cbFirstCard, sizeof(BYTE)*cbFirstCount);
|
||
CopyMemory(cbNextTurnCard, cbNextCard, sizeof(BYTE)*cbNextCount);
|
||
|
||
BYTE cbFirstCardData = SortOutCardList(cbFirstTurnCard, cbFirstCount, CT_THREE_LINE, cbFirstBlockCount);
|
||
BYTE cbNextCardData = SortOutCardList(cbNextTurnCard, cbNextCount, CT_THREE_LINE, cbFirstBlockCount);
|
||
|
||
//获取数值
|
||
BYTE cbNextLogicValue = GetCardLogicValue(cbNextCardData);
|
||
BYTE cbFirstLogicValue = GetCardLogicValue(cbFirstCardData);
|
||
|
||
//对比扑克
|
||
return cbNextLogicValue > cbFirstLogicValue;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
//构造扑克
|
||
BYTE CGameLogic::MakeCardData(BYTE cbLogicValue, BYTE cbColorIndex)
|
||
{
|
||
//return (cbColorIndex<<4)|(cbValueIndex+1);
|
||
|
||
BYTE cbCardColor = (cbColorIndex << 4);
|
||
|
||
//转换数值
|
||
if (cbLogicValue > 0x0D)
|
||
{
|
||
cbLogicValue -= 0x0D;
|
||
}
|
||
|
||
return (cbCardColor | cbLogicValue);
|
||
}
|
||
|
||
//分析扑克
|
||
VOID CGameLogic::AnalysebCardData(const BYTE cbCardData[], BYTE cbCardCount, tagAnalyseResult & AnalyseResult)
|
||
{
|
||
//设置结果
|
||
ZeroMemory(&AnalyseResult,sizeof(AnalyseResult));
|
||
|
||
//扑克分析
|
||
for (BYTE i=0;i<cbCardCount;i++)
|
||
{
|
||
//变量定义
|
||
BYTE cbSameCount=1,cbCardValueTemp=0;
|
||
BYTE cbLogicValue=GetCardLogicValue(cbCardData[i]);
|
||
|
||
//搜索同牌
|
||
for (BYTE j=i+1;j<cbCardCount;j++)
|
||
{
|
||
//获取扑克
|
||
if (GetCardLogicValue(cbCardData[j])!=cbLogicValue) break;
|
||
|
||
//设置变量
|
||
cbSameCount++;
|
||
}
|
||
|
||
if(cbSameCount > 4)
|
||
{
|
||
ASSERT(FALSE);
|
||
//设置结果
|
||
ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
|
||
return;
|
||
}
|
||
|
||
//设置结果
|
||
BYTE cbIndex=AnalyseResult.cbBlockCount[cbSameCount-1]++;
|
||
for (BYTE j=0;j<cbSameCount;j++) AnalyseResult.cbCardData[cbSameCount-1][cbIndex*cbSameCount+j]=cbCardData[i+j];
|
||
|
||
//设置索引
|
||
i+=cbSameCount-1;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//分析分布
|
||
VOID CGameLogic::AnalysebDistributing(const BYTE cbCardData[], BYTE cbCardCount, tagDistributing & Distributing)
|
||
{
|
||
//设置变量
|
||
ZeroMemory(&Distributing,sizeof(Distributing));
|
||
|
||
//设置变量
|
||
for (BYTE i=0;i<cbCardCount;i++)
|
||
{
|
||
//if (cbCardData[i]==0) continue;
|
||
|
||
////获取属性
|
||
//BYTE cbCardColor=GetCardColor(cbCardData[i]);
|
||
//BYTE cbCardValue=GetCardValue(cbCardData[i]);
|
||
|
||
////分布信息
|
||
//Distributing.cbCardCount++;
|
||
//Distributing.cbDistributing[cbCardValue-1][cbIndexCount]++;
|
||
//Distributing.cbDistributing[cbCardValue-1][cbCardColor>>4]++;
|
||
|
||
if (cbCardData[i] == 0) continue;
|
||
|
||
//获取属性
|
||
BYTE cbCardColor = GetCardColor(cbCardData[i]);
|
||
BYTE cbCardValue = GetCardLogicValue(cbCardData[i]);
|
||
|
||
//分布信息
|
||
Distributing.cbCardCount++;
|
||
Distributing.cbDistributing[cbCardValue][cbIndexCount]++;
|
||
Distributing.cbDistributing[cbCardValue][cbCardColor >> 4]++;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//出牌搜索
|
||
BYTE CGameLogic::SearchOutCard( const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount,
|
||
tagSearchCardResult *pSearchCardResult )
|
||
{
|
||
//设置结果
|
||
ASSERT( pSearchCardResult != NULL );
|
||
if( pSearchCardResult == NULL ) return 0;
|
||
ZeroMemory(pSearchCardResult,sizeof(tagSearchCardResult));
|
||
|
||
//变量定义
|
||
BYTE cbResultCount = 0;
|
||
tagSearchCardResult tmpSearchCardResult = {};
|
||
|
||
//构造扑克
|
||
BYTE cbCardData[MAX_COUNT];
|
||
BYTE cbCardCount=cbHandCardCount;
|
||
CopyMemory(cbCardData,cbHandCardData,sizeof(BYTE)*cbHandCardCount);
|
||
|
||
//排列扑克
|
||
SortCardList(cbCardData,cbCardCount,ST_ORDER);
|
||
|
||
//获取类型(必然不是最后一手牌);
|
||
BYTE cbTurnOutType = GetCardType(cbTurnCardData, cbTurnCardCount, false);
|
||
|
||
if (CT_ERROR == cbTurnOutType) return 0;
|
||
|
||
// 先当做最后一首牌处理;
|
||
if (CompareCard(cbTurnCardData, cbCardData, cbTurnCardCount, cbCardCount, true) == true)
|
||
{
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbCardCount;
|
||
memcpy(pSearchCardResult->cbResultCard[cbResultCount], cbCardData, sizeof(BYTE)*cbCardCount);
|
||
cbResultCount++;
|
||
}
|
||
else
|
||
{
|
||
//出牌分析
|
||
switch (cbTurnOutType)
|
||
{
|
||
case CT_SINGLE: //单牌类型
|
||
case CT_DOUBLE: //对牌类型
|
||
{
|
||
//变量定义
|
||
BYTE cbReferCard = cbTurnCardData[0];
|
||
BYTE cbSameCount = 1;
|
||
if (cbTurnOutType == CT_DOUBLE) cbSameCount = 2;
|
||
|
||
//搜索相同牌
|
||
cbResultCount = SearchSameCard(cbCardData, cbCardCount, cbReferCard, cbSameCount, pSearchCardResult);
|
||
|
||
break;
|
||
}
|
||
case CT_SINGLE_LINE: //单连类型
|
||
{
|
||
//变量定义
|
||
BYTE cbReferCard = cbTurnCardData[cbTurnCardCount - 1];
|
||
cbResultCount = SearchSingleLine(cbCardData, cbCardCount, cbReferCard, cbTurnCardCount, pSearchCardResult);
|
||
break;
|
||
}
|
||
case CT_DOUBLE_LINE: //对连类型
|
||
{
|
||
//变量定义
|
||
BYTE cbReferCard = cbTurnCardData[cbTurnCardCount - 1];
|
||
BYTE cbLineCount = cbTurnCardCount / 2;
|
||
cbResultCount = SearchDoubleLine(cbCardData, cbCardCount, cbReferCard, cbLineCount, pSearchCardResult);
|
||
break;
|
||
}
|
||
case CT_THREE_LINE: //三连类型
|
||
{
|
||
//效验牌数
|
||
if (cbCardCount < cbTurnCardCount) break;
|
||
|
||
// 搜索出牌的情况,上家必然不是最后一手牌;
|
||
BYTE cbBlockCount = cbTurnCardCount / 5;
|
||
|
||
//BYTE cbTmpTurnCard[MAX_COUNT] = {};
|
||
//CopyMemory(cbTmpTurnCard, cbTurnCardData, sizeof(BYTE)*cbTurnCardCount);
|
||
//SortOutCardList(cbTmpTurnCard, cbTurnCardCount, false);
|
||
BYTE cbTmpTurnCard = SortOutCardList((BYTE*)cbTurnCardData, cbTurnCardCount, CT_THREE_LINE, cbBlockCount);
|
||
|
||
//搜索(要算出最小牌);
|
||
//BYTE cbMinLogicValue = (GetCardLogicValue(cbTmpTurnCard[0]) - cbBlockCount + 1);
|
||
BYTE cbMinLogicValue = (GetCardLogicValue(cbTmpTurnCard) - cbBlockCount + 1);
|
||
cbResultCount = SearchThreeLineTakeTwo(cbCardData, cbCardCount, cbMinLogicValue, cbBlockCount, pSearchCardResult);
|
||
|
||
break;
|
||
}
|
||
case CT_THREE_TAKE_TWO: //三带一对
|
||
{
|
||
//效验牌数
|
||
if (cbCardCount < cbTurnCardCount) break;
|
||
|
||
//BYTE cbTmpTurnCard[MAX_COUNT] = {};
|
||
//CopyMemory(cbTmpTurnCard, cbTurnCardData, sizeof(BYTE)*cbTurnCardCount);
|
||
//SortOutCardList(cbTmpTurnCard, cbTurnCardCount, false);
|
||
|
||
BYTE cbTmpTurnCard = SortOutCardList((BYTE*)cbTurnCardData, cbTurnCardCount, CT_THREE_TAKE_TWO, 1);
|
||
|
||
//搜索三带牌型
|
||
cbResultCount = SearchThreeTakeTwo(cbCardData, cbCardCount, cbTmpTurnCard, pSearchCardResult);
|
||
|
||
break;
|
||
}
|
||
case CT_FOUR_TAKE_THREE: //四带三
|
||
{
|
||
//效验牌数
|
||
if (!IsHasGameRule(ePDKRuleEnum_FOUR_TAKE_THREE)) break;
|
||
if (cbCardCount < cbTurnCardCount) break;
|
||
|
||
//BYTE cbTmpTurnCard[MAX_COUNT] = {};
|
||
//CopyMemory(cbTmpTurnCard, cbTurnCardData, sizeof(BYTE)*cbTurnCardCount);
|
||
//SortOutCardList(cbTmpTurnCard, cbTurnCardCount, false);
|
||
BYTE cbTmpTurnCard = SortOutCardList((BYTE*)cbTurnCardData, cbTurnCardCount, CT_FOUR_TAKE_THREE, 1);
|
||
|
||
//搜索带牌
|
||
cbResultCount = SearchFourTakeThree(cbCardData, cbCardCount, cbTmpTurnCard, pSearchCardResult);
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
//搜索炸弹
|
||
if ((cbCardCount >= 4) && (cbTurnOutType != CT_3A_BOMB_CARD))
|
||
{
|
||
//变量定义
|
||
BYTE cbReferCard = 0;
|
||
if (cbTurnOutType == CT_BOMB_CARD) cbReferCard = cbTurnCardData[0];
|
||
|
||
//搜索炸弹
|
||
BYTE cbTmpResultCount = SearchSameCard(cbCardData, cbCardCount, cbReferCard, 4, &tmpSearchCardResult);
|
||
for (BYTE i = 0; i < cbTmpResultCount; i++)
|
||
{
|
||
pSearchCardResult->cbCardCount[cbResultCount] = tmpSearchCardResult.cbCardCount[i];
|
||
CopyMemory(pSearchCardResult->cbResultCard[cbResultCount], tmpSearchCardResult.cbResultCard[i],
|
||
sizeof(BYTE)*tmpSearchCardResult.cbCardCount[i]);
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
|
||
//搜索火箭(0x01,0x11,0x21)
|
||
if (cbTurnOutType != CT_3A_BOMB_CARD && (cbCardCount >= 3) && (IsHasGameRule(ePDKRuleEnum_3ABomb)))
|
||
{
|
||
BYTE cbACard[3] = { 0 };
|
||
BYTE cbACardCount = 0;
|
||
|
||
//有三张A;
|
||
for (BYTE 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;
|
||
}
|
||
|
||
//同牌搜索
|
||
BYTE CGameLogic::SearchSameCard( const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbReferCard, BYTE cbSameCardCount,
|
||
tagSearchCardResult *pSearchCardResult )
|
||
{
|
||
//设置结果
|
||
if( pSearchCardResult )
|
||
ZeroMemory(pSearchCardResult,sizeof(tagSearchCardResult));
|
||
BYTE cbResultCount = 0;
|
||
|
||
//构造扑克
|
||
BYTE cbCardData[MAX_COUNT];
|
||
BYTE cbCardCount=cbHandCardCount;
|
||
CopyMemory(cbCardData,cbHandCardData,sizeof(BYTE)*cbHandCardCount);
|
||
|
||
//排列扑克
|
||
SortCardList(cbCardData,cbCardCount,ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData( cbCardData,cbCardCount,AnalyseResult );
|
||
|
||
BYTE cbReferLogicValue = cbReferCard==0?0:GetCardLogicValue(cbReferCard);
|
||
BYTE cbBlockIndex = cbSameCardCount-1;
|
||
do
|
||
{
|
||
for( BYTE i = 0; i < AnalyseResult.cbBlockCount[cbBlockIndex]; i++ )
|
||
{
|
||
BYTE 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) );
|
||
|
||
//复制扑克
|
||
CopyMemory( pSearchCardResult->cbResultCard[cbResultCount],&AnalyseResult.cbCardData[cbBlockIndex][cbIndex],
|
||
cbSameCardCount*sizeof(BYTE) );
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbSameCardCount;
|
||
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
|
||
cbBlockIndex++;
|
||
}while( cbBlockIndex < CountArray(AnalyseResult.cbBlockCount) );
|
||
|
||
if( pSearchCardResult )
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
return cbResultCount;
|
||
}
|
||
|
||
//搜索比出牌;
|
||
bool CGameLogic::SearchMustOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbMustOutCard)
|
||
{
|
||
if (!IsValidCard(cbMustOutCard)) return false;
|
||
|
||
for (BYTE i = 0; i < cbHandCardCount; i++)
|
||
{
|
||
if (cbHandCardData[i] == cbMustOutCard)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
//搜索单顺;
|
||
BYTE CGameLogic::SearchSingleLine(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbReferCard, BYTE cbLineCount, tagSearchCardResult *pSearchCardResult)
|
||
{
|
||
//设置结果
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
if (cbLineCount < 5) return 0;
|
||
|
||
//定义变量
|
||
BYTE cbResultCount = 0;
|
||
BYTE cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
ZeroMemory(pSearchCardResult, sizeof(tagSearchCardResult));
|
||
|
||
//超过A
|
||
if (cbReferIndex + cbLineCount > GetCardLogicValue(0x01)+1)
|
||
{
|
||
return cbResultCount;
|
||
}
|
||
|
||
//长度判断
|
||
if (cbHandCardCount < cbLineCount)
|
||
{
|
||
return cbResultCount;
|
||
}
|
||
|
||
// 癞子分析;
|
||
BYTE cbNormalCard[MAX_COUNT] = { 0 };
|
||
BYTE cbNormalCardCount = 0; // 正常牌数量;
|
||
|
||
//变幻准备
|
||
for (BYTE i = 0; i < cbHandCardCount; i++)
|
||
{
|
||
cbNormalCard[cbNormalCardCount++] = cbHandCardData[i];
|
||
}
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//搜索顺子
|
||
BYTE cbMaxIndex = GetCardLogicValue(0x01) - cbLineCount + 1;
|
||
|
||
// 不带癞子;
|
||
for (BYTE i = cbReferIndex; i <= cbMaxIndex; i++)
|
||
{
|
||
if ((Distributing.cbDistributing[i][cbIndexCount] < 1) && (i != cbMaxIndex)) continue;
|
||
|
||
BYTE cbTmpLinkCount = 0; // 当前最大连牌数;
|
||
|
||
for (BYTE j = i; j <= GetCardLogicValue(0x01); j++)
|
||
{
|
||
//继续判断
|
||
if (Distributing.cbDistributing[j][cbIndexCount] < 1)
|
||
{
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
cbTmpLinkCount++;
|
||
}
|
||
|
||
// 找到足够大的连牌;
|
||
if (cbTmpLinkCount >= cbLineCount)
|
||
{
|
||
//复制扑克
|
||
BYTE cbCount = 0;
|
||
for (BYTE cbIndex = i; cbIndex <= j; cbIndex++)
|
||
{
|
||
BYTE cbTmpCount = 0;
|
||
for (BYTE cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (BYTE 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;
|
||
}
|
||
|
||
//搜索双顺;
|
||
BYTE CGameLogic::SearchDoubleLine(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbReferCard, BYTE cbLineCount, tagSearchCardResult *pSearchCardResult)
|
||
{
|
||
//设置结果
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
if (cbLineCount < 2) return 0;
|
||
|
||
//定义变量
|
||
BYTE cbResultCount = 0;
|
||
BYTE cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
ZeroMemory(pSearchCardResult, sizeof(tagSearchCardResult));
|
||
|
||
//超过A
|
||
if (cbReferIndex + cbLineCount > GetCardLogicValue(0x01) + 1)
|
||
{
|
||
return cbResultCount;
|
||
}
|
||
|
||
//长度判断
|
||
if (cbHandCardCount < cbLineCount * 2)
|
||
{
|
||
return cbResultCount;
|
||
}
|
||
|
||
// 癞子分析;
|
||
BYTE cbNormalCard[MAX_COUNT] = { 0 };
|
||
BYTE cbNormalCardCount = 0; // 正常牌数量;
|
||
|
||
//变幻准备
|
||
for (BYTE i = 0; i < cbHandCardCount; i++)
|
||
{
|
||
cbNormalCard[cbNormalCardCount++] = cbHandCardData[i];
|
||
}
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//搜索顺子
|
||
BYTE cbMaxIndex = GetCardLogicValue(0x01) - cbLineCount + 1;
|
||
|
||
// 不带癞子;
|
||
for (BYTE i = cbReferIndex; i <= cbMaxIndex; i++)
|
||
{
|
||
if ((Distributing.cbDistributing[i][cbIndexCount] < 1) && (i != cbMaxIndex)) continue;
|
||
|
||
BYTE cbTmpLinkCount = 0; // 当前最大连牌数;
|
||
BYTE cbUseMagicCount = 0; // 已经使用癞子数量;
|
||
|
||
for (BYTE j = i; j <= GetCardLogicValue(0x01); j++)
|
||
{
|
||
// 有2张牌;
|
||
if (Distributing.cbDistributing[j][cbIndexCount] >= 2)
|
||
{
|
||
cbTmpLinkCount++;
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
|
||
// 找到足够大的连牌;
|
||
if (cbTmpLinkCount >= cbLineCount)
|
||
{
|
||
//复制扑克
|
||
BYTE cbCount = 0;
|
||
for (BYTE cbIndex = i; cbIndex <= j; cbIndex++)
|
||
{
|
||
BYTE cbTmpCount = 0;
|
||
for (BYTE cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (BYTE 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;
|
||
}
|
||
|
||
//搜索三带二;
|
||
BYTE CGameLogic::SearchThreeTakeTwo(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbReferCard, tagSearchCardResult *pSearchCardResult)
|
||
{
|
||
if (cbHandCardCount < 5) return 0;
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
|
||
//定义变量
|
||
BYTE cbResultCount = 0;
|
||
BYTE cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
ZeroMemory(pSearchCardResult, sizeof(tagSearchCardResult));
|
||
|
||
// 只有一张2;
|
||
if (cbReferIndex > GetCardLogicValue(0x01)) return 0;
|
||
|
||
//构造扑克
|
||
BYTE cbNormalCard[MAX_COUNT] = { 0 };
|
||
BYTE cbNormalCardCount = cbHandCardCount;
|
||
memcpy(cbNormalCard, cbHandCardData, sizeof(BYTE)*cbHandCardCount);
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//分析扑克
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbNormalCard, cbNormalCardCount, AnalyseResult);
|
||
|
||
//BYTE cbMinIndex = GetCardLogicValue(0x03);
|
||
BYTE cbMaxIndex = GetCardLogicValue(0x01); // 最大牌是A;
|
||
|
||
// 不带癞子搜索;
|
||
for (BYTE i = cbReferIndex; i < cbMaxIndex; i++)
|
||
{
|
||
// 没有不做变幻;
|
||
if (Distributing.cbDistributing[i][cbIndexCount] == 0) continue;
|
||
|
||
// 三带二
|
||
if (Distributing.cbDistributing[i][cbIndexCount] == 3)
|
||
{
|
||
// 先找带牌,如果找不到带牌,则牌型不成立;
|
||
BYTE cbTmpCount = 0;
|
||
BYTE cbTakeCard[5] = { 0 };
|
||
|
||
//复制扑克
|
||
for (BYTE cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (BYTE cbColorCount = 0; cbColorCount < Distributing.cbDistributing[i][cbColorIndex]; cbColorCount++)
|
||
{
|
||
cbTakeCard[cbTmpCount++] = MakeCardData(i, cbColorIndex);
|
||
|
||
if (cbTmpCount == 3) break;
|
||
}
|
||
|
||
if (cbTmpCount == 3) break;
|
||
}
|
||
|
||
for (BYTE j = 0; j < CountArray(AnalyseResult.cbBlockCount); j++)
|
||
{
|
||
for (BYTE k = 0; k < AnalyseResult.cbBlockCount[j]; k++)
|
||
{
|
||
// 带牌的起始位置;
|
||
BYTE cbIndex = (AnalyseResult.cbBlockCount[j] - k - 1)*(j + 1);
|
||
|
||
// 过滤相同牌;
|
||
if (i == GetCardLogicValue(AnalyseResult.cbCardData[j][cbIndex]))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
// 提取带牌;
|
||
for (BYTE 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(BYTE)*cbTmpCount);
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbTmpCount;
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pSearchCardResult)
|
||
{
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
}
|
||
|
||
return cbResultCount;
|
||
}
|
||
|
||
//搜索四带三;
|
||
BYTE CGameLogic::SearchFourTakeThree(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbReferCard, tagSearchCardResult *pSearchCardResult)
|
||
{
|
||
if (cbHandCardCount < 7) return 0;
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
|
||
//定义变量
|
||
BYTE cbResultCount = 0;
|
||
BYTE cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
ZeroMemory(pSearchCardResult, sizeof(tagSearchCardResult));
|
||
|
||
// 只有一张2;
|
||
if (cbReferIndex > GetCardLogicValue(0x01)) return 0;
|
||
|
||
//构造扑克
|
||
BYTE cbNormalCard[MAX_COUNT] = { 0 };
|
||
BYTE cbNormalCardCount = cbHandCardCount;
|
||
memcpy(cbNormalCard, cbHandCardData, sizeof(BYTE)*cbHandCardCount);
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, ST_ORDER);
|
||
|
||
//分析扑克
|
||
tagDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//分析扑克
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbNormalCard, cbNormalCardCount, AnalyseResult);
|
||
|
||
BYTE cbMaxIndex = GetCardLogicValue(0x01); // 最大牌是A;
|
||
|
||
// 不带癞子搜索;
|
||
for (BYTE i = cbReferIndex; i < cbMaxIndex; i++)
|
||
{
|
||
// 没有不做变幻;
|
||
if (Distributing.cbDistributing[i][cbIndexCount] == 0) continue;
|
||
|
||
// 三带二
|
||
if (Distributing.cbDistributing[i][cbIndexCount] == 4)
|
||
{
|
||
// 先找带牌,如果找不到带牌,则牌型不成立;
|
||
BYTE cbTmpCount = 0;
|
||
BYTE cbTakeCard[7] = { 0 };
|
||
|
||
//复制扑克
|
||
for (BYTE cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (BYTE cbColorCount = 0; cbColorCount < Distributing.cbDistributing[i][cbColorIndex]; cbColorCount++)
|
||
{
|
||
cbTakeCard[cbTmpCount++] = MakeCardData(i, cbColorIndex);
|
||
|
||
if (cbTmpCount == 4) break;
|
||
}
|
||
|
||
if (cbTmpCount == 4) break;
|
||
}
|
||
|
||
for (BYTE j = 0; j < CountArray(AnalyseResult.cbBlockCount); j++)
|
||
{
|
||
for (BYTE k = 0; k < AnalyseResult.cbBlockCount[j]; k++)
|
||
{
|
||
// 带牌的起始位置;
|
||
BYTE cbIndex = (AnalyseResult.cbBlockCount[j] - k - 1)*(j + 1);
|
||
|
||
// 过滤相同牌;
|
||
if (i == GetCardLogicValue(AnalyseResult.cbCardData[j][cbIndex]))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
// 提取带牌;
|
||
for (BYTE 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(BYTE)*cbTmpCount);
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbTmpCount;
|
||
cbResultCount++;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pSearchCardResult)
|
||
{
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
}
|
||
|
||
return cbResultCount;
|
||
}
|
||
|
||
//搜索飞机;
|
||
BYTE CGameLogic::SearchThreeLineTakeTwo(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbReferCard, BYTE cbBlockCount, tagSearchCardResult *pSearchCardResult)
|
||
{
|
||
//设置结果
|
||
if (pSearchCardResult == nullptr) return 0;
|
||
if (!IsValidCard(cbReferCard)) return 0;
|
||
if (cbHandCardCount < cbBlockCount * 5) return 0;
|
||
|
||
BYTE cbReferIndex = GetCardLogicValue(cbReferCard) + 1; // 最后一张牌;
|
||
|
||
//超过A
|
||
if ((cbReferIndex + cbBlockCount) > GetCardLogicValue(0x01)) return 0;
|
||
|
||
ZeroMemory(pSearchCardResult, sizeof(tagSearchCardResult));
|
||
|
||
// 癞子分析;
|
||
BYTE cbNormalCard[MAX_COUNT] = { 0 };
|
||
BYTE cbNormalCardCount = 0; // 正常牌数量;
|
||
|
||
//变幻准备
|
||
for (BYTE i = 0; i < cbHandCardCount; i++)
|
||
{
|
||
cbNormalCard[cbNormalCardCount++] = cbHandCardData[i];
|
||
}
|
||
|
||
//排列扑克
|
||
SortCardList(cbNormalCard, cbNormalCardCount, ST_ORDER);
|
||
|
||
//定义变量
|
||
BYTE cbResultCount = 0;
|
||
|
||
//分析扑克(分布规则:逻辑值);
|
||
tagDistributing Distributing = {};
|
||
AnalysebDistributing(cbNormalCard, cbNormalCardCount, Distributing);
|
||
|
||
//搜索顺子
|
||
BYTE cbMaxIndex = GetCardLogicValue(0x01) - cbBlockCount + 1;
|
||
|
||
// 不考虑癞子;
|
||
for (BYTE i = cbReferIndex; i <= cbMaxIndex; i++)
|
||
{
|
||
if ((Distributing.cbDistributing[i][cbIndexCount] < 1) && (i != cbMaxIndex)) continue;
|
||
|
||
BYTE cbTmpLinkCount = 0; // 当前最大连牌数;
|
||
BYTE cbUseMagicCount = 0; // 已经使用癞子数量;
|
||
BYTE cbTmpCard[MAX_COUNT] = { 0 };
|
||
|
||
for (BYTE j = i; j <= GetCardLogicValue(0x01); j++)
|
||
{
|
||
// 有2张牌;
|
||
if (Distributing.cbDistributing[j][cbIndexCount] >= 3)
|
||
{
|
||
cbTmpLinkCount++;
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
|
||
// 找到足够大的连牌;
|
||
if (cbTmpLinkCount >= cbBlockCount)
|
||
{
|
||
//复制扑克
|
||
BYTE cbCount = 0;
|
||
for (BYTE cbIndex = i; cbIndex <= j; cbIndex++)
|
||
{
|
||
BYTE cbTmpCount = 0;
|
||
for (BYTE cbColorIndex = 0; cbColorIndex < 4; cbColorIndex++)
|
||
{
|
||
for (BYTE cbColorCount = 0; cbColorCount < Distributing.cbDistributing[cbIndex][3 - cbColorIndex]; cbColorCount++)
|
||
{
|
||
cbTmpCard[cbCount++] = MakeCardData(cbIndex, 3 - cbColorIndex);
|
||
|
||
if (++cbTmpCount == 3) break;
|
||
}
|
||
|
||
if (cbTmpCount == 3) break;
|
||
}
|
||
}
|
||
|
||
// 加入尾巴;
|
||
BYTE cbTakeCard[MAX_COUNT] = { 0 };
|
||
BYTE cbTakeCardCount = cbNormalCardCount;
|
||
CopyMemory(cbTakeCard, cbNormalCard, sizeof(BYTE)*cbNormalCardCount);
|
||
|
||
// 将已经取出的牌删除;
|
||
if (RemoveCard(cbTmpCard, cbCount, cbTakeCard, cbNormalCardCount))
|
||
{
|
||
cbTakeCardCount -= cbCount;
|
||
}
|
||
|
||
// 分析剩余牌;
|
||
tagAnalyseResult AnalyseResult = {};
|
||
AnalysebCardData(cbTakeCard, cbTakeCardCount, AnalyseResult);
|
||
|
||
for (BYTE j = 0; j < CountArray(AnalyseResult.cbBlockCount); j++)
|
||
{
|
||
for (BYTE k = 0; k < AnalyseResult.cbBlockCount[j]; k++)
|
||
{
|
||
// 带牌的起始位置;
|
||
BYTE cbIndex = (AnalyseResult.cbBlockCount[j] - k - 1)*(j + 1);
|
||
|
||
// 提取带牌;
|
||
for (BYTE 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 != CT_THREE_LINE) break;
|
||
|
||
// 找到牌型;
|
||
if (cbCount == cbBlockCount * 5)
|
||
{
|
||
//设置变量
|
||
CopyMemory(pSearchCardResult->cbResultCard[cbResultCount], cbTmpCard, sizeof(BYTE)*cbCount);
|
||
pSearchCardResult->cbCardCount[cbResultCount] = cbCount;
|
||
cbResultCount++;
|
||
}
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pSearchCardResult)
|
||
{
|
||
pSearchCardResult->cbSearchCount = cbResultCount;
|
||
}
|
||
|
||
return cbResultCount;
|
||
}
|
||
|
||
////得到飞机的块大小;
|
||
//BYTE CGameLogic::GetThreeLineBlockCount(const BYTE cbCardData[], BYTE cbCardCount, bool isLastCard)
|
||
//{
|
||
// // 非最后一手牌,必须是5的倍数;
|
||
// if (!isLastCard) return cbCardCount / 5;
|
||
//
|
||
// // 5的倍数;
|
||
// if ((cbCardCount % 5) == 0) return cbCardCount / 5;
|
||
//
|
||
// //分析牌
|
||
// tagAnalyseResult AnalyseResult = {};
|
||
// AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);
|
||
//
|
||
// //三连判断;
|
||
// if (AnalyseResult.cbBlockCount[2] + AnalyseResult.cbBlockCount[3] > 1)
|
||
// {
|
||
// BYTE cbLineCardData[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, ST_ORDER);
|
||
//
|
||
// //分析扑克
|
||
// tagDistributing 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];
|
||
// }
|
||
//
|
||
// return cbMaxThreeLength;
|
||
// }
|
||
//
|
||
// return 0;
|
||
//}
|