#include"CardRule_Busness.h"
void CCardRules::QuickSort( vector<PocketData> vecPocket, int iArrBegin , int iArrEnd )
{
if ( iArrBegin < iArrEnd)
{
int iCutLine = Partition( vecPocket , iArrBegin , iArrEnd );
if (iCutLine == 0)
return;
QuickSort( vecPocket , iArrBegin , iCutLine-1 );
QuickSort( vecPocket , iCutLine+1 , iArrEnd );
}
}
int CCardRules::Partition( vector<PocketData> vecPocket , int iArrBegin , int iArrEnd )
{
int iBegin = iArrBegin;
int iEnd = iArrEnd;
int iCompare = (vecPocket[iBegin].m_iID & 0xFFF00000);
PocketData stBase = vecPocket[iBegin];
while( iBegin < iEnd )
{
while( iCompare <= ( vecPocket[iEnd].m_iID & 0xFFF000000 ) && iBegin < iEnd )
{
#ifdef _DEBUDE_TEST_
printf("Partition : iCompare = %x\n" , ( vecPocket[iEnd].m_iID & 0xFFF000000 ));
#endif
//高位找小,找到了,就把它弄到前面去
iEnd--;
}
vecPocket[iBegin] = vecPocket[iEnd];
while( ( vecPocket[iBegin].m_iID & 0xFFF000000 ) <= iCompare && iBegin < iEnd )
{
//低位找大,找到了,就把它弄到后面去
iBegin++;
}
vecPocket[iEnd] = vecPocket[iBegin];
}
vecPocket[iBegin] = stBase;
return iBegin;
}
int CCardRules::Partition( char szArray[] , int iArrBegin , int iArrEnd )
{
int iBegin = iArrBegin;
int iEnd = iArrEnd;
int iBase = szArray[iBegin];
int iCompare = (szArray[iBegin] & 0x0F);
while( iBegin < iEnd )
{
while( iCompare <= ( 0x0F & szArray[iEnd] ) && iBegin < iEnd )
{
//高位找小,找到了,就把它弄到前面去
iEnd--;
}
szArray[iBegin] = szArray[iEnd];
while( ( szArray[iBegin] & 0x0F ) <= iCompare && iBegin < iEnd )
{
//低位找大,找到了,就把它弄到后面去
iBegin++;
}
szArray[iEnd] = szArray[iBegin];
}
szArray[iBegin] = iBase;
return iBegin;
}
void CCardRules::QuickSort( char szArray[] , int iArrBegin , int iArrEnd )
{
if ( iArrBegin < iArrEnd)
{
int iCutLine = Partition( szArray , iArrBegin , iArrEnd );
QuickSort( szArray , iArrBegin , iCutLine-1 );
QuickSort( szArray , iCutLine+1 , iArrEnd );
}
}
/**************************************************
* 类名 : CCardRules
* 函数名 : IsStraightFlush
* 返回类型 : bool
* 函数功能 : 判断手中的底牌和发的5张牌是否为同花顺
* 参数描述 : pMax : 用户需要保存的最大的牌
* : pSelf : 用户手中的底牌
* : pOther : 用户获得的5张牌
**************************************************/
bool CCardRules::IsStraightFlush(char* pMax , char* pCardSave)
{
/*
* 由五张连张同花色的牌组成
*/
if (pMax == NULL && pCardSave == NULL)
{
return false;
}
/*
* 以下代码用于计算同花
*/
int iDiamondCount = 0; // 方块计数
int iPlumCount = 0; // 梅花计数
int iHeartsCount = 0; // 红桃计数
int iSplistCount = 0; // 黑桃计数
int iLoop = 0;
char szCardFlush[7 + 1] = {0}; // 用于保存同花花色的牌
char szCardSave[7 + 1] = {0}; // 用于保存最后需要的牌
strncpy(szCardFlush , pCardSave , 7);
while(szCardFlush[iLoop] != 0)
{
// 方块 A - K
if ( (szCardFlush[iLoop] & 0x30) == 0x00 )
{
iDiamondCount++;
iLoop++;
continue;
}
// 梅花 A - K
else if ( (szCardFlush[iLoop] & 0x30) == 0x10 )
{
iPlumCount++;
iLoop++;
continue;
}
// 红桃 A - K
else if ( (szCardFlush[iLoop] & 0x30) == 0x20 )
{
iHeartsCount++;
iLoop++;
continue;
}
// 黑桃 A - K
else
{
iSplistCount++;
iLoop++;
continue;
}
}
iLoop = 0;
char cSingleChar = 0; // 用于过滤恶意数据
bool bSingleFirst = true;
if ( iDiamondCount >= 5 )
{
int iIndex = 0;
while(szCardFlush[iLoop] != 0)
{
// 方块 A - K
if ( (szCardFlush[iLoop] & 0x30) == 0x00 )
{
if (bSingleFirst == false && cSingleChar == szCardFlush[iLoop])
{
return false;
}
bSingleFirst = false;
szCardSave[iIndex] = szCardFlush[iLoop];
cSingleChar = szCardFlush[iIndex];
iIndex++;
}
iLoop++;
}
}
else if ( iPlumCount >= 5 )
{
int iIndex = 0;
while(szCardFlush[iLoop] != 0)
{
// 梅花 A - K
if ( (szCardFlush[iLoop] & 0x30) == 0x10 )
{
if (bSingleFirst == false && cSingleChar == szCardFlush[iLoop])
{
return false;
}
bSingleFirst = false;
szCardSave[iIndex] = szCardFlush[iLoop];
cSingleChar = szCardFlush[iIndex];
iIndex++;
}
iLoop++;
}
}
else if (iHeartsCount >= 5)
{
int iIndex = 0;
while(szCardFlush[iLoop] != 0)
{
// 红桃 A - K
if ( (szCardFlush[iLoop] & 0x30) == 0x20 )
{
if (bSingleFirst == false && cSingleChar == szCardFlush[iLoop])
{
return false;
}
bSingleFirst = false;
szCardSave[iIndex] = szCardFlush[iLoop];
cSingleChar = szCardFlush[iIndex];
iIndex++;
}
iLoop++;
}
}
else
{
int iIndex = 0;
while(szCardFlush[iLoop] != 0)
{
// 黑桃 A - K
if (0x31 <= szCardFlush[iLoop])
{
if (bSingleFirst == false && cSingleChar == szCardFlush[iLoop])
{
return false;
}
bSingleFirst = false;
szCardSave[iIndex] = szCardFlush[iLoop];
cSingleChar = szCardFlush[iIndex];
iIndex++;
}
iLoop++;
}
}
int iCardLen = strlen(szCardSave);
QuickSort(szCardSave , 0 , iCardLen - 1);
/*
* 以上代码用于计算同花
* 以下代码用于计算顺子
*/
char cIndexValue = 0; // 数组下标对应的值
int iElemSuccession = 0; // 元素的连续个数
int iStraightIndex = 7; // 数组索引
cIndexValue = szCardSave[strlen(szCardSave) - 1];
bool bHaveAce = false; // 是否存在A
if ( (cIndexValue & 0x0F) == 0x0D )
{
int iLoopAce = 0; // 用于循环查找A的个数
while (iLoopAce < 7)
{
if (szCardSave[iLoopAce] == 0x0D)
{
szCardSave[iLoopAce] = 0x0; // 暂时将为A的牌赋植为0;
bHaveAce = true;
}
iLoopAce++;
}
}
if (bHaveAce == true)
QuickSort(szCardSave , 0 , iCardLen - 1);
while( iLoop > 0 )
{
cIndexValue = szCardSave[iStraightIndex] - szCardSave[iStraightIndex - 1];
iStraightIndex--;
if( ( 0x01 == cIndexValue ) || ( 0x11 == cIndexValue ) )
iElemSuccession++;
else
iElemSuccession = 0;
if (iElemSuccession == 4)
{
int iLoopToA = 0;
while (iLoopToA < iCardLen)
{
if (szCardSave[iLoopToA] == 0x00)
szCardSave[iLoopToA] = 0x0D; // 如果是有A的情况则在这里进行植的反填
iLoopToA++;
}
strncpy( pMax , szCardSave + iStraightIndex , 5 );
return true;
}
iLoop--;
}
return false;
}
/**************************************************
* 类名 : CCardRules
* 函数名 : IsFourOfAKind
* 返回类型 : bool
* 函数功能 : 判断手中的底牌和发的5张牌是否为四条
* 参数描述 : pMax : 用户需要保存的最大的牌
* : pSelf : 用户手中的底牌
* : pOther : 用户获得的5张牌
**************************************************/
bool CCardRules::IsFourOfAKind(char* pMax , char* pCardSave)
{
/*
* 4张同点值的牌加上一张其他任何牌(最大的牌)
*/
if (pMax == NULL && pCardSave == NULL)
{
return false;
}
int iLoop = 0;
int iIndex = 0; // 循环的次数用数组的索引标识
int iRepeatCount = 0; // 记录手牌重复的次数等于3次则代表有4张牌重复
char szCardSave[7 + 1] = {0};
char cSingleChar = 0; // 记录单个字符.用于判断是否有恶意数据的传入
char cCharactor = 0; // 遍历中各个字符,或者是存在4张牌的那个字符
strncpy( szCardSave , pCardSave , 7);
// 此while用于遍历所有字符
while ( iIndex < 7 )
{
cCharactor = (szCardSave[iIndex] & 0x0F);
cSingleChar = szCardSave[iIndex];
// 此while用于遍历查找所有字符中此固定字符是否存在4次
while ( iLoop < 7 )
{
bool bRepeat = false;
// 用于过滤恶意数据和获得需要的数据
if (cCharactor == (szCardSave[iLoop] & 0x0F) && (iLoop != iIndex) && szCardSave[iLoop] != cSingleChar)
{
bRepeat = true;
iRepeatCount++;
}
if ( iRepeatCount == 3 )
{
int iPutIn = 0;
iLoop = 0;
char cCharMax = 0; // 除了4张相�
评论0