|
- #include "Stdafx.h"
- #include "GameLogic_poker.h"
- #include<algorithm>
- //////////////////////////////////////////////////////////////////////////
- //静态变量
-
- //索引变量
- const BYTE cbIndexCount=5;
-
- //扑克数据
- const BYTE CGameLogic_Poker::m_cbCardData[FULL_COUNT_Poker] =
- {
- 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D, //方块 A - K
- 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D, //梅花 A - K
- 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D, //红桃 A - K
- 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D, //黑桃 A - K
- 0x4E,0x4F,
- 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D, //方块 A - K
- 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D, //梅花 A - K
- 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D, //红桃 A - K
- 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D, //黑桃 A - K
- 0x4E,0x4F,
- };
-
- //////////////////////////////////////////////////////////////////////////
-
- //构造函数
- CGameLogic_Poker::CGameLogic_Poker()
- {
- m_GameMagicMode = 2;
- }
-
- //析构函数
- CGameLogic_Poker::~CGameLogic_Poker()
- {
- }
-
- //获取类型
- BYTE CGameLogic_Poker::GetCardType(const BYTE cbCardData[], BYTE cbCardCount, BYTE &cbStarLevel, BomoType&BomoInfo)
- {
- BYTE cbTmpCardData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(cbTmpCardData, cbCardData,cbCardCount);
- SortCardList(cbTmpCardData, cbCardCount, ST_ORDER, ORDERBY_DES);
- //变量初始化
- cbStarLevel=0;
-
- //简单牌型
- switch (cbCardCount)
- {
- case 0: //空牌
- {
- return CT_ERROR;
- }
- case 1: //单牌
- {
- return CT_SINGLE;
- }
- }
-
- //排炸类型
- if (cbCardCount>=12)
- {
- //变量定义
- BYTE cbCardIndex=0;
- BYTE cbBlockCount=0;//同牌个数
-
- BYTE cbBombCardData[MAX_COUNT_Poker/4];//炸弹单牌 按照顺序存储
- BYTE cbSmallCount=0;//最小的同牌个数
- BYTE cbMaxCount=0;//最大的同牌个数
- ZeroMemory(cbBombCardData,sizeof(cbBombCardData));
-
- //扑克分析
- do
- {
- //变量定义
- BYTE cbSameCount=1;
- BYTE cbCardValue = GetCardLogicValue(cbTmpCardData[cbCardIndex]);
-
- //同牌搜索
- for (BYTE i=cbCardIndex+1;i<cbCardCount;i++)
- {
- if (GetCardLogicValue(cbTmpCardData[i]) == cbCardValue)
- {
- cbSameCount++;
- }
- else break;
- }
-
- //连牌判断
- if (cbSameCount>=4)
- {
- cbBombCardData[cbBlockCount] = cbTmpCardData[cbCardIndex];
- cbBlockCount++;
- cbCardIndex+=cbSameCount;
- if(cbSmallCount==0)
- cbSmallCount=cbSameCount;
- else
- cbSmallCount=min(cbSameCount,cbSmallCount);
- if(cbMaxCount==0)
- cbMaxCount=cbSameCount;
- else
- cbMaxCount=max(cbMaxCount,cbSameCount);
-
- }
- else break;
-
- } while (cbCardIndex<cbCardCount);
-
- //结果判断
- if ((cbBlockCount >= 3) && (cbCardIndex == cbCardCount) && (cbCardCount%cbBlockCount == 0) && IsStructureLink(cbTmpCardData, cbCardCount, cbCardCount / cbBlockCount, true) && (cbSmallCount == cbMaxCount))
- {
-
- BomoInfo.tong = cbCardCount / cbBlockCount;
- BomoInfo.lian = cbBlockCount;
- BomoInfo.BomoTypes = BomoTypeLian;
- BomoInfo.CbBomoCount = BomoInfo.tong*BomoInfo.lian;
- SetBomoLevel(BomoInfo);
-
-
- cbStarLevel = BomoInfo.Level;
- return CT_BOMB_LINK;
- }
- if ((cbBlockCount >= 3) && (cbCardIndex == cbCardCount) && (IsStructureLink(cbTmpCardData, cbCardCount, cbCardCount / cbBlockCount, true) == FALSE && (cbSmallCount == cbMaxCount)))
- {
- cbStarLevel=cbBlockCount+cbSmallCount;
- BomoInfo.BomoTypes = BomoTypeXian;
- BomoInfo.fu = cbBlockCount;
- BomoInfo.xian = cbCardCount / cbBlockCount;
- SetBomoLevel(BomoInfo);
- cbStarLevel = BomoInfo.Level;
- BomoInfo.CbBomoCount = BomoInfo.fu*BomoInfo.xian;
- if (BomoInfo.fu==3||(BomoInfo.fu==4&&BomoInfo.xian==4))
- {
- ZeroMemory(&BomoInfo, sizeof(BomoInfo));
- return CT_ERROR;
- }
- return CT_BOMB_XIAN;
- }
- }
-
- //分析扑克
- tagAnalyseResult_Poker AnalyseResult;
- AnalysebCardData(cbTmpCardData, cbCardCount, AnalyseResult);
-
- if (GetMagicType() != NoHaveMagic)
- {
- //3王炸弹
-
- if ((cbCardCount == 3) )
- {
- BOOL bFindNoJoker = FALSE;
- for (int i = 0; i < 3; i++)
- {
- if (cbTmpCardData[i] != 0x4E && cbTmpCardData[i] != 0x4F)
- {
- bFindNoJoker = TRUE;
- break;
- }
- }
- if ( bFindNoJoker == FALSE)
- {
- cbStarLevel = 6;
- BomoInfo.Level = cbStarLevel;
- return CT_BOMB_3W;
- }
-
- }
- }
-
-
-
- //同牌判断
- if ((cbCardCount==3)&&(AnalyseResult.cbBlockCount[2]==1)) return CT_THREE; //3张同牌
-
-
- if ((cbCardCount==2)&&(AnalyseResult.cbBlockCount[1]==1)) return CT_DOUBLE;//对子牌型
-
- //判断是否是 大小王对子
- if (cbCardCount == 2 && GetMagicType()!= NoHaveMagic)
- {
- if (cbCardData[0]==0x4f&&cbCardData[1]==0x4e)
- {
- return CT_DOUBLE;
- }
- }
- //天王炸弹
-
- if ((cbCardCount == 4))
- {
- BYTE MagicCount = 0;
- for (int i = 0; i < 4;i++)
- {
- if (cbCardData[i]==0x4e||cbCardData[i]==0x4f)
- {
- MagicCount++;
- }
- }
- if (MagicCount==4)
- {
- if (GetMagicType() == NoHaveMagic)
- {
- cbStarLevel = 8;//4王炸弹7星级 最大
- }
- else
- {
- cbStarLevel = 7;//4王炸弹7星级 最大
- }
- BomoInfo.Level = cbStarLevel;
- return CT_BOMB_TW;
- }
-
- }
- //炸弹类型
- if ((cbCardCount>=4)&&(cbCardCount<=12)&&(AnalyseResult.cbBlockCount[cbCardCount-1]==1))
- {
- cbStarLevel= cbCardCount;
- return CT_BOMB;
- }
-
- //对连类型
- if ((cbCardCount>=6)&&((AnalyseResult.cbBlockCount[1]*2)==cbCardCount))
- {
- BYTE cbDoubleCount=AnalyseResult.cbBlockCount[1]*2;
- if (IsStructureLink(AnalyseResult.cbCardData[1],cbDoubleCount,2)==true) return CT_DOUBLE_LINK;
- }
-
- //三连类型
- if ((cbCardCount>=9)&&((AnalyseResult.cbBlockCount[2]*3)==cbCardCount))
- {
- BYTE cbThreeCount=AnalyseResult.cbBlockCount[2]*3;
- if (IsStructureLink(AnalyseResult.cbCardData[2],cbThreeCount,3)==true) return CT_THREE_LINK;
- }
-
- //顺子类型
- if ((cbCardCount>=5)&&AnalyseResult.cbBlockCount[0]==cbCardCount)
- {
- if (IsStructureLink(AnalyseResult.cbCardData[0],cbCardCount,1)==true) return CT_SHUNZI;
- }
-
- return CT_ERROR;
- }
-
-
-
- //排列扑克
- VOID CGameLogic_Poker::SortCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbSortType,BYTE OrderByType)
- {
- //数目过虑
- if (cbCardCount==0) return;
-
- //转换数值
- BYTE cbSortValue[MAX_COUNT_Poker];
- for (BYTE i=0;i<cbCardCount;i++)
- {
- if (cbSortType==ST_VALUE)
- {
- cbSortValue[i]=GetCardValue(cbCardData[i]);
- }
- else
- {
- cbSortValue[i]=GetCardLogicValue(cbCardData[i]);
- }
- }
- if (OrderByType==ORDERBY_ASE)
- {
- //排序操作 升序
- bool bSorted = true;
- BYTE cbSwitchData = 0, cbLast = cbCardCount - 1;
- do
- {
- bSorted = true;
- for (BYTE i = 0; i < cbLast; i++)
- {
- if ((cbSortValue[i] > cbSortValue[i + 1]) ||
- ((cbSortValue[i] == cbSortValue[i + 1]) && (cbCardData[i] > cbCardData[i + 1])))
- {
- //设置标志
- bSorted = false;
-
- //扑克数据
- cbSwitchData = cbCardData[i];
- cbCardData[i] = cbCardData[i + 1];
- cbCardData[i + 1] = cbSwitchData;
-
- //排序权位
- cbSwitchData = cbSortValue[i];
- cbSortValue[i] = cbSortValue[i + 1];
- cbSortValue[i + 1] = cbSwitchData;
- }
- }
- cbLast--;
- } while (bSorted == false);
-
- }
- else
- {
- //降序
- 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_Poker 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;
- }
-
-
- //混乱扑克
- //OutCardType 3中情况 1张发 3张发 6张发
-
- VOID
- CGameLogic_Poker::RandCardList(BYTE cbCardBuffer[], BYTE cbBufferCount, byte OutCardType, WORD wRoomId)
- {
-
- //混乱准备
- BYTE cbCardData[CountArray(m_cbCardData)];
- CopyMemory(cbCardData,m_cbCardData,sizeof(m_cbCardData));
- BYTE cbUserCardData[4][27] = { 0 };
- BYTE cbUserCardCount[4] = { 0 };
- BYTE cbPosition=0;
-
- //混乱扑克
-
- int nCount;
- switch (OutCardType)
- {
- case OneCardDeal:{
- nCount = 1;
- break;
- }
- case ThreeCardDeal:{
- nCount = 2;
- break;
- }
- case sixCardDeal:
- {
- nCount = 3;
- break;
- }
- default:
- nCount = 3;
- break;
- }
- if (OutCardType == sixCardDeal)
- {
- srand(time(0) * wRoomId); //随机种子由当前时间和房间ID生成
- vector<vector<BYTE>> AllCards;//保存所有扑克
- for (int i = 0; i < 15; i++)
- {
- vector<BYTE> tmp;
- AllCards.push_back(tmp);
- }
- for (int i = 0; i < 108; i++)
- {
- BYTE Value = GetCardValue(m_cbCardData[i]);
- AllCards[Value - 1].push_back(m_cbCardData[i]);
- }
- BYTE cbLeftCount = 108;
- BYTE RandValue, RandCount;
-
- //先将4个人的index随机排序
- BYTE NewUserIndexNum[4] = { 0 };
- {
-
- BYTE UserIndexNum[] = { 0, 1, 2, 3 };
-
- BYTE cbUserRandCount = 0;
- BYTE cbPosition = 0;
- BYTE cbBufferCount = 4;
- do
- {
- BYTE cbUserBufferCount = 4;
- BYTE cbTempRandCount = 0;
- cbPosition = rand() % (cbUserBufferCount - cbUserRandCount);
- NewUserIndexNum[cbUserRandCount++] = UserIndexNum[cbPosition];
- UserIndexNum[cbPosition] = UserIndexNum[cbBufferCount - cbUserRandCount];
- cbTempRandCount++;
- } while (cbUserRandCount < cbBufferCount);
- }
- //随机出每个人妹没个炸弹的个数以及牌值
- struct RandCardInfos
- {
- BYTE userID;
- BYTE BomoCount;
- BYTE BomoCardValue[4];//每幅炸的牌值
- BYTE BomoCardCount[4];//每幅炸弹的张数
-
- };
- vector<RandCardInfos> vBomoInfos;
-
-
- for (int UserIndex = 0; UserIndex < 4; UserIndex++)
- {
- RandCardInfos CardInfo;
- ZeroMemory(&CardInfo, sizeof(RandCardInfos));
- CardInfo.userID = NewUserIndexNum[UserIndex];
- BYTE cbBomoCountArr[] = {1,2,3,4 };
-
- int BomoCount = rand() % 4;
- CardInfo.BomoCount = cbBomoCountArr[BomoCount];
-
- for (int TmpBomoCount = 0; TmpBomoCount < CardInfo.BomoCount; TmpBomoCount++)
- {
- srand((unsigned)time(0)*CardInfo.userID);
- BYTE cbCardCountArr[] = { 4, 5, 6, 7, 8 };
- BYTE CardIndex = rand() % 12;
- BYTE CardCount = rand() % 5;
- CardInfo.BomoCardValue[TmpBomoCount] = CardIndex;
- CardInfo.BomoCardCount[TmpBomoCount] = cbCardCountArr[CardCount];
- }
- vBomoInfos.push_back(CardInfo);
- // CString outstr;
- // outstr.Format(_T("UserIndex=%d BomoCount=%d\r\n"),CardInfo.userID,CardInfo.BomoCount);
- // OutputDebugString(outstr);
- }
- //OutputDebugString(_T("--------------------------------------\r\n"));
- //把每个牌取出来
- vector<RandCardInfos>::iterator it = vBomoInfos.begin();
- for (; it != vBomoInfos.end();it++)
- {
- for (int BomoCount = 0; BomoCount < it->BomoCount; BomoCount++)
- {
- BYTE index = it->BomoCardValue[BomoCount];
- //牌堆里面的牌 如果允许用户全部拿走
- if (AllCards[index].size()>=it->BomoCardCount[BomoCount])
- {
- for (int CopyCard = 0; CopyCard < it->BomoCardCount[BomoCount];CopyCard++)
- {
- if (cbUserCardCount[it->userID]>=27)
- {
- break;
- }
- cbUserCardData[it->userID][cbUserCardCount[it->userID]++] = AllCards[index][0];
- AllCards[index].erase(AllCards[index].begin());
- }
- }
- }
- }
-
-
- //剩余牌随机
- BYTE cbBufferAllCards[108] = { 0 };
- BYTE cbBufferAllCardsCount = 0;
- for (int i = 0; i < AllCards.size(); i++)
- {
- for (int j = 0; j < AllCards[i].size(); j++)
- {
- cbBufferAllCards[cbBufferAllCardsCount++] = AllCards[i][j];
- }
- }
- //洗牌之后的
- BYTE cbRandedCards[108] = { 0 };
- BYTE cbRandedCardCount = cbBufferAllCardsCount;
-
-
- nCount = 4;
- while (nCount > 0)
- {
- srand(time(0) * wRoomId); //随机种子由当前时间和房间ID生成
- BYTE cbRandCount = 0, cbTempRandCount = 0;
- nCount--;
- do
- {
-
- cbTempRandCount = 0;
- cbPosition = rand() % (cbRandedCardCount - cbRandCount);
- cbRandedCards[cbRandCount++] = cbBufferAllCards[cbPosition];
- cbBufferAllCards[cbPosition] = cbBufferAllCards[cbRandedCardCount - cbRandCount];
- cbTempRandCount++;
- while ((cbPosition < cbRandedCardCount - cbRandCount) && (cbTempRandCount < 4))
- {
- cbPosition++;
- cbRandedCards[cbRandCount++] = cbBufferAllCards[cbPosition];
- cbBufferAllCards[cbPosition] = cbBufferAllCards[cbRandedCardCount - cbRandCount];
- cbTempRandCount++;
- }
-
- } while (cbRandCount < cbRandedCardCount);
- CopyMemory(cbBufferAllCards, cbRandedCards, 108);
- }
- //每人27张
- BYTE StartIndex = 0;
- BYTE *TmpPointCardBuffer = cbCardBuffer;
- for (int index = 0; index < 4;index++)
- {
- if (cbUserCardCount[index]==0)
- {
-
- CopyMemory(TmpPointCardBuffer, &cbRandedCards[StartIndex], 27);
- StartIndex += 27;
- TmpPointCardBuffer += 27;
- }
- else{
- CopyMemory(TmpPointCardBuffer, &cbUserCardData[index], cbUserCardCount[index]);
- TmpPointCardBuffer += cbUserCardCount[index];
- BYTE CopyDataCount = 27 - cbUserCardCount[index];
- CopyMemory(TmpPointCardBuffer, &cbRandedCards[StartIndex], CopyDataCount);
- StartIndex += CopyDataCount;
- TmpPointCardBuffer += CopyDataCount;
- }
- }
-
- }
- else
- {
- while (nCount > 0)
- {
-
- nCount--;
- srand(time(0) * wRoomId); //随机种子由当前时间和房间ID生成
- BYTE cbRandCount = 0, cbTempRandCount = 0;
- do
- {
-
- cbTempRandCount = 0;
- cbPosition = rand() % (cbBufferCount - cbRandCount);
- cbCardBuffer[cbRandCount++] = cbCardData[cbPosition];
- cbCardData[cbPosition] = cbCardData[cbBufferCount - cbRandCount];
- cbTempRandCount++;
- while ((cbPosition < cbBufferCount - cbRandCount) && (cbTempRandCount < 4))
- {
- cbPosition++;
- cbCardBuffer[cbRandCount++] = cbCardData[cbPosition];
- cbCardData[cbPosition] = cbCardData[cbBufferCount - cbRandCount];
- cbTempRandCount++;
- }
-
- } while (cbRandCount < cbBufferCount);
- CopyMemory(cbCardData, cbCardBuffer,108);
- }
- }
-
- return;
- }
-
- //删除扑克
- bool CGameLogic_Poker::RemoveCard(const BYTE cbRemoveCard[], BYTE cbRemoveCount, BYTE cbCardData[], BYTE cbCardCount)
- {
- //检验数据
- ASSERT(cbRemoveCount<=cbCardCount);
-
- //定义变量
- BYTE cbDeleteCount=0,cbTempCardData[MAX_COUNT_Poker];
- if (cbCardCount > CountArray(cbTempCardData))
- {
- OutputDebugString(L"RemoveCard CountArray ");
- 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;
- }
- }
- }
- ASSERT(cbDeleteCount==cbRemoveCount);
- if (cbDeleteCount != cbRemoveCount)
- {
- OutputDebugString(L"Delete Count 不相等 ");
- return false;
- }
- ZeroMemory(cbCardData, cbCardCount);
- //清理扑克
- BYTE cbCardPos=0;
- for (BYTE i=0;i<cbCardCount;i++)
- {
- if (cbTempCardData[i]!=0)
- cbCardData[cbCardPos++]=cbTempCardData[i];
- }
-
- return true;
- }
-
- //有效判断
- bool CGameLogic_Poker::IsValidCard(BYTE cbCardData)
- {
- //获取属性
- BYTE cbCardColor=GetCardColor(cbCardData);
- BYTE cbCardValue=GetCardValue(cbCardData);
-
- //有效判断
- if ((cbCardColor<=0x30)&&(cbCardValue>=0x01)&&(cbCardValue<=0x0D)) return true;
- if(cbCardData==0x4F||cbCardData==0x4E) return true;
- return false;
- }
-
- //逻辑数值
- BYTE CGameLogic_Poker::GetCardLogicValue(BYTE cbCardData)
- {
- //扑克属性
- BYTE cbCardColor=GetCardColor(cbCardData);
- BYTE cbCardValue=GetCardValue(cbCardData);
-
- //王牌扑克
- if (cbCardValue>=0x0E) return cbCardValue+2;
-
- //转换数值
- return (cbCardValue<=2)?(cbCardValue+13):cbCardValue;
- }
-
- BYTE CGameLogic_Poker::GetMaxLogicValue(const BYTE cbCarddata[], BYTE cbCardCount)
- {
- BYTE szCardData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szCardData, cbCarddata, cbCardCount);
- SortCardList(szCardData, cbCardCount, ST_ORDER, ORDERBY_DES);
- return GetCardLogicValue(szCardData[0]);
-
-
- }
-
- //只支持 2-A 的转换
- BYTE CGameLogic_Poker::TagIndexToNoColorCardValue(BYTE cbCardData){
- if (cbCardData < 14)
- {
- return cbCardData;
- }
- CString strRet;
- switch (cbCardData)
- {
- case 14:
- case 15:
- return cbCardData % 13;
- break;
- case 16:
- case 17:
- return cbCardData;
- break;
- default:
- return cbCardData;
- break;
- }
- return 0;
- }
-
- CString CGameLogic_Poker::LogicValueToString(BYTE cbCardData)
- {
- //1-15 3-KA2
- //16 17 小王 大王
- if (cbCardData<11)
- {
- CString str;
- str.Format(L"%d", cbCardData);
- return str;
- }
- CString strRet;
- switch (cbCardData)
- {
- case 11:
- strRet = L"J";
- break;
- case 12:
- strRet = L"Q";
- break;
- case 13:
- strRet = L"K";
- break;
- case 1:
- strRet = L"A";
- break;
- case 2:
- strRet = L"2";
- break;
- case 14:
- case 16:
- strRet = L"XW";
- break;
- case 15:
- case 17:
- strRet = L"DW";
- break;
- default:
- break;
- }
- return strRet;
- }
-
- //对比扑克
- //cbFirstCard 上家的牌
- //cbNextCard 本家的牌
- //比较前 应该是逆序排列 最大的牌值放在最前面
- bool CGameLogic_Poker::CompareCard( BYTE cbFirstCard[], BYTE cbNextCard[], BYTE cbFirstCount, BYTE cbNextCount)
- {
-
- SortCardList(cbFirstCard, cbFirstCount, ST_ORDER, ORDERBY_DES);
- SortCardList(cbNextCard, cbNextCount, ST_ORDER, ORDERBY_DES);
- //引用变量
- BYTE cbFirstStarLevel;
- BYTE cbNextStarLevel;
-
- //类型判断
- BomoType bomoinfo,bomoinfo2;
- BYTE cbNextType = GetCardType(cbNextCard, cbNextCount, cbNextStarLevel, bomoinfo);
- BYTE cbFirstType = GetCardType(cbFirstCard, cbFirstCount, cbFirstStarLevel, bomoinfo2);
-
- //炸弹过虑
- if ((cbFirstType>=CT_BOMB)||(cbNextType>=CT_BOMB))
- {
- //炸弹类型
- if (cbNextType<CT_BOMB) return false;
- if (cbFirstType<CT_BOMB) return true;
-
- //星级比较
- if (cbFirstStarLevel != cbNextStarLevel)
- {
- return cbNextStarLevel>cbFirstStarLevel;
- }
- else
- {
- if (cbFirstType == CT_BOMB_3W || cbNextType==CT_BOMB_3W)
- {
- if (cbFirstType==CT_BOMB_3W)
- {
- return cbNextStarLevel >= 6;
- }
- if (cbNextType==CT_BOMB_3W)
- {
- return false;
- }
- }
- if (cbFirstType == CT_BOMB_TW || cbNextType == CT_BOMB_TW)
- {
- //无论是否来自天王炸都是同线级别最大的
- if (cbFirstType == CT_BOMB_TW)
- {
- return false;
- }
- if (cbNextType == CT_BOMB_TW)
- {
- return true;
- }
- }
-
- //线级别相同,按照张数比较大小
- if (cbFirstCount!=cbNextCount)
- {
- return cbNextCount < cbFirstCount;
- }
-
- BYTE cbConsultNext = GetCardLogicValue(cbNextCard[0]);
- BYTE cbConsultFirst = GetCardLogicValue(cbFirstCard[0]);
- return cbConsultNext > cbConsultFirst;
-
- }
- }
-
- //不同类型
- if (cbFirstType!=cbNextType) return false;
-
- //相同类型
- switch (cbFirstType)
- {
- case CT_SINGLE: //单牌类型
- case CT_DOUBLE: //对子类型
- case CT_THREE: //三条类型
- case CT_SHUNZI: //顺子类型
- {
- //数目判断
- if (cbFirstCount!=cbNextCount) return false;
-
- //变量定义
- BYTE cbConsultNext=GetCardLogicValue(cbNextCard[0]);
- BYTE cbConsultFirst=GetCardLogicValue(cbFirstCard[0]);
-
- return cbConsultNext>cbConsultFirst;
- }
- case CT_DOUBLE_LINK: //对连类型
- case CT_THREE_LINK: //三连类型
- {
- //数目判断
- if (cbFirstCount!=cbNextCount) return false;
-
- //变量定义
- BYTE cbConsultNext=GetCardValue(cbNextCard[0]);
- BYTE cbConsultFirst=GetCardValue(cbFirstCard[0]);
-
- //数值转换
- if (cbConsultNext!=2)
- {
- //设置变量
- cbConsultNext=0;
-
- //扑克搜索
- for (BYTE i=0;i<cbNextCount;i++)
- {
- BYTE cbLogicValue=GetCardLogicValue(cbNextCard[i]);
- if (cbLogicValue>cbConsultNext) cbConsultNext=cbLogicValue;
- }
- }
-
- //数值转换
- if (cbConsultFirst!=2)
- {
- //设置变量
- cbConsultFirst=0;
-
- //扑克搜索
- for (BYTE i=0;i<cbFirstCount;i++)
- {
- BYTE cbLogicValue=GetCardLogicValue(cbFirstCard[i]);
- if (cbLogicValue>cbConsultFirst) cbConsultFirst=cbLogicValue;
- }
- }
-
- return cbConsultNext>cbConsultFirst;
- }
-
- }
-
- //错误断言
- ASSERT(FALSE);
-
- return false;
- }
- //对比扑克
- bool CGameLogic_Poker::CompareCard(BYTE cbFirstCard, BYTE cbNextCard)
- {
- //获取数值
- BYTE cbNextValue=GetCardLogicValue(cbNextCard);
- BYTE cbFirstValue=GetCardLogicValue(cbFirstCard);
-
- //比较大小
- return (cbNextValue>cbFirstValue);
- }
-
- BYTE CGameLogic_Poker::FindHaveCardCount(const BYTE cbCardBuffer[], BYTE cbCardCount, BYTE cbCardData, BYTE cbCardPosition[2])
- {
- BYTE CbCardHaveCount=0;
- for (BYTE i = 0; i < cbCardCount; i++){
- if (cbCardBuffer[i]==cbCardData)
- {
- cbCardPosition[CbCardHaveCount] = i;
- CbCardHaveCount++;
- }
- }
- return CbCardHaveCount;
- }
-
- //变幻扑克
- bool CGameLogic_Poker::MagicCardData(BYTE cbCardData[], BYTE cbCardCount, BYTE cbResultCard[MAX_COUNT_Poker])
- {
- //变量定义
- BYTE cbNormalCard[MAX_COUNT_Poker];
- BYTE cbMagicCardCount=0,cbNormalCardCount=0;
- if (m_GameMagicMode==NoHaveMagic)
- {
- CopyMemory(cbResultCard, cbCardData, cbCardCount*sizeof(BYTE));
- return false;
- }
- //变幻准备
- for (BYTE i=0;i<cbCardCount;i++)
- {
-
- switch (m_GameMagicMode)
- {
- case TwoMagicMode:{
- if (cbCardData[i] == 0x4F || cbCardData[i] == 0x4E) cbMagicCardCount++;
- else cbNormalCard[cbNormalCardCount++] = cbCardData[i];
- }
- break;
- case OneMagicMode:{
- if (cbCardData[i] == 0x4F) cbMagicCardCount++;
- else cbNormalCard[cbNormalCardCount++] = cbCardData[i];
- }
- break;
- case NoHaveMagic:
- cbNormalCard[cbNormalCardCount++] = cbCardData[i];
- break;
- default:
- break;
- }
-
-
-
- }
-
- //失败判断
- if ((cbMagicCardCount==0)||(cbNormalCardCount==0))
- {
- CopyMemory(cbResultCard,cbCardData,cbCardCount*sizeof(BYTE));
- return false;
- }
-
- //获取数值
- BYTE cbLogicValue=GetCardLogicValue(cbNormalCard[0]);
-
- //同牌变幻
- for (BYTE i=1;i<cbNormalCardCount;i++)
- {
- if (GetCardLogicValue(cbNormalCard[i])!=cbLogicValue) break;
- //特殊判断
- if(1 == cbNormalCardCount)
- {
- i=cbNormalCardCount;
- }
- if (i==cbNormalCardCount)
- {
- //设置结果
- for (BYTE j=0;j<cbMagicCardCount;j++) cbResultCard[j]=cbNormalCard[0];
- for (BYTE j=0;j<cbNormalCardCount;j++) cbResultCard[j+cbMagicCardCount]=cbNormalCard[j];
- return true;
- }
- }
-
- //扑克分析
- BYTE cbMaxSameCount=1,cbSameCount=1,cbBlock=0;
- for (BYTE i=1;i<cbNormalCardCount;i++)
- {
- //获取扑克
- BYTE cbCardValueTemp=GetCardLogicValue(cbNormalCard[i]);
- if (cbCardValueTemp==cbLogicValue) cbSameCount++;
-
- //结果处理
- if ((cbCardValueTemp!=cbLogicValue)||(i==(cbNormalCardCount-1)))
- {
- cbMaxSameCount=__max(cbSameCount,cbMaxSameCount);
- cbBlock++;
- }
-
- //恢复变量
- if ((cbCardValueTemp!=cbLogicValue)&&(i!=(cbNormalCardCount-1)))
- {
- cbSameCount=1;
- cbLogicValue=cbCardValueTemp;
- }
- }
-
- //等同变换
- if((cbCardCount>=12)&&(cbCardCount%cbBlock==0)&&(cbBlock>=3))
- {
- //最大牌数
- BYTE cbMaxSameCount1=cbCardCount/cbBlock;
-
- //连炸判断
- if(cbMaxSameCount1>=4)
- {
- //分析分布
- tagDistributing Distributing;
- AnalysebDistributing(cbNormalCard,cbNormalCardCount,Distributing);
-
- //变量定义
- BYTE cbFillCount=0;
- BYTE cbLeaveCount=cbNormalCardCount;
- BYTE cbUseableCount=cbMagicCardCount;
-
- //填充状态
- BYTE cbFillStatus[13];
- ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
-
- //填充扑克
- for (BYTE i=0;i<13;i++)
- {
- //变量定义
- BYTE cbIndex=i;
-
- //填充判断
- if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
- {
- //失败判断
- if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<cbMaxSameCount1) break;
-
- //变量定义
- BYTE cbTurnFillCount=0;
-
- //常规扑克
- for (BYTE j=0;j<4;j++)
- {
- for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
- {
- cbLeaveCount--;
- cbTurnFillCount++;
- cbResultCard[cbFillCount++]=MakeCardData(cbIndex,j);
- }
- }
-
- //填充变幻
- for (BYTE i=cbTurnFillCount;i<cbMaxSameCount1;i++)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
- }
-
- //设置变量
- cbFillStatus[cbIndex]=cbMaxSameCount;
- }
- }
- //成功判断
- if ((cbUseableCount==0)&&(cbLeaveCount==0))
- {
- SortCardList(cbResultCard,cbCardCount,ST_ORDER);
- return true;
- }
- }
- }
- //等同变换
- if((cbCardCount>=12)&&(cbCardCount%cbBlock==0)&&(cbBlock>=3))
- {
- //最大牌数
- BYTE cbMaxSameCount1=cbCardCount/cbBlock;
-
- //连炸判断
- if(cbMaxSameCount1>=4)
- {
- //分析分布
- tagDistributing Distributing;
- AnalyseRealDistributing(cbNormalCard,cbNormalCardCount,Distributing);
-
- //变量定义
- BYTE cbFillCount=0;
- BYTE cbLeaveCount=cbNormalCardCount;
- BYTE cbUseableCount=cbMagicCardCount;
-
- //填充状态
- BYTE cbFillStatus[13];
- ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
-
- //填充扑克
- for (BYTE i=0;i<13;i++)
- {
- //变量定义
- BYTE cbIndex=i;
-
- //填充判断
- if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
- {
- //失败判断
- if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<cbMaxSameCount) break;
-
- //变量定义
- BYTE cbTurnFillCount=0;
-
- //常规扑克
- for (BYTE j=0;j<4;j++)
- {
- for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
- {
- cbLeaveCount--;
- cbTurnFillCount++;
- cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,j);
- }
- }
-
- //填充变幻
- for (BYTE i=cbTurnFillCount;i<cbMaxSameCount1;i++)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,0);
- }
-
- //设置变量
- cbFillStatus[cbIndex]=cbMaxSameCount;
- }
- }
- //成功判断
- if ((cbUseableCount==0)&&(cbLeaveCount==0))
- {
- SortCardList(cbResultCard,cbCardCount,ST_ORDER);
- return true;
- }
- }
- }
-
- //不等变换
- if((cbMaxSameCount>=4)&&(cbBlock>=3)&&(cbCardCount>=12)) //3连排炸
- {
- //分析分布
- tagDistributing Distributing;
- AnalysebDistributing(cbNormalCard,cbNormalCardCount,Distributing);
-
- //填充分析
- for (BYTE cbTimes=0;cbTimes<2;cbTimes++)
- {
- //变量定义
- BYTE cbFillCount=0;
- BYTE cbLeaveCount=cbNormalCardCount;
- BYTE cbUseableCount=cbMagicCardCount;
-
- //填充状态
- BYTE cbFillStatus[13];
- ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
-
- //填充扑克
- for (BYTE i=0;i<13;i++)
- {
- //变量定义
- BYTE cbIndex=(cbTimes==1)?(cbIndex=(13-i)%13):i;
-
- //填充判断
- if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
- {
- //过滤炸弹
- if(Distributing.cbDistributing[cbIndex][cbIndexCount]>=4)
- {
- //记录数据
- cbFillStatus[cbIndex]=Distributing.cbDistributing[cbIndex][cbIndexCount];
- }
-
- //失败判断
- if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<4) break;
-
- //变量定义
- BYTE cbTurnFillCount=0;
-
- //常规扑克
- for (BYTE j=0;j<4;j++)
- {
- for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
- {
- cbLeaveCount--;
- cbTurnFillCount++;
- cbResultCard[cbFillCount++]=MakeCardData(cbIndex,j);
- }
- }
-
- //填充变幻
- for (BYTE i=cbTurnFillCount;i<4;i++)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
- }
-
- //设置变量
- if(cbTurnFillCount<4)
- cbFillStatus[cbIndex]=4;
- else
- cbFillStatus[cbIndex]=cbTurnFillCount;
- }
- }
-
- //剩余填充
- if ((cbLeaveCount==0)&&(cbUseableCount>0))
- {
- //现在先查找最小填充数
- BYTE cbMinFillCount=0;
- BYTE cbMaxFillCount=0;
- BYTE cbMinIndex=0;//最小索引
- for (BYTE i=0;i<13;i++)
- {
- if (cbFillStatus[i]==0) continue;//过滤没有填充的
-
- if(cbMinIndex==0 &&cbMinFillCount==0)
- {
- cbMinFillCount=cbFillStatus[i];
- cbMinIndex=i;
- }
-
- //开始寻找 取大
- if(cbFillStatus[i]<cbMinFillCount)
- {
- cbMinFillCount=cbFillStatus[i];
- cbMinIndex=i;
- }
- cbMaxFillCount=max(cbMaxFillCount,cbFillStatus[i]);
- }
-
- for (BYTE i=cbMinIndex;i<13;i++)
- {
- //变量定义
- BYTE cbIndex=(cbTimes==1)?(cbIndex=(13-i)%13):i;
- if (cbFillStatus[cbIndex]==0) continue;//过滤没有填充的
-
-
- //填充扑克
- for (BYTE j=cbFillStatus[cbIndex];j<cbMaxFillCount;j++)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
- //完成判断
- if (cbUseableCount==0) break;
-
- }
-
- //完成判断
- if (cbUseableCount==0) break;
- }
- //如果都填充满了 还有多余的王 那就从大到小的填充 毕竟王牌只有2个 一次就够了阿
- if(cbUseableCount>0)
- {
- for (BYTE i=12;i>=0;i--)
- {
- //填充扑克
- if(cbFillStatus[i]>0)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeCardData(i,0);
- cbFillStatus[i]++;
- }
-
- //完成判断
- if (cbUseableCount==0) break;
- }
- }
- }
-
-
-
- //成功判断
- if ((cbUseableCount==0)&&(cbLeaveCount==0))
- {
- SortCardList(cbResultCard,cbCardCount,ST_ORDER);
- return true;
- }
- }
- }
-
- //不等变换
- if((cbMaxSameCount>=4)&&(cbBlock>=3)&&(cbCardCount>=12)) //3连排炸
- {
- //分析分布
- tagDistributing Distributing;
- AnalyseRealDistributing(cbNormalCard,cbNormalCardCount,Distributing);
-
- //填充分析
- for (BYTE cbTimes=0;cbTimes<2;cbTimes++)
- {
- //变量定义
- BYTE cbFillCount=0;
- BYTE cbLeaveCount=cbNormalCardCount;
- BYTE cbUseableCount=cbMagicCardCount;
-
- //填充状态
- BYTE cbFillStatus[13];
- ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
-
- //填充扑克
- for (BYTE i=0;i<13;i++)
- {
- //变量定义
- BYTE cbIndex=(cbTimes==1)?(cbIndex=(13-i)%13):i;
-
- //填充判断
- if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
- {
- //过滤炸弹
- if(Distributing.cbDistributing[cbIndex][cbIndexCount]>=4)
- {
- //记录数据
- cbFillStatus[cbIndex]=Distributing.cbDistributing[cbIndex][cbIndexCount];
- }
-
- //失败判断
- if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<4) break;
-
- //变量定义
- BYTE cbTurnFillCount=0;
-
- //常规扑克
- for (BYTE j=0;j<4;j++)
- {
- for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
- {
- cbLeaveCount--;
- cbTurnFillCount++;
- cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,j);
- }
- }
-
- //填充变幻
- for (BYTE i=cbTurnFillCount;i<4;i++)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,0);
- }
-
- //设置变量
- if(cbTurnFillCount<4)
- cbFillStatus[cbIndex]=4;
- else
- cbFillStatus[cbIndex]=cbTurnFillCount;
- }
- }
-
- //剩余填充
- if ((cbLeaveCount==0)&&(cbUseableCount>0))
- {
- //现在先查找最小填充数
- BYTE cbMinFillCount=0;
- BYTE cbMaxFillCount=0;
- BYTE cbMinIndex=0;//最小索引
- for (BYTE i=0;i<13;i++)
- {
- if (cbFillStatus[i]==0) continue;//过滤没有填充的
-
- if(cbMinIndex==0 &&cbMinFillCount==0)
- {
- cbMinFillCount=cbFillStatus[i];
- cbMinIndex=i;
- }
-
- //开始寻找 取大
- if(cbFillStatus[i]<cbMinFillCount)
- {
- cbMinFillCount=cbFillStatus[i];
- cbMinIndex=i;
- }
- cbMaxFillCount=max(cbMaxFillCount,cbFillStatus[i]);
- }
-
- for (BYTE i=cbMinIndex;i<13;i++)
- {
- //变量定义
- BYTE cbIndex=(cbTimes==1)?(cbIndex=(13-i)%13):i;
- if (cbFillStatus[cbIndex]==0) continue;//过滤没有填充的
-
-
- //填充扑克
- for (BYTE j=cbFillStatus[cbIndex];j<cbMaxFillCount;j++)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,0);
- //完成判断
- if (cbUseableCount==0) break;
-
- }
-
- //完成判断
- if (cbUseableCount==0) break;
- }
- //如果都填充满了 还有多余的王 那就从大到小的填充 毕竟王牌只有2个 一次就够了阿
- if(cbUseableCount>0)
- {
- for (BYTE i=12;i>=0;i--)
- {
- //填充扑克
- if(cbFillStatus[i]>0)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeRealCardData(i,0);
- cbFillStatus[i]++;
- }
-
- //完成判断
- if (cbUseableCount==0) break;
- }
- }
- }
-
-
-
- //成功判断
- if ((cbUseableCount==0)&&(cbLeaveCount==0))
- {
- SortCardList(cbResultCard,cbCardCount,ST_ORDER);
- return true;
- }
- }
- }
- //连牌变幻
- if ((cbMaxSameCount<=3)&&((cbCardCount%cbMaxSameCount)==0)&&(cbCardCount/cbMaxSameCount<=13))
- {
- //分析分布
- tagDistributing Distributing;
- AnalysebDistributing(cbNormalCard,cbNormalCardCount,Distributing);
-
- //填充分析
- for (BYTE cbTimes=0;cbTimes<2;cbTimes++)
- {
- //变量定义
- BYTE cbFillCount=0;
- BYTE cbLeaveCount=cbNormalCardCount;
- BYTE cbUseableCount=cbMagicCardCount;
-
- //填充状态
- BYTE cbFillStatus[13];
- ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
-
- //填充扑克
- for (BYTE i=0;i<12;i++)
- {
- //变量定义
- BYTE cbIndex=(cbTimes==1)?(cbIndex=(11-i)%12):i;
-
- //填充判断
- if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
- {
- //失败判断
- if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<cbMaxSameCount) break;
-
- //变量定义
- BYTE cbTurnFillCount=0;
-
- //常规扑克
- for (BYTE j=0;j<4;j++)
- {
- for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
- {
- cbLeaveCount--;
- cbTurnFillCount++;
- cbResultCard[cbFillCount++]=MakeCardData(cbIndex,j);
- }
- }
-
- //填充变幻
- for (BYTE i=cbTurnFillCount;i<cbMaxSameCount;i++)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
- }
-
- //设置变量
- cbFillStatus[cbIndex]=cbMaxSameCount;
- }
- }
-
- //剩余填充
- if ((cbLeaveCount==0)&&(cbUseableCount>0))
- {
- for (BYTE i=0;i<12;i++)
- {
- //变量定义
- BYTE cbIndex=(cbTimes==0)?(cbIndex=(11-i)%12):i;
-
- //填充扑克
- for (BYTE j=cbFillStatus[cbIndex];j<cbMaxSameCount;j++)
- {
- cbUseableCount--;
- cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
- }
-
- //完成判断
- if (cbUseableCount==0) break;
- }
- }
-
- //成功判断
- if ((cbUseableCount==0)&&(cbLeaveCount==0))
- {
- SortCardList(cbResultCard,cbCardCount,ST_ORDER);
- return true;
- }
- }
- }
- //设置扑克
- CopyMemory(cbResultCard,cbCardData,cbCardCount*sizeof(BYTE));
-
- return false;
- }
-
- BOOL CGameLogic_Poker::ReplaceWangCards(BYTE OldCards[], BYTE cbCount, BYTE ReplacCards[4], OUT BYTE cbNoMagicCards[MAX_COUNT_Poker])
- {
-
- CopyMemory(cbNoMagicCards, OldCards, cbCount);
- byte mode = GetMagicType();
- if (mode==NoHaveMagic||ReplacCards[0]==0)
- {
- return FALSE;
- }
- for (int i = 0; i < 4;i++)
- {
- if (ReplacCards[i]==0)
- {
- break;
- }
- for (BYTE j = 0; j < cbCount; j++)
- {
- BOOL bFind = FALSE;
- switch (mode){
- case OneMagicMode:{
- if (cbNoMagicCards[j] == 0x4f)
- {
- bFind = TRUE;
- cbNoMagicCards[j] = ReplacCards[i];
- }
- break;
- }
- case TwoMagicMode:{
- if (cbNoMagicCards[j] == 0x4f || cbNoMagicCards[j] == 0x4e)
- {
- bFind = TRUE;
- cbNoMagicCards[j] = ReplacCards[i];
-
- break;
- }
- }
- }
- if (bFind)
- {
- break;
- }
- }
- }
- return TRUE;
- }
-
- //分析扑克
- VOID CGameLogic_Poker::AnalysebCardData(const BYTE cbCardData[], BYTE cbCardCount, tagAnalyseResult_Poker & 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++;
- }
-
- //设置结果
- 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_Poker::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 cbLogicValue=GetCardLogicValue(cbCardData[i]);
-
- //分布信息
- Distributing.cbCardCount++;
- Distributing.cbDistributing[cbLogicValue-3][cbIndexCount]++;
- Distributing.cbDistributing[cbLogicValue-3][cbCardColor>>4]++;
- }
-
-
- return;
- }
-
- //分析分布
- VOID CGameLogic_Poker::AnalyseRealDistributing(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]++;
- }
- }
-
- //出牌搜索
- bool CGameLogic_Poker::SearchOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagOutCardResult & OutCardResult)
- {
- //设置结果
- ZeroMemory(&OutCardResult,sizeof(OutCardResult));
-
- //构造扑克
- BYTE cbCardData[MAX_COUNT_Poker];
- BYTE cbCardCount=cbHandCardCount;
- CopyMemory(cbCardData,cbHandCardData,sizeof(BYTE)*cbHandCardCount);
-
- //排列扑克
- SortCardList(cbCardData,cbCardCount,ST_ORDER);
-
- //获取类型
- BYTE cbStarLevel;
- BomoType bomoinfo;
- BYTE cbTurnOutType = GetCardType(cbTurnCardData, cbTurnCardCount, cbStarLevel,bomoinfo);
-
- //出牌分析
- switch (cbTurnOutType)
- {
- case CT_ERROR: //错误类型
- {
- //获取数值
- BYTE cbLogicValue=GetCardLogicValue(cbCardData[cbCardCount-1]);
-
- //多牌判断
- BYTE cbSameCount=1;
- for (BYTE i=1;i<cbCardCount;i++)
- {
- if (GetCardLogicValue(cbCardData[cbCardCount-i-1])==cbLogicValue) cbSameCount++;
- else break;
- }
-
- //完成处理
- if (cbSameCount>1)
- {
- OutCardResult.cbCardCount=cbSameCount;
- for (BYTE j=0;j<cbSameCount;j++) OutCardResult.cbResultCard[j]=cbCardData[cbCardCount-1-j];
- return true;
- }
-
- //单牌处理
- OutCardResult.cbCardCount=1;
- OutCardResult.cbResultCard[0]=cbCardData[cbCardCount-1];
-
- return true;
- }
- }
-
-
- return false;
- }
-
- //搜索顺子
- bool CGameLogic_Poker::SearchLinkCard( const BYTE cbHandCardData[],BYTE cbHandCardCount,const BYTE cbFirstCardData,const BYTE cbLastCardData,tagOutCardResult &OutCardResult )
- {
- ASSERT( IsValidCard(cbFirstCardData) && IsValidCard(cbLastCardData) );
-
- //获取首位
- BYTE byFirstCardValue = GetCardLogicValue(cbFirstCardData);
- BYTE byLastCardValue = GetCardLogicValue(cbLastCardData);
-
- //交换数据
- if( byFirstCardValue > byLastCardValue )
- {
- BYTE byTemp = byFirstCardValue;
- byFirstCardValue = byLastCardValue;
- byLastCardValue = byTemp;
- }
-
- //判断顺子
- if( byFirstCardValue > 14 || byLastCardValue > 14 || byLastCardValue-byFirstCardValue<4 )
- return false;
-
- //定义变量
- tagDistributing Distribute;
- BYTE byCardData[MAX_COUNT_Poker],byCardCount = cbHandCardCount;
- CopyMemory(byCardData,cbHandCardData,sizeof(BYTE)*byCardCount);
- ZeroMemory(&OutCardResult,sizeof(OutCardResult));
-
- //分析扑克
- AnalysebDistributing(byCardData,byCardCount,Distribute);
-
- //变幻准备
- BYTE cbMagicCardCount=0;
- for (BYTE i=0;i<byCardCount;i++)
- {
- if (byCardData[i]==0x4F) cbMagicCardCount++;
- }
-
- //构造数据
- OutCardResult.cbResultCard[OutCardResult.cbCardCount++] = cbFirstCardData;
- OutCardResult.cbResultCard[OutCardResult.cbCardCount++] = cbLastCardData;
- for( BYTE i = byFirstCardValue-2; i < byLastCardValue-3; i++ )
- {
- if( Distribute.cbDistributing[i][cbIndexCount] > 0 )
- {
- //获取花色
- BYTE cbHeadColor=0xFF;
- for (BYTE cbColorIndex=0;cbColorIndex<4;cbColorIndex++)
- {
- if (Distribute.cbDistributing[i][3-cbColorIndex]>0)
- {
- cbHeadColor=3-cbColorIndex;
- break;
- }
- }
- ASSERT(cbHeadColor!=0xFF);
- OutCardResult.cbResultCard[OutCardResult.cbCardCount++] = MakeCardData(i,cbHeadColor);
-
- }
- else
- {
- //王牌替换
- if(cbMagicCardCount>0)
- {
- OutCardResult.cbResultCard[OutCardResult.cbCardCount++] = 0x4F;
-
- //王牌递减
- cbMagicCardCount--;
- }
- else
- break;
- }
- if (i == byLastCardValue - 3)
- {
-
- SortCardList(OutCardResult.cbResultCard, OutCardResult.cbCardCount);
- return true;
- }
- }
-
-
- //结果清零
- ZeroMemory(&OutCardResult,sizeof(OutCardResult));
- return false;
- }
-
- void CGameLogic_Poker::SetMagicType(BYTE nMode)
- {
- m_GameMagicMode = nMode;
- }
-
- BYTE CGameLogic_Poker::GetMagicType()
- {
- return m_GameMagicMode;
- }
-
- BYTE CGameLogic_Poker::GetCardCount(const BYTE cbCardData[], BYTE MAX_CardNum /*= MAX_COUNT_Poker*/)
- {
- for (BYTE i = 1; i <= MAX_CardNum; ++i)
- {
- if (cbCardData[i] == 0)
- return i;
- }
- return MAX_CardNum;
- }
-
- BYTE CGameLogic_Poker::GetCardMagicCount(const BYTE cbCardData[], BYTE CardCount)
- {
- BYTE cbMagicCardCount = 0;
- switch (m_GameMagicMode)
- {
- case TwoMagicMode:{
- for (int i = 0; i < CardCount;i++)
- {
- if (cbCardData[i] == 0x4F || cbCardData[i] == 0x4E)
- cbMagicCardCount++;
- }
-
-
- }
- break;
- case OneMagicMode:{
- for (int i = 0; i < CardCount; i++)
- {
- if (cbCardData[i] == 0x4F)
- cbMagicCardCount++;
- }
- }
- break;
- case NoHaveMagic:
- cbMagicCardCount=0;
- break;
- default:
- break;
- }
- return cbMagicCardCount;
- }
- bool HitComp(HitStruct & h1, HitStruct h2){
- return h1.cbCardCount<h2.cbCardCount;
- }
- BOOL CGameLogic_Poker::bCanOutCard(const BYTE cbCardDatas[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- BYTE cbCardData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(cbCardData, cbCardDatas, cbCount);
- SortCardList(cbCardData, cbCount, ST_ORDER, ORDERBY_DES);
- if (cbCount==0)
- {
- return TRUE;
- }
- ListHit.clear();
- //先获取用户出牌的数据类型
- BYTE cbLevel;
- BomoType BomoInfo;
- BYTE type = GetCardType(cbCardData, cbCount, cbLevel, BomoInfo);
- tagDistributing tag;
- AnalysebDistributing(UserCards, cbUserCount, tag);
- tagAnalyseResult_Poker tagResult;
- AnalysebCardData(UserCards, cbUserCount, tagResult);
- LastCardsInfo lstCardsInfo;
- lstCardsInfo.CardType = type;
- lstCardsInfo.cbCardCount = cbCount;
- CopyMemory(lstCardsInfo.cbCards, cbCardData, cbCount);
- lstCardsInfo.BomoInfo = BomoInfo;
-
- switch(type){
- case CT_SINGLE:{
- //1-8张的牌 全部取一张
- HintSignle(cbCardData, cbCount, UserCards, cbUserCount, ListHit);
- //查找 可以组成4张牌的炸弹
- //HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
- AllSameBomos(cbCardData, cbCount,4, type, UserCards, cbUserCount, ListHit, TRUE);
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- //所有特殊牌 5-8X相炸弹
- //所有特殊牌 5-12线连 炸弹
- //HintBoomWithXian(cbCardData, cbCount, BomoInfo, UserCards, cbUserCount, ListHit, TRUE);
- break;
- }
- //5张或5张以上才可能是顺子
- case CT_SHUNZI:{
- HintSHUNZI(cbCardData, cbCount, UserCards, cbUserCount, ListHit);
- HintShunWithJoker(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit);
- HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
- AllSameBomos(cbCardData, cbCount,4, type, UserCards, cbUserCount, ListHit, TRUE);
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- break;
- }
- case CT_DOUBLE:{
- HintSameCardCount(cbCardData, cbCount, cbCount, UserCards, cbUserCount, ListHit, FALSE);
- //从3-8 中 找对子
- HintSameCardCount_WithFindCount(cbCardData, cbCount, 2, UserCards, cbUserCount, ListHit);
- //HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
- AllSameBomos(cbCardData, cbCount, 4, type, UserCards, cbUserCount, ListHit, TRUE);
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- break;
- }
- //连对3或3以上个对子
- case CT_DOUBLE_LINK:{
-
- HintDOUBLE_LINK(cbCardData, cbCount, UserCards, cbUserCount, ListHit);
- HintShunWithJoker(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit);
- //HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
- AllSameBomos(cbCardData, cbCount,4, type, UserCards, cbUserCount, ListHit, TRUE);
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- break;
- }
- case CT_THREE:{
- HintSameCardCount(cbCardData, cbCount, cbCount,UserCards, cbUserCount, ListHit, FALSE);
- HintSameCardCount_WithFindCount(cbCardData, cbCount, 3, UserCards, cbUserCount, ListHit);
- HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
- AllSameBomos(cbCardData, cbCount, 4, type, UserCards, cbUserCount, ListHit, TRUE);
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
-
- break;
- }
- //连三张 或者叫飞机 555666777 最少9张
- case CT_THREE_LINK:{
- HintTHREE_LINK(cbCardData, cbCount, UserCards, cbUserCount, ListHit);
- HintShunWithJoker(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit);
- HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
- AllSameBomos(cbCardData, cbCount,4, type, UserCards, cbUserCount, ListHit, TRUE);
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- break;
- }
- case CT_BOMB:{
- lstCardsInfo.BomoInfo.Level = cbLevel;
- BomoInfo.Level = cbLevel;
- //4 5 6 7 8 都叫X相炸弹
- //if (cbCount==4 )
- //{
- // HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
- //}
- AllSameBomos(cbCardData, cbCount, cbCount,type, UserCards, cbUserCount, ListHit, TRUE);
- //查找5-12线炸弹
- HintBomoWithXian(cbCardData, cbCount, type,BomoInfo, UserCards, cbUserCount, ListHit);
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- break;
- }
- case CT_BOMB_3W:{
- //3王炸 仅癞子玩法有此牌 最小的6线
- GetAllSameCards(6, ListHit, tag);
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- break;
- }
- case CT_BOMB_TW:{
- //天王炸 4个王 癞子算7线 非癞子 算最大牌(8线)
- if (GetMagicType()==NoHaveMagic)
- {
- GetAllSameCards(9, ListHit, tag);
- }
- else
- {
- GetAllSameCards(8, ListHit, tag);
- }
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- break;
- }
- case CT_BOMB_LINK:
- case CT_BOMB_XIAN:
- {
-
- FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
- //根据当前线级别 找对应 同级别的
- if (BomoInfo.Level<12)
- {
- GetAllSameCards(BomoInfo.Level, ListHit, tag);
- }
- Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
- break;
- }
- }
-
- //sort(ListHit.begin(), ListHit.end(), HitComp);
- //vector 排序 根据牌的个数
- if (ListHit.size()>0)
- {
- return TRUE;
- }
- return FALSE;
-
- }
-
- BOOL CGameLogic_Poker::HaveCanOutCard(BYTE cbCardLogicValue, BYTE SameCardCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- tagDistributing tagDsit;
- AnalysebDistributing(UserCards, cbUserCount, tagDsit);
- for (int CardCount = SameCardCount; CardCount > 0; CardCount--){
- //找逻辑值比他大的牌
- for (int i = cbCardLogicValue - 3 + 1; i < 16; i++)
- {
- if (tagDsit.cbDistributing[i][5] >= CardCount)
- {
- HitStruct st;
- st.cbCardType = CT_SINGLE;
- st.cbHintLogicCardData[0] = GetCardLogicValue(UserCards[i]);
- ListHit.push_back(st);
- }
- }
- BYTE MagicCount = GetCardMagicCount(UserCards, cbUserCount);
- if (MagicCount >= CardCount)
- {
- return TRUE;
- }
- for (int Count = MagicCount; Count > 0; Count--){
- for (int i = cbCardLogicValue - 3 + 1; i < 16; i++)
- {
- if (tagDsit.cbDistributing[i][5] >= CardCount-Count)
- {
- return TRUE;
- }
- }
- }
- }
- return FALSE;
- }
-
- //构造扑克
- BYTE CGameLogic_Poker::MakeCardData(BYTE cbValueIndex, BYTE cbColorIndex)
- {
- //构造扑克
- switch (cbValueIndex)
- {
- case 11: //A 扑克
- {
- return (cbColorIndex<<4)|0x01;
- }
- case 12: //2 扑克
- {
- return (cbColorIndex<<4)|0x02;
- }
-
- case 13: //小鬼扑克
- {
- return (4<<4)|0x0E;
- }
- case 14: //大鬼扑克
- {
- return (4<<4)|0x0F;
- }
- default: //其他扑克
- {
- return (cbColorIndex<<4)|(cbValueIndex+3);
- }
- }
-
- return 0x00;
- }
-
- //构造扑克
- BYTE CGameLogic_Poker::MakeRealCardData(BYTE cbValueIndex, BYTE cbColorIndex)
- {
- //构造扑克
- switch (cbValueIndex)
- {
-
- case 13: //小鬼扑克
- {
- return (4<<4)|0x0E;
- }
- case 14: //大鬼扑克
- {
- return (4<<4)|0x0F;
- }
-
- default: //其他扑克
- {
- return (cbColorIndex<<4)|(cbValueIndex+1);
- }
- }
-
- return 0x00;
- }
-
-
- //是否连牌
- bool CGameLogic_Poker::IsStructureLink(const BYTE cbCardData[], BYTE cbCardCount, BYTE cbCellCount,bool bSpecial)
- {
- //数目判断
- ASSERT((cbCardCount%cbCellCount)==0);
- if ((cbCardCount%cbCellCount)!=0) return false;
-
- //变量定义
- BYTE cbBlockCount=cbCardCount/cbCellCount;
- BYTE cbFirstValue=GetCardLogicValue(cbCardData[0]);
-
- if(bSpecial)
- {
- //特殊处理 2在连炸中
- if (cbFirstValue==15)
- {
- for (BYTE i=1;i<cbBlockCount;i++)
- {
- //获取数值
- BYTE cbLogicValue=GetCardLogicValue(cbCardData[i*cbCellCount]);
-
- //连牌判断
- if ((cbFirstValue!=(cbLogicValue+i))&&(cbFirstValue!=(cbLogicValue+i+(15-cbBlockCount-2)))) return false;
- }
-
- return true;
- }
- }
-
- //大牌过滤
- if(cbFirstValue>14) return false;
-
- //分析处理
- for (BYTE i=1;i<cbBlockCount;i++)
- {
- BYTE NextCardValue = (GetCardLogicValue(cbCardData[i*cbCellCount]) + i);
- if (cbFirstValue != NextCardValue){
- return false;
- }
-
- }
-
- return true;
- }
-
- bool CGameLogic_Poker::IsStructureLink_zhengxu(const BYTE cbCardData[], BYTE cbCardCount, BYTE cbCellCount, bool bSpecial /*= false*/)
- {
- //数目判断
- ASSERT((cbCardCount%cbCellCount) == 0);
- if ((cbCardCount%cbCellCount) != 0) return false;
-
- //变量定义
- BYTE cbBlockCount = cbCardCount / cbCellCount;
- BYTE cbFirstValue = GetCardLogicValue(cbCardData[0]);
-
- if (bSpecial)
- {
- //特殊处理 2在连炸中
- if (cbFirstValue == 15)
- {
- for (BYTE i = 1; i < cbBlockCount; i++)
- {
- //获取数值
- BYTE cbLogicValue = GetCardLogicValue(cbCardData[i*cbCellCount]);
-
- //连牌判断
- if ((cbFirstValue != (cbLogicValue - i)) && (cbFirstValue != (cbLogicValue - i + (15 - cbBlockCount - 2))))
- return false;
- }
-
- return true;
- }
- }
-
- //大牌过滤
- if (cbFirstValue > 14) return false;
-
- //分析处理
- for (BYTE i = 1; i < cbBlockCount; i++)
- {
-
- BYTE NextCardValue = (GetCardLogicValue(cbCardData[i*cbCellCount])-i );
- if (cbFirstValue != NextCardValue){
- return false;
- }
-
- }
-
- return true;
- }
-
- void CGameLogic_Poker::HintSignle(const BYTE cbCardData[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- tagDistributing tag;
- AnalysebDistributing(UserCards, cbUserCount, tag);
- BYTE cbLogicCardValue = GetCardLogicValue(cbCardData[0]);
-
- //所有单牌 找到所有牌中的 单张
- for (int j = 1; j <= 3;j++) // 优化后 单张 只从 1 2 3 张中寻找 [1/29/2019 Zoro]
- {
- for (int i = cbLogicCardValue - 3 + 1; i < 15; i++)
- {
- if (tag.cbDistributing[i][5] == j)
- {
- HitStruct st;
- st.cbCardType = CT_SINGLE;
- st.cbCardCount = 1;
- st.cbHintLogicCardData[0] = TagIndexToNoColorCardValue(i + 3);
- ListHit.push_back(st);
- }
- }
- }
-
- }
-
- void CGameLogic_Poker::HintSameCardCount(const BYTE cbCardData[], BYTE cbCardDataCount, BYTE NeedFindCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit, BOOL IsAll)
- {
- tagDistributing tag;
- AnalysebDistributing(UserCards, cbUserCount, tag);
- BYTE cbLogicCardValue = 2;//应该是3 但是下面循环+1 了 所以写2
- if (!IsAll)
- {
- cbLogicCardValue=GetCardLogicValue(cbCardData[0]);
- }
-
-
- for (int i = cbLogicCardValue - 3 + 1; i < 15; i++)
- {
- BOOL bPusthHisList = TRUE;
- if (tag.cbDistributing[i][5] == NeedFindCount)
- {
- HitStruct st;
- st.cbCardCount = NeedFindCount;
- switch (NeedFindCount)
- {
- case 1:
- st.cbCardType = CT_SINGLE;
-
- break;
- case 2:
- st.cbCardType = CT_DOUBLE;
- break;
- case 3:
- st.cbCardType = CT_THREE;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- st.cbCardType = CT_BOMB;
- break;
- default:
- break;
- }
- for (int j = 0; j< NeedFindCount; j++)
- {
- st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
- }
- //如果当前是炸弹,计算是否比上家的炸弹大
- if (st.cbCardType==CT_BOMB)
- {
- BYTE cbLastLevel = 0;
- BomoType LastBomo;
- int nOldType=GetCardType(cbCardData, cbCardDataCount, cbLastLevel, LastBomo);
- if (nOldType==CT_BOMB)
- {
- LastBomo.Level = cbLastLevel;
- }
- BYTE cbLevel=0;
- BomoType BomoInfo;
-
- int nNewType=GetCardType(st.cbHintLogicCardData, st.cbCardCount, cbLevel, BomoInfo);
-
- if (nNewType == CT_BOMB)
- {
- BomoInfo.Level = cbLevel;
- }
- if (cbLevel>cbLastLevel)
- {
- bPusthHisList = TRUE;
- }
- else
- {
- if (cbLevel >= 4 && cbLastLevel >= 4)
- {
- bPusthHisList = CompareCardBigLastCards(LastBomo, (BYTE*)cbCardData, cbCardDataCount, BomoInfo, st.cbHintLogicCardData, st.cbCardCount);
- }
- }
-
- }
- if (bPusthHisList)
- {
- ListHit.push_back(st);
- }
-
- }
- }
-
- //计算magic 所处位置
- BYTE cbCardMagic[4] = { 0 };
- BYTE nMagicCount = GetMagicJokerCount(UserCards, cbUserCount,cbCardMagic);
- for (BYTE NeedMagicConut = 1; NeedMagicConut <= nMagicCount;NeedMagicConut++)
- {
- int MaxIndex = 13;
- for (int i = cbLogicCardValue - 3 + 1; i < MaxIndex; i++)
- {
- BOOL bPusthHisList = TRUE;
- if (tag.cbDistributing[i][5] != 0 && tag.cbDistributing[i][5] == NeedFindCount - NeedMagicConut && (NoJokerBigUserCards(i, tag.cbDistributing[i][5], cbCardData, cbCardDataCount) == FALSE || ListHit.size()==0))
- {
- HitStruct st;
- st.cbCardCount = NeedFindCount;
- switch (NeedFindCount)
- {
- case 1:
- st.cbCardType = CT_SINGLE;
-
- break;
- case 2:
- st.cbCardType = CT_DOUBLE;
- break;
- case 3:
- st.cbCardType = CT_THREE;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- st.cbCardType = CT_BOMB;
- break;
- default:
- break;
- }
- BYTE cbReplacedCards[MAX_COUNT_Poker] = { 0 };
- for (int j = 0; j < NeedFindCount - NeedMagicConut; j++)
- {
- st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);
- cbReplacedCards[j] = TagIndexToNoColorCardValue(i + 3);
- }
- BYTE WithMagicCount = 0;
- for (int magicindex = NeedFindCount - NeedMagicConut; magicindex < NeedFindCount; magicindex++)
- {
- st.cbHintLogicCardData[magicindex] = GetCardLogicValue(cbCardMagic[WithMagicCount]);
- cbReplacedCards[magicindex] = TagIndexToNoColorCardValue(i + 3);
- WithMagicCount++;
- }
- //如果当前是炸弹,计算是否比上家的炸弹大
- // if (st.cbCardType == CT_BOMB)
- // {
- // BYTE NoColorCardValue = i + 3;
- // BYTE LastCard = GetCardLogicValue(cbCardData[0]);
- // if (NoColorCardValue<=LastCard)
- // {
- // bPusthHisList = FALSE;
- // }
- // }
- //如果当前是炸弹,计算是否比上家的炸弹大
- if (st.cbCardType == CT_BOMB)
- {
- BYTE cbLastLevel = 0;
- BomoType LastBomo;
- int nOldType = GetCardType(cbCardData, cbCardDataCount, cbLastLevel, LastBomo);
- if (nOldType == CT_BOMB)
- {
- LastBomo.Level = cbLastLevel;
- }
- BYTE cbLevel = 0;
- BomoType BomoInfo;
-
- int nNewType = GetCardType(cbReplacedCards, st.cbCardCount, cbLevel, BomoInfo);
-
- if (nNewType == CT_BOMB)
- {
- BomoInfo.Level = cbLevel;
- }
- if (cbLevel>cbLastLevel)
- {
- bPusthHisList = TRUE;
- }
- else
- {
- if (cbLevel >= 4 && cbLastLevel >= 4)
- {
- bPusthHisList = CompareCardBigLastCards(LastBomo, (BYTE*)cbCardData, cbCardDataCount, BomoInfo, cbReplacedCards, st.cbCardCount);
- }
- }
-
- }
- if (bPusthHisList)
- {
- ListHit.push_back(st);
- }
-
- }
- }
- }
-
- }
-
- void CGameLogic_Poker::HintSameCardCount_WithFindCount(const BYTE cbCardData[], BYTE cbCount, BYTE nFindCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- tagDistributing tag;
- AnalysebDistributing(UserCards, cbUserCount, tag);
- BYTE cbLogicCardValue = GetCardLogicValue(cbCardData[0]);
-
- for (int Count = nFindCount; Count <= 8; Count++){
- for (int i = cbLogicCardValue - 3 + 1; i < 15; i++)
- {
-
- if (tag.cbDistributing[i][5] > Count&&tag.cbDistributing[i][5]<4)
- {
- HitStruct st;
- st.cbCardCount = Count;
- switch (Count)
- {
- case 1:
- st.cbCardType = CT_SINGLE;
-
- break;
- case 2:
- st.cbCardType = CT_DOUBLE;
- break;
- case 3:
- st.cbCardType = CT_THREE;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- st.cbCardType = CT_BOMB;
- break;
- default:
- break;
- }
- if (Count == 3 && cbCount==2)
- {
- continue;
- }
- for (int j = 0; j < Count; j++)
- {
- st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
- }
- ListHit.push_back(st);
- }
- }
- }
-
-
-
- //计算magic 所处位置
- BYTE cbCardMagic[4] = { 0 };
- BYTE nMagicCount = GetMagicJokerCount(UserCards, cbUserCount, cbCardMagic);
- for (int Count = nFindCount; Count <= 8; Count++){
- for (BYTE NeedMagicConut = 1; NeedMagicConut <= nMagicCount; NeedMagicConut++)
- {
- for (int i = cbLogicCardValue - 3 + 1; i < 13; i++)
- {
-
- if (tag.cbDistributing[i][5] == Count - NeedMagicConut&&tag.cbDistributing[i][5] != 0 && tag.cbDistributing[i][5]<4)
- {
- HitStruct st;
- st.cbCardCount = cbCount;
- switch (cbCount)
- {
- case 1:
- st.cbCardType = CT_SINGLE;
-
- break;
- case 2:
- st.cbCardType = CT_DOUBLE;
- break;
- case 3:
- st.cbCardType = CT_THREE;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- st.cbCardType = CT_BOMB;
- break;
- default:
- break;
- }
- for (int j = 0; j < cbCount - NeedMagicConut; j++)
- {
- st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
- }
- BYTE WithMagicCount = 0;
- for (int magicindex = cbCount - NeedMagicConut; magicindex < cbCount; magicindex++)
- {
- st.cbHintLogicCardData[magicindex] = GetCardLogicValue(cbCardMagic[WithMagicCount++]);
- }
- ListHit.push_back(st);
- }
- }
- }
- }
- }
-
- void CGameLogic_Poker::HintDOUBLE_LINK(const BYTE cbCardData[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- cbCount = cbCount / 2;
- if (cbUserCount < cbCount)
- {
- return;
- }
- BYTE szcbCardData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szcbCardData, cbCardData, cbCount*2);
- SortCardList(szcbCardData, cbCount*2, ST_ORDER, ORDERBY_ASE);
-
- BYTE MinCardLogic = GetCardLogicValue(szcbCardData[0]);
-
-
- BYTE szTmpUserCards[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szTmpUserCards, UserCards, cbUserCount);
- SortCardList(szTmpUserCards, cbUserCount, ST_ORDER, ORDERBY_ASE);
- tagDistributing tag;
- AnalysebDistributing(szTmpUserCards, cbUserCount, tag);
- BYTE OneCardArray[MAX_COUNT_Poker] = { 0 };
- BYTE OneCardCount = 0;
- //顺子 2不能再其中 所以12 即可
- for (int i = 0; i < 12; i++)
- {
- if (tag.cbDistributing[i][5] >= 2)
- {
- if (MinCardLogic >= i + 3)
- {
- continue;
- }
- OneCardArray[OneCardCount++] = TagIndexToNoColorCardValue(i + 3);;
- }
- }
- if (OneCardCount < cbCount)
- {
- return;
- }
- vector<vector<BYTE>> vShunNoJoker;
- SortCardList(OneCardArray, OneCardCount, ST_ORDER, ORDERBY_ASE);
- FindShunZI(OneCardArray, OneCardCount, cbCount, vShunNoJoker);
- if (vShunNoJoker.size()>0)
- {
- vector<vector<BYTE>>::iterator oneSt = vShunNoJoker.begin();
- for (; oneSt != vShunNoJoker.end(); oneSt++)
- {
- HitStruct hit;
- hit.cbCardCount = cbCount;
- hit.cbCardType = CT_DOUBLE_LINK;
- for (int i = 0; i < hit.cbCardCount; i++)
- {
- hit.cbHintLogicCardData[hit.cbCardCount - i - 1] = (*oneSt)[i];
- hit.cbHintLogicCardData[2*hit.cbCardCount - i - 1] = (*oneSt)[i];
- }
- hit.cbCardCount = cbCount*2;
- SortCardList(hit.cbHintLogicCardData, hit.cbCardCount, ST_ORDER, ORDERBY_ASE);
- ListHit.push_back(hit);
- }
- }
-
- }
-
-
-
- void CGameLogic_Poker::HintTHREE_LINK(const BYTE cbCardData[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- cbCount = cbCount / 3;
- if (cbUserCount < cbCount)
- {
- return;
- }
- BYTE szcbCardData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szcbCardData, cbCardData, cbCount * 3);
- SortCardList(szcbCardData, cbCount * 3, ST_ORDER, ORDERBY_ASE);
-
- BYTE MinCardLogic = GetCardLogicValue(szcbCardData[0]);
-
-
- BYTE szTmpUserCards[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szTmpUserCards, UserCards, cbUserCount);
- SortCardList(szTmpUserCards, cbUserCount, ST_ORDER, ORDERBY_ASE);
- tagDistributing tag;
- AnalysebDistributing(szTmpUserCards, cbUserCount, tag);
- BYTE OneCardArray[MAX_COUNT_Poker] = { 0 };
- BYTE OneCardCount = 0;
- //顺子 2不能再其中 所以12 即可
- for (int i = 0; i < 12; i++)
- {
- if (tag.cbDistributing[i][5] >= 3)
- {
- if (MinCardLogic >= i + 3)
- {
- continue;
- }
- OneCardArray[OneCardCount++] = TagIndexToNoColorCardValue(i + 3);;
- }
- }
- if (OneCardCount < cbCount)
- {
- return;
- }
- vector<vector<BYTE>> vShunNoJoker;
- SortCardList(OneCardArray, OneCardCount, ST_ORDER, ORDERBY_ASE);
- FindShunZI(OneCardArray, OneCardCount, cbCount, vShunNoJoker);
- if (vShunNoJoker.size()>0)
- {
- vector<vector<BYTE>>::iterator oneSt = vShunNoJoker.begin();
- for (; oneSt != vShunNoJoker.end(); oneSt++)
- {
- HitStruct hit;
- hit.cbCardCount = cbCount;
- hit.cbCardType = CT_THREE_LINK;
- for (int i = 0; i < hit.cbCardCount; i++)
- {
- hit.cbHintLogicCardData[hit.cbCardCount - i - 1] = (*oneSt)[i];
- hit.cbHintLogicCardData[2 * hit.cbCardCount - i - 1] = (*oneSt)[i];
- hit.cbHintLogicCardData[3 * hit.cbCardCount - i - 1] = (*oneSt)[i];
- }
- hit.cbCardCount = cbCount * 3;
- SortCardList(hit.cbHintLogicCardData, hit.cbCardCount, ST_ORDER, ORDERBY_ASE);
- ListHit.push_back(hit);
- }
- }
- }
-
- //顺子
- void CGameLogic_Poker::HintSHUNZI(const BYTE cbCardData[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- if (cbUserCount<cbCount)
- {
- return;
- }
- BYTE szcbCardData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szcbCardData, cbCardData, cbCount);
- SortCardList(szcbCardData, cbCount, ST_ORDER, ORDERBY_ASE);
-
- BYTE MinCardLogic = GetCardLogicValue(szcbCardData[0]);
-
-
- BYTE szTmpUserCards[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szTmpUserCards, UserCards, cbUserCount);
- SortCardList(szTmpUserCards, cbUserCount, ST_ORDER, ORDERBY_ASE);
- tagDistributing tag;
- AnalysebDistributing(szTmpUserCards, cbUserCount, tag);
- BYTE OneCardArray[MAX_COUNT_Poker] = { 0 };
- BYTE OneCardCount = 0;
- //顺子 2不能再其中 所以12 即可
- for (int i = 0; i < 12;i++)
- {
- if (tag.cbDistributing[i][5] != 0)
- {
- if (MinCardLogic>=i+3)
- {
- continue;
- }
- OneCardArray[OneCardCount++] = TagIndexToNoColorCardValue(i + 3);;
- }
- }
- if (OneCardCount<cbCount)
- {
- return;
- }
- vector<vector<BYTE>> vShunNoJoker;
- SortCardList(OneCardArray, OneCardCount, ST_ORDER, ORDERBY_ASE);
- FindShunZI(OneCardArray, OneCardCount, cbCount, vShunNoJoker);
- if (vShunNoJoker.size()>0)
- {
- vector<vector<BYTE>>::iterator oneSt = vShunNoJoker.begin();
- for (; oneSt!=vShunNoJoker.end();oneSt++)
- {
- HitStruct hit;
- hit.cbCardCount = cbCount;
- hit.cbCardType = CT_SHUNZI;
- for (int i = 0; i <hit.cbCardCount; i++)
- {
- hit.cbHintLogicCardData[hit.cbCardCount-i-1] = (*oneSt)[i];
- }
- ListHit.push_back(hit);
- }
- }
-
-
-
- }
-
- void CGameLogic_Poker::HintBoom(const BYTE cbCardData[], BYTE cbCount, BYTE cbCardType, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit,BOOL WithJoker)
- {
- tagDistributing tag;
- AnalysebDistributing(UserCards, cbUserCount, tag);
- BYTE cbLogicCardValue = GetCardLogicValue(cbCardData[0]);
- int FromIndex = 0;
- if (cbCardType<7)
- {
- FromIndex = 0;
- }
- else
- {
- if (cbCount!=4)
- {
- //OutputDebugString(L"HintBoom 只处理4张的炸 和小牌");
- return;
- }
- FromIndex = cbLogicCardValue - 3 + 1;
- }
-
- for (int i = FromIndex; i < 13; i++)
- {
- BYTE ThisCardCount = tag.cbDistributing[i][5];
- if (ThisCardCount == 4)
- {
- HitStruct st;
- st.cbCardCount = ThisCardCount;
- st.cbCardType = CT_BOMB;
-
- for (int j = 0; j < ThisCardCount; j++)
- {
- st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
- }
- ListHit.push_back(st);
- }
- }
-
- //如果带王 则找到 需要1个王 2个王 三个王 4个王的
- BYTE MagicCount=0;
- if (WithJoker)
- {
- BYTE MagicCards[4] = { 0 };
- BYTE ReplaceConut = 0;
- MagicCount = GetMagicJokerCount(UserCards, cbUserCount, MagicCards);
- if (MagicCount>3)
- {
- return;
- }
- for (int JokerCount = 1; JokerCount <= MagicCount;JokerCount++)
- {
-
- for (int i = FromIndex; i < 13; i++)
- {
- ReplaceConut = 0;
- BYTE ThisCardCount = tag.cbDistributing[i][5];
- if (ThisCardCount + JokerCount == 4/* && (i + 3)>cbLogicCardValue*/)
- {
- HitStruct st;
- st.cbCardCount = ThisCardCount + JokerCount;
- st.cbCardType = CT_BOMB;
- for (int j = 0; j < ThisCardCount; j++)
- {
- st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
- }
- for (int lastIndex = 4 - JokerCount; lastIndex < 4; lastIndex++)
- {
- st.cbHintLogicCardData[lastIndex] = GetCardLogicValue(MagicCards[ReplaceConut++]);
- }
- ListHit.push_back(st);
- }
- }
-
- }
-
- }
-
-
-
- }
-
-
- void CGameLogic_Poker::AllSameBomos(const BYTE cbCardData[], BYTE cbCount, BYTE FromIndex,BYTE cbCardType, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit, BOOL WithJoker)
- {
- for (int i = FromIndex; i < 14; i++)
- {
- if (i==0)
- {
- continue;
- }
- HintSameCardCount(cbCardData, cbCount, i, UserCards, cbUserCount, ListHit, TRUE);
- }
- }
-
- void CGameLogic_Poker::HintBomoWithXian(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType BomoInfo, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
-
- //如果上家出的牌不是炸弹 则 直接从0找 5-12线炸弹
- tagDistributing tag;
- AnalysebDistributing(UserCards, cbUserCount, tag);
- tagAnalyseResult_Poker tagResult;
- AnalysebCardData(UserCards, cbUserCount, tagResult);
- if (cbCount<6)
- {
- FindAll5XianBomo(cbCardData, cbCount, type, BomoInfo, tag, tagResult, ListHit, UserCards, cbUserCount);
- }
-
- }
-
- void CGameLogic_Poker::HintBomoWithLian(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType BomoInfo, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
-
- cbCount = cbCount / BomoInfo.tong;
- if (cbUserCount < cbCount)
- {
- return;
- }
- BYTE szcbCardData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szcbCardData, cbCardData, cbCount * BomoInfo.tong);
- SortCardList(szcbCardData, cbCount * BomoInfo.tong, ST_ORDER, ORDERBY_ASE);
-
- BYTE MinCardLogic = GetCardLogicValue(szcbCardData[0]);
-
-
- BYTE szTmpUserCards[MAX_COUNT_Poker] = { 0 };
- CopyMemory(szTmpUserCards, UserCards, cbUserCount);
- SortCardList(szTmpUserCards, cbUserCount, ST_ORDER, ORDERBY_ASE);
- tagDistributing tag;
- AnalysebDistributing(szTmpUserCards, cbUserCount, tag);
- BYTE OneCardArray[MAX_COUNT_Poker] = { 0 };
- BYTE OneCardCount = 0;
- //顺子 2不能再其中 所以12 即可
- for (int i = 0; i < 12; i++)
- {
- if (tag.cbDistributing[i][5] >= BomoInfo.tong)
- {
- if (MinCardLogic >= i + BomoInfo.tong)
- {
- continue;
- }
- OneCardArray[OneCardCount++] = TagIndexToNoColorCardValue(i + 3);
- }
- }
- if (OneCardCount < cbCount)
- {
- return;
- }
- vector<vector<BYTE>> vShunNoJoker;
- SortCardList(OneCardArray, OneCardCount, ST_ORDER, ORDERBY_ASE);
- FindShunZI(OneCardArray, OneCardCount, cbCount, vShunNoJoker);
- if (vShunNoJoker.size()>0)
- {
- vector<vector<BYTE>>::iterator oneSt = vShunNoJoker.begin();
- for (; oneSt != vShunNoJoker.end(); oneSt++)
- {
- HitStruct hit;
- hit.cbCardCount = cbCount;
- hit.cbCardType = CT_BOMB_LINK;
- for (int i = 0; i < hit.cbCardCount; i++)
- {
- for (int j = 1; j <= BomoInfo.tong;j++)
- {
- hit.cbHintLogicCardData[j*hit.cbCardCount - i - 1] = (*oneSt)[i];
- }
-
- }
- hit.cbCardCount = cbCount * BomoInfo.tong;
- SortCardList(hit.cbHintLogicCardData, hit.cbCardCount, ST_ORDER, ORDERBY_ASE);
- ListHit.push_back(hit);
- }
- }
- }
-
- BYTE CGameLogic_Poker::GetMagicJokerCount(const BYTE cbCardData[], BYTE cbCount,BYTE cbMagicCards[4])
- {
- BYTE MagicJokerCount = 0;
-
- for (int i = 0; i < cbCount;i++)
- {
- if (CardIsMagicJoker(cbCardData[i]))
- {
- cbMagicCards[MagicJokerCount++] = cbCardData[i];
- }
- }
-
- return MagicJokerCount;
- }
-
- BYTE CGameLogic_Poker::GetMagicJokerCount(tagDistributing tag, BYTE MagicCards[4])
- {
- BYTE MagicType = GetMagicType();
- //BYTE nCount = tag.cbDistributing[13][5] + tag.cbDistributing[14][5];
- BYTE magicCount = 0;
- if (MagicType==OneMagicMode)
- {
- for (int i = 0; i < tag.cbDistributing[14][5]; i++)
- {
-
- MagicCards[magicCount++] = 0x4f;
- }
- }
- if (MagicType==TwoMagicMode)
- {
- for (int i = 0; i < tag.cbDistributing[13][5]; i++)
- {
-
- MagicCards[magicCount++] = 0x4e;
- }
- for (int i = 0; i < tag.cbDistributing[14][5]; i++)
- {
-
- MagicCards[magicCount++] = 0x4f;
- }
- }
-
- return magicCount;
- }
-
- BOOL CGameLogic_Poker::CardIsMagicJoker(BYTE cbCard)
- {
- BYTE MagicType= GetMagicType();
- if (MagicType==OneMagicMode)
- {
- if (cbCard==0x4f)
- {
- return TRUE;
- }
- }
- else if (MagicType==TwoMagicMode)
- {
- if (cbCard==0x4e ||cbCard==0x4f)
- {
- return TRUE;
- }
- }
- return FALSE;
- }
-
- BOOL CGameLogic_Poker::FindSameXianBomo(const BYTE cbCardData[], BYTE cbCount, BomoType bomoinfo, tagDistributing tagDsit, std::vector<HitStruct> &ListHit)
- {
-
- int BomoIndex = 0;
- if (bomoinfo.BomoTypes == 0)
- {
- BYTE cbLogicCardValue = GetCardLogicValue(cbCardData[0]);
- BomoIndex = cbLogicCardValue - 3 + 1;
- }
-
- //5线 正规5张一样的
-
- for (BYTE i = BomoIndex; i < 13; i++)
- {
- BYTE cbCardCount = tagDsit.cbDistributing[i][5];
- if (cbCardCount == 5)
- {
- HitStruct st;
- st.cbCardCount = cbCardCount;
- st.cbCardType = CT_BOMB;
- for (int j = 0; j < cbCardCount; j++)
- {
- st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
- }
- ListHit.push_back(st);
- }
-
- }
- return TRUE;
- }
-
- BOOL CGameLogic_Poker::FindSameXianBomoWithJoker(const BYTE cbCardData[], BYTE cbCount,BYTE xian, BYTE type, BomoType bomoinfo, tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, std::vector<HitStruct> &ListHit)
- {
-
- BYTE cbCards[4] = { 0 };
- BYTE nMagicCount = GetMagicJokerCount(tagDsit, cbCards);
- for (int i = 0; i < 11;i++)
- {
- for (int j = 0; j < 27;j++)
- {
- if (tagReslt.cbCardData[i][j]==0x4e||tagReslt.cbCardData[i][j]==0x4f)
- {
- tagReslt.cbCardData[i][j] = 0;
- }
- }
- BYTE cbTmpCardData[MAX_COUNT_Poker] = { 0 };
- BYTE cbTmpCardCount = 0;
- for (int CarCount = 0; CarCount < 27; CarCount++)
- {
- if (tagReslt.cbCardData[i][CarCount] != 0)
- {
- cbTmpCardData[cbTmpCardCount++] = tagReslt.cbCardData[i][CarCount];
-
- }
- }
- if (cbTmpCardCount > 0)
- {
- ZeroMemory(tagReslt.cbCardData[i], MAX_COUNT_Poker);
- memcpy(tagReslt.cbCardData[i], cbTmpCardData, cbTmpCardCount);
- }
- }
- //带王的 五张
- BYTE cbMaxCardCount = xian;
- for (BYTE CurrentMagicCount = 1; CurrentMagicCount <= nMagicCount; CurrentMagicCount++)
- {
- byte cbFinSameCount = cbMaxCardCount - CurrentMagicCount;
- //4张同牌的 一共有多少
- BYTE cbZuHeCount = tagReslt.cbBlockCount[cbFinSameCount - 1];
- for (int OneCard = 0; OneCard < cbZuHeCount; OneCard++)
- {
- if (type == CT_BOMB)
- {
- BYTE cbCard = GetCardLogicValue(tagReslt.cbCardData[cbFinSameCount - 1][OneCard * cbFinSameCount]);
- BYTE LastCard = GetCardLogicValue(cbCardData[0]);
- if (cbCard < LastCard)
- {
- continue;
- }
- }
- HitStruct st;
- st.cbCardCount = cbMaxCardCount;
- st.cbCardType = CT_BOMB;
- for (int j = 0; j < cbMaxCardCount - CurrentMagicCount; j++)
- {
- st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(GetCardLogicValue(tagReslt.cbCardData[cbFinSameCount - 1][OneCard * cbFinSameCount + j]));
- }
- for (int j = 1; j <= CurrentMagicCount; j++)
- {
- st.cbHintLogicCardData[cbMaxCardCount - j] = TagIndexToNoColorCardValue(GetCardLogicValue(cbCards[j - 1]));
- }
- ListHit.push_back(st);
- }
-
- }
- return TRUE;
- }
-
- BOOL CGameLogic_Poker::Find4Fu4xian(const BYTE cbCardData[], BYTE cbCount, BYTE xian, BYTE type, BomoType bomoinfo, tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, std::vector<HitStruct> &ListHit)
- {
- //5线 正规 4付4线
- BYTE cbMaxCardLogicValue = 0;
- if (bomoinfo.BomoTypes == BomoTypeXian)
- {
- //要比较我方是否有比对方最大值还大的 线牌
- cbMaxCardLogicValue = GetMaxLogicValue(cbCardData,cbCount);
- }
- //保存无花色 牌的逻辑值
- BYTE cbBomoCards[16] = { 0 };
- BYTE cbBomoCardCount = 0;
- for (BYTE i = 0; i < 13; i++)
- {
- BYTE cbCardCount = tagDsit.cbDistributing[i][5];
- if (cbCardCount >= 4)
- {
- cbBomoCards[cbBomoCardCount++] = TagIndexToNoColorCardValue(i + 3);;
- }
- }
- //进行排列组合
- if (cbMaxCardLogicValue!=0)
- {
- BOOL bFind = FALSE;//是否有比上家4f4线大的牌
- for (int i = 0; i < 16; i++ )
- {
- if (cbBomoCards[i]==0)
- {
- break;
- }
- if (cbBomoCards[i]>cbMaxCardLogicValue)
- {
- bFind = TRUE;
- break;
- }
- }
- if (bFind==FALSE)
- {
- return FALSE;
- }
- //现在比上次最大的牌大的 有了。
- vector<vector<BYTE>> allHits = CardSecret(cbBomoCards, cbBomoCardCount, 4, cbMaxCardLogicValue);
-
- vector<vector<BYTE>>::iterator it = allHits.begin();
-
- for (it; it!=allHits.end();it++)
- {
- HitStruct st;
- st.cbCardCount = 4 * 4;
- st.cbCardType = CT_BOMB_XIAN;
- BYTE CardIndex = 0;
- vector<BYTE>::iterator OneValue = it->begin();
- for (; OneValue != it->end(); OneValue++)
- {
-
- //将4个值赋值到st中
- for (BYTE index = 0; index < 4; index++)
- {
- st.cbHintLogicCardData[CardIndex * 4 + index] = *OneValue;
- }
- CardIndex++;
- }
- //不是连排 可以加入 连排 让后面的处理 不属于5线
- if (IsStructureLink(st.cbHintLogicCardData, st.cbCardCount, 4) == FALSE)
- {
- ListHit.push_back(st);
- }
- }
-
- }
- return TRUE;
- }
- //根据手牌
- BOOL CGameLogic_Poker::Find4Fu4xianWithJoker(const BYTE cbCardData[], BYTE cbCount, BYTE xian, BYTE type, BomoType bomoinfo, tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, std::vector<HitStruct> &ListHit)
- {
- BYTE FindFu = 4;
- BYTE cbMagicData[4] = { 0 };
- BYTE cbMaxMagicCount = GetMagicJokerCount(tagDsit, cbMagicData);
- BYTE cbMaxCardLogicValue = 0;
- if (bomoinfo.BomoTypes!=0)
- {
- cbMaxCardLogicValue = GetMaxLogicValue(cbCardData, cbCount);
- }
- if (tagDsit.cbCardCount<16)
- {
- return FALSE;
- }
- // 取消掉0张牌的。
- BYTE cbIndex[MAX_COUNT_Poker] = { 0 };
- BYTE cbIndexCount = 0;
- for (int i = 0; i < 13;i++)
- {
- if (tagDsit.cbDistributing[i][5]==0)
- {
- continue;
- }
- cbIndex[cbIndexCount++] = i;
- }
- //然后所有牌进行4张的排列组合。
- vector<vector<BYTE>> AllHitsIndex = CardSecret(cbIndex, cbIndexCount, 4, 0);
- //写一个函数 查看其4种牌的组合+王 是否能够组成4付4线
- //oneHitIndex(vector<BYTE> vIndex,tagDistributing tagDsit,std::vector<HitStruct> &ListHit);
- vector<vector<BYTE>>::iterator OneItem = AllHitsIndex.begin();
- for (; OneItem != AllHitsIndex.end();OneItem++)
- {
- if (cbCount==5)
- {
- BOOL bCanNext = FALSE;
- //判定4付4线中最大的牌 是否大于当前玩家的牌
- BYTE CbCard = cbCardData[0];
- BYTE CardLogicValue = GetCardLogicValue(CbCard);
- for (int i = 0; i < 4; i++){
- if ((*OneItem)[i] + 3>CardLogicValue)
- {
- bCanNext = TRUE;
- break;
- }
- }
- if (bCanNext==FALSE)
- {
- continue;
-
- }
- }
- //组合后 将牌大于4张的变为4张。
- //然后根据每个组合确认癞子牌是否足够
- //足够的 将癞子牌替换之
- CanZuCheng44(*OneItem, tagDsit, ListHit);
- }
-
-
-
- return TRUE;
- }
- BOOL CGameLogic_Poker::CanZuCheng44(vector<BYTE> vIndex, tagDistributing tagDsitA, std::vector<HitStruct> &ListHit)
- {
- tagDistributing tagDsit ;
- CopyMemory(&tagDsit, &tagDsitA, sizeof(tagDistributing));
- int nCont = vIndex.size();
- int nAllCardCount=0;
- for (int i = 0; i < nCont;i++)
- {
- int nTmpCount = tagDsit.cbDistributing[vIndex[i]][5];
- if (nTmpCount>=4)
- {
- nTmpCount = 4;
- }
- nAllCardCount += nTmpCount;
- }
- if (nAllCardCount==16)
- {
- //无需癞子的 忽略
- return TRUE;
- }
- if (GetMagicType()==MagicMode::NoHaveMagic)
- {
- return FALSE;
- }
- int AllMagicCount = 0;
- for (int i = 0; i < 2;i++)
- {
- int nTmpCount = tagDsit.cbDistributing[13+i][5];
- AllMagicCount += nTmpCount;
- }
- if (nAllCardCount + AllMagicCount<16)
- {
- return FALSE;
- }
- //
- HitStruct st;
- st.cbCardCount = 16;
- st.cbCardType = CT_BOMB_XIAN;
- int cbCardCountIndex = 0;
- int MagicCount = 0;
- for (size_t i = 0; i < 4; i++)
- {
- int nTmpCount = tagDsit.cbDistributing[vIndex[i]][5];
- if (nTmpCount>4)
- {
- nTmpCount = 4;
- }
- for (int count = 0; count < nTmpCount; count++)
- {
- st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(vIndex[i] + 3);
- }
- if (nTmpCount<4)
- {
- //用王填充
- int Need = 4 - nTmpCount;
- INT xJoker = tagDsit.cbDistributing[13][5];
- if (xJoker>0)
- {
- if (xJoker>=Need)
- {
- for (int j = 0; j < Need; j++)
- {
- st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(16);//小王
- tagDsit.cbDistributing[13][5]--;
- }
- }
- else
- {
- for (int j = 0; j < xJoker; j++)
- {
- st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(16);//小王
- tagDsit.cbDistributing[13][5]--;
- }
- Need = Need - xJoker;
- INT DJoker = tagDsit.cbDistributing[15][5];
- if (DJoker>=Need)
- {
- for (int j = 0; j < Need; j++)
- {
- st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(17);//大王
- tagDsit.cbDistributing[14][5]--;
- }
- }
- else{
- for (int j = 0; j < xJoker; j++)
- {
- st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(17);//大王
- tagDsit.cbDistributing[14][5]--;
- }
- }
- }
- }
- else
- {
- //没有小王
- INT DJoker = tagDsit.cbDistributing[15][5];
- for (int j = 0; j < Need; j++)
- {
- st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(17);//大王
- tagDsit.cbDistributing[14][5]--;
- }
- }
-
- }
-
- }
- ListHit.push_back(st);
- return TRUE;
- }
-
- BOOL CGameLogic_Poker::Find3WBomo(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType BomoInfo, tagDistributing tag, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- if (GetMagicType() == MagicMode::NoHaveMagic)
- {
- return FALSE;
- }
- if (BomoInfo.Level < 6)
- {
- //查找3W炸弹
- BYTE cbMagicCards[4] = { 0 };
- BYTE nCount = GetMagicJokerCount(tag, cbMagicCards);
- if (nCount < 3)
- {
- return FALSE;
- }
- HitStruct st;
- st.cbCardCount = 3;
- st.cbCardType = CT_BOMB_3W;
- for (int i = 0; i < 3; i++)
- {
- st.cbHintLogicCardData[i] = TagIndexToNoColorCardValue(GetCardLogicValue(cbMagicCards[i]));
- }
- ListHit.push_back(st);
- }
-
- }
-
- BOOL CGameLogic_Poker::Find4WBomo(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType BomoInfo, tagDistributing tag, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- BYTE MagicType = GetMagicType();
- BYTE cbMagicCards[4] = { 0 };
- BYTE nCount=0;// = GetMagicJokerCount(tag, cbMagicCards);
- for (int i = 0; i < cbUserCount;i++)
- {
- if (UserCards[i]==0x4e||UserCards[i]==0x4f)
- {
-
- cbMagicCards[nCount++] = UserCards[i];
- }
- }
- if (nCount!=4)
- {
- return FALSE;
- }
- if (MagicType == MagicMode::NoHaveMagic)
- {
- HitStruct st;
- st.cbCardCount = 4;
- st.cbCardType = CT_BOMB_TW;
- for (int i = 0; i < 4; i++)
- {
- st.cbHintLogicCardData[i] = TagIndexToNoColorCardValue(GetCardLogicValue(cbMagicCards[i]));
- }
- ListHit.push_back(st);
- }
- else
- {
- if (BomoInfo.Level < 8)
- {
- HitStruct st;
- st.cbCardCount = 4;
- st.cbCardType = CT_BOMB_TW;
- for (int i = 0; i < 4; i++)
- {
- st.cbHintLogicCardData[i] = TagIndexToNoColorCardValue(GetCardLogicValue(cbMagicCards[i]));
- }
- ListHit.push_back(st);
- }
- }
-
- }
-
- BOOL CGameLogic_Poker::FindAllHit(const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- tagAnalyseResult_Poker tagResult;
- AnalysebCardData(UserCards, cbUserCount, tagResult);
- for (int i = 1; i < 8;i++)
- {
- byte CardCount = tagResult.cbBlockCount[i - 1];
- if (CardCount==0)
- {
- continue;
- }
- if (i>=4)
- {
- if (ListHit.size()>0)
- {
- break;
- }
- }
- for (int cbCount = 1; cbCount <= CardCount;cbCount++)
- {
- HitStruct hit;
- hit.cbCardCount = i;
- switch (hit.cbCardCount)
- {
- case 1:
- hit.cbCardType = CT_SINGLE;
- break;
- case 2:
- hit.cbCardType = CT_DOUBLE;
- break;
- case 3:
- hit.cbCardType = CT_THREE;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- hit.cbCardType = CT_BOMB;
- break;
- default:
- break;
- }
- for (BYTE cbCardIndex = 0; cbCardIndex < hit.cbCardCount;cbCardIndex++)
- {
- hit.cbHintLogicCardData[cbCardIndex] = TagIndexToNoColorCardValue(GetCardLogicValue(tagResult.cbCardData[i - 1][(cbCount - 1)*i + cbCardIndex]));
-
- }
- ListHit.push_back(hit);
- }
-
- }
- return 0;
- }
-
- int CGameLogic_Poker::rand9xianInfo(BomoType &info)
- {
- //5付5线等同9线;4线5连等同9线;3付6线等同9线,5线3连等同9线
- int Bomo = 0;
- int nType = rand() % 3;
- switch (nType){
- case 0:{
-
- info.Level = 9;
- info.BomoTypes = BomoTypeXian;
- info.fu = 5;
- info.xian = 5;
- Bomo = TRUE;
- break;
- }
- case 1:{
- info.Level = 9;
- info.BomoTypes = BomoTypeLian;
- info.tong = 4;
- info.lian = 5;
- Bomo = 1;
- break;
- }
- case 2:{
- Bomo = 2;
- break;
- }
- }
- return Bomo;
- }
-
-
- BOOL CGameLogic_Poker::bFind9xianCards(vector<vector<BYTE>> &AllCards, BYTE cbCardBuffer[], BYTE &cbBufferCount, BomoType& Bomo, BOOL isXian)
- {
- if (isXian)
- {
- int XianCount = 0;
- vector<BYTE> vCardIndexs;
- for (BYTE i = 0; i < AllCards.size(); i++)
- {
- if (AllCards[i].size()>=Bomo.xian)
- {
- XianCount++;
- vCardIndexs.push_back(i);
- }
- }
- if (XianCount<Bomo.fu)
- {
- return FALSE;
- }
- for (int nFu = 0; nFu < Bomo.fu; nFu++)
- {
- BYTE cbCardIndex = RandIndexAndDelIt(vCardIndexs);
- for (int nXian = 0; nXian < Bomo.xian; nXian++){
- cbCardBuffer[cbBufferCount++] = AllCards[cbCardIndex][0];
- AllCards[cbCardIndex].erase(AllCards[cbCardIndex].begin());
- }
- }
- return TRUE;
-
- }
- else
- {
- //随机一个数据 判断从这个值开始连续M连 是否可行,可行继续 不可行 忽略。
- BYTE cbStartIndex = rand() % 7;
- for (BYTE i = cbStartIndex; i < AllCards.size(); i++)
- {
- if (i>=13)
- {
- continue;
- }
- if (AllCards[i].size()<Bomo.tong)
- {
- return FALSE;
- }
- }
- for (int nLian = 0; nLian < Bomo.lian;nLian++)
- {
- for (int nTong = 0; nTong < Bomo.tong; nTong++)
- {
- cbCardBuffer[cbBufferCount++] = AllCards[cbStartIndex + nLian][0];
- AllCards[cbStartIndex + nLian].erase(AllCards[cbStartIndex + nLian].begin());
- }
- }
-
- return TRUE;
- }
- }
-
- BYTE CGameLogic_Poker::RandIndexAndDelIt(vector<BYTE>& CardIndex)
- {
- BYTE cbIndex = rand() % CardIndex.size();
- BYTE cbCardIndex = CardIndex[cbIndex];
- CardIndex.erase(CardIndex.begin()+cbIndex);
- return cbCardIndex;
- }
-
- BOOL CGameLogic_Poker::FindNFuMxian(const BYTE cbCardData[], BYTE cbCount, BYTE Fu, BYTE xian, BYTE type, BomoType bomoinfo, tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, std::vector<HitStruct> &ListHit)
- {
- // 正规 N付M线
- BYTE cbMaxCardLogicValue = 0;
- if (bomoinfo.BomoTypes == BomoTypeXian)
- {
- //要比较我方是否有比对方最大值还大的 线牌
- cbMaxCardLogicValue = GetMaxLogicValue(cbCardData, cbCount);
- }
- //保存无花色 牌的逻辑值
- BYTE cbBomoCards[16] = { 0 };
- BYTE cbBomoCardCount = 0;
- for (BYTE i = 0; i < 13; i++)
- {
- BYTE cbCardCount = tagDsit.cbDistributing[i][5];
- if (cbCardCount >= xian)
- {
- cbBomoCards[cbBomoCardCount++] = TagIndexToNoColorCardValue(i + 3);;
- }
- }
- //进行排列组合
- if (cbMaxCardLogicValue != 0)
- {
- BOOL bFind = FALSE;//是否有比上家4f4线大的牌
- for (int i = 0; i < 16; i++)
- {
- if (cbBomoCards[i] == 0)
- {
- break;
- }
- if (cbBomoCards[i] > cbMaxCardLogicValue)
- {
- bFind = TRUE;
- break;
- }
- }
- if (bFind == FALSE)
- {
- return FALSE;
- }
- //现在比上次最大的牌大的 有了。
- vector<vector<BYTE>> allHits = CardSecret(cbBomoCards, cbBomoCardCount, xian, cbMaxCardLogicValue);
-
- vector<vector<BYTE>>::iterator it = allHits.begin();
-
- for (it; it != allHits.end(); it++)
- {
- HitStruct st;
- st.cbCardCount = Fu * xian;
- st.cbCardType = CT_BOMB_XIAN;
- BYTE CardIndex = 0;
- vector<BYTE>::iterator OneValue = it->begin();
- for (; OneValue != it->end(); OneValue++)
- {
-
- //将4个值赋值到st中
- for (BYTE index = 0; index < xian; index++)
- {
- st.cbHintLogicCardData[CardIndex * Fu + index] = *OneValue;
- }
- CardIndex++;
- }
- //不是连排 可以加入 连排 让后面的处理 不属于5线
- if (IsStructureLink(st.cbHintLogicCardData, st.cbCardCount, xian) == FALSE)
- {
- ListHit.push_back(st);
- }
- }
-
- }
- return TRUE;
- }
-
- BOOL CGameLogic_Poker::FindAll5XianBomo(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType bomoinfo, tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, std::vector<HitStruct> &ListHit, const BYTE cbUserCardData[], BYTE cbUserCount)
- {
- // if (cbCount==5)
- // {
- // //正规5相炸弹
- // FindSameXianBomo(cbCardData, cbCount, bomoinfo, tagDsit, ListHit);
- // }
- //FindNFuMxian(cbCardData, cbCount, 4, 4, type, bomoinfo, tagDsit, tagReslt, ListHit);
- if (cbCount==5)
- {
- HintSameCardCount(cbCardData, cbCount, 5, cbUserCardData, cbUserCount, ListHit, TRUE);
- }
- //带王的 4付4线
- //Find4Fu4xianWithJoker(cbCardData, cbCount, 4, type, bomoinfo, tagDsit, tagReslt, ListHit);
-
-
- return TRUE;
- }
-
- void CGameLogic_Poker::FindShunZI(const BYTE cbCardData[], BYTE bCount, BYTE nFindCount, vector<vector<BYTE>>& result)
- {
- //4 5 6 7 8 9 10
- for (int index = 0; index <= bCount - nFindCount; index++)
- {
- BOOL isShun = IsStructureLink_zhengxu(&cbCardData[index], nFindCount, 1);
- if (isShun)
- {
- vector<BYTE> vCards;
- for (int i = 0; i < nFindCount;i++)
- {
- vCards.push_back(cbCardData[index+i]);
-
- }
- result.push_back(vCards);
- }
- }
-
-
- }
-
-
- BOOL CGameLogic_Poker::HintShunWithJoker(const BYTE cbCardData[], BYTE cbCount, BYTE type, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
- {
- BYTE tmpCardData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(tmpCardData, cbCardData, cbCount);
- SortCardList(tmpCardData, cbCount, ST_ORDER, ORDERBY_ASE);
- tagDistributing tag;
- AnalysebDistributing(UserCards, cbUserCount, tag);
- BYTE LianCount = 0;
- BYTE TypeCount;
- BYTE MinCard = GetCardLogicValue(tmpCardData[0]);
- BYTE cbMagic[4] = { 0 };
- int MagicCount = GetMagicJokerCount(tag, cbMagic);
- if (MagicCount==0)
- {
- return 0;
- }
- switch (type)
- {
- case CT_SHUNZI:
- LianCount = cbCount;
- TypeCount = 1;
- break;
- case CT_DOUBLE_LINK:
- LianCount = cbCount/2;
- TypeCount = 2;
- break;
- case CT_THREE_LINK:
- LianCount = cbCount/3;
- TypeCount = 3;
- break;
- default:
- break;
- }
- int nStartIndex = MinCard - 3 + 1;
- int MaxIndex = 12 - LianCount;
- for (int StartIndex = nStartIndex; StartIndex <= MaxIndex; StartIndex++)
- {
- BYTE cbReplacCards[MAX_COUNT_Poker] = { 0 }; //替换后的牌值 有王 用于给前端
- memset(cbReplacCards, 0xff, MAX_COUNT_Poker);
- BYTE cbReplacdCardsNoJoker[MAX_COUNT_Poker] = { 0 };//替换后的牌值 无王
- BYTE NeedMagcCount = CalcuTagDistStructureLinkNeedMagicCount(tag, StartIndex, LianCount, TypeCount, cbReplacCards, cbReplacdCardsNoJoker);
- if (NeedMagcCount<=MagicCount)
- {
- HitStruct ST;
- ST.cbCardCount = cbCount;
- ST.cbCardType = type;
- BYTE cbReplacCardCount = 0;
-
- for (BYTE reIndex = 0; reIndex < ST.cbCardCount; reIndex++)
- {
- if (cbReplacCards[reIndex] == 255)
- {
- cbReplacCards[reIndex] =GetCardLogicValue(cbMagic[cbReplacCardCount++]);
- }
- }
- for (int i = 0; i < MAX_COUNT_Poker; i++)
- {
- if (cbReplacCards[i]==255)
- {
- break;
- }
- ST.cbHintLogicCardData[i] = cbReplacCards[i];
- }
- if (IsStructureLink_zhengxu(cbReplacdCardsNoJoker, ST.cbCardCount, TypeCount))
- {
- ListHit.push_back(ST);
- }
-
-
- }
- }
-
-
- return TRUE;
- }
- //计算连对 需要magic 个数
- BYTE CGameLogic_Poker::CalcuTagDistStructureLinkNeedMagicCount(tagDistributing tag, BYTE tagIndex, BYTE LianCount, BYTE TypeCount, BYTE cbOutCards[MAX_COUNT_Poker], BYTE cbOutCardsNoJoker[MAX_COUNT_Poker])
- {
- BYTE cbTmpCards[MAX_COUNT_Poker] = { 0 };
- BYTE cbTmpCardCount=0;
- BYTE NeedMagicCount = 0;
- for (BYTE Count = 0; Count < LianCount;Count++)
- {
- BYTE curCardCount = tag.cbDistributing[tagIndex + Count][5];
- if (curCardCount >= TypeCount)
- {
- for (BYTE cardIndex = 0; cardIndex < TypeCount; cardIndex++)
- {
- cbOutCards[Count*TypeCount + cardIndex] = TagIndexToNoColorCardValue(tagIndex + Count + 3);
- cbOutCardsNoJoker[Count*TypeCount + cardIndex]=TagIndexToNoColorCardValue(tagIndex + Count + 3);
- }
- }
- else
- {
- //cbOutCards 里面包含王
- //cbOutCardsNoJoker 无王
- BYTE tmpNeedMagic = TypeCount - curCardCount;
- NeedMagicCount += tmpNeedMagic;
- for (BYTE cardIndex = 0; cardIndex < TypeCount; cardIndex++)
- {
- cbOutCardsNoJoker[Count*TypeCount + cardIndex] = TagIndexToNoColorCardValue(tagIndex + Count + 3);
- }
- for (BYTE cardIndex = 0; cardIndex < TypeCount - tmpNeedMagic; cardIndex++)
- {
- BYTE cbIndex = tagIndex + Count + 3;
- cbOutCards[Count*TypeCount + cardIndex] = TagIndexToNoColorCardValue(cbIndex);
-
- }
- }
- }
- return NeedMagicCount;
- }
-
-
-
-
- BYTE CGameLogic_Poker::FindAllPaiBomoCards(tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, LastCardsInfo stLastCardsInfo, std::vector<HitStruct> &ListHit)
- {
- //3-A 排序前的准备
- BYTE cbAllCardIndex[12] = { 0 };
- for (BYTE i = 0; i < 12;i++)
- {
- cbAllCardIndex[i] = i;
- }
- BYTE cbNotSameCardCount[] = { 3, 4, 5 ,6};
- BYTE cbStartSameCont[] = { 4, 4, 5 ,4};
- BYTE cbSameMaxCount[] = { 9, 6, 5 ,4};
- vector<BomoType> BomoInfos;
- for (int nNotCard = 0; nNotCard < 4;nNotCard++)
- {
- //分析所有不同牌的组合 是否满足 某线某连/ 某付某线
- for (int nStartSameCardCount = cbStartSameCont[nNotCard]; nStartSameCardCount <= cbSameMaxCount[nNotCard];nStartSameCardCount++)
- {
- //n TONG =nStartSameCardCount
- //m NotTong = cbNotSameCardCount[nNotCard]
- vector<vector<BYTE>> resultAll;
- vector<BYTE> tmpVec;
- CardPerm(cbAllCardIndex, 12, cbNotSameCardCount[nNotCard], tmpVec,resultAll, 0);
- //resultAll 中保存了 所有不通牌的 组合 index
- //函数功能 确定这个索引对应的牌 是否可以组成特殊牌,是否能够加入到提示列表
-
- vector<vector<BYTE>>::iterator OneIndex = resultAll.begin();
- for (; OneIndex != resultAll.end();OneIndex++)
- {
- FromIndexToHitList(*OneIndex, nStartSameCardCount,tagDsit, stLastCardsInfo, ListHit);
- }
- }
- }
- return FALSE;
- }
-
- std::vector<std::vector<BYTE>> CGameLogic_Poker::CardSecret(const BYTE Cards[], BYTE cbCount, int nLen,BYTE LastMaxCard)
- {
- {
- vector<vector<BYTE>> strVect;
-
- if (cbCount == 0 || nLen > cbCount) //返回一个空表
- return strVect;
-
- vector<BYTE> chVect;
- CardPerm(Cards, cbCount, nLen, chVect, strVect, LastMaxCard);
- return strVect;
- }
- }
-
- void CGameLogic_Poker::CardPerm(const BYTE str[], BYTE strCount, int nLen, vector<BYTE>& ve, vector<vector<BYTE>>& result, BYTE LastMaxCard)
- {
- {
-
- if (nLen == 0) //已经找到一个全排列的组合,而且这个组合就在ve中
- {
- vector<BYTE> st;
- vector<BYTE>::iterator it = ve.begin();
- for (; it != ve.end(); it++)
- {
- st.push_back(*it);
- }
- //如果最大值 比某个值小 则 不进入
- sort(st.begin(), st.end());
- if (st[st.size()-1]<LastMaxCard)
- {
- return;
- }
- result.push_back(st); //找到了一种组合,将它保存在动态数组中
- return;
- }
- if (strCount == 0)
- return;
-
- ve.push_back(str[0]);
- CardPerm(str + 1, strCount - 1, nLen - 1, ve, result, LastMaxCard);
- //递归从这里出来的条件只有两种,
- //要么str为空了, 说明当前已经遍历一遍字符串,
- //要么nLen为0了,说明已经找到了一种组合
-
- ve.pop_back(); //此时要将最后一个字符出栈,然后遍历下一个字符
-
- CardPerm(str + 1, strCount - 1, nLen, ve, result, LastMaxCard);
-
- }
- }
- //计算 带癞子 和不带癞子的情况
- BOOL CGameLogic_Poker::FromIndexToHitList(vector<BYTE> cbCardIndexFormTag, BYTE nTongCardCount, tagDistributing tagDsit, LastCardsInfo stLastCardsInfo, std::vector<HitStruct> &ListHit)
- {
- //计算不带癞子的情况
- BYTE mNotSameCount = cbCardIndexFormTag.size();
-
- BYTE cbNeedCount=mNotSameCount*nTongCardCount;
- BYTE CurrentCount = 0;
- BYTE cbBomoCardData[MAX_COUNT_Poker] = { 0 };
- BYTE cbBomoCardCount = 0;
- BYTE cbMagicReplaceCardNotColorCardValue[MAX_COUNT_Poker] = { 0 };
- BYTE cbReplaceCount=0;
- //牌数不够 用癞子凑
- BYTE cbMagicData[4] = { 0 };
-
- BYTE cbMagicCardCont = GetMagicJokerCount(tagDsit, cbMagicData);
-
- for (int i = 0; i < cbCardIndexFormTag.size();i++)
- {
- int TmpCount = tagDsit.cbDistributing[cbCardIndexFormTag[i]][5];
- if (TmpCount >= nTongCardCount)
- {
- CurrentCount += nTongCardCount;
- for (int CopyDataIndex = 0; CopyDataIndex < nTongCardCount; CopyDataIndex++)
- {
- cbBomoCardData[cbBomoCardCount++] = TagIndexToNoColorCardValue(cbCardIndexFormTag[i] + 3);
- }
- }
- else
- {
- CurrentCount += TmpCount;
- if (cbMagicCardCont>0)
- {
- //此时 不够的牌用FF 代替
- for (int CopyDataIndex = 0; CopyDataIndex <TmpCount; CopyDataIndex++)
- {
- cbBomoCardData[cbBomoCardCount++] = TagIndexToNoColorCardValue(cbCardIndexFormTag[i] + 3);
- }
- cbMagicReplaceCardNotColorCardValue[cbReplaceCount] = TagIndexToNoColorCardValue(cbCardIndexFormTag[i] + 3);
- for (int CopyDataIndex = TmpCount; CopyDataIndex < nTongCardCount; CopyDataIndex++)
- {
- cbBomoCardData[cbBomoCardCount++] = GetCardLogicValue(cbMagicData[cbReplaceCount]);
- }
- cbReplaceCount++;
- }
-
- }
-
- }
-
- //不带癞子可以组成的话 就不用计算癞子了组合了,由其他组合计算。
- if (CurrentCount==cbNeedCount)
- {
- //不用癞子就可以组成
- //可以根据牌值 组成2中
-
- /*
- 【1】 NotSameCount付nTongCardCont 线
- 【2】 nTongCardCount现 NotSameCount 连
- */
- BYTE cbLevel = 0;
- BomoType BomoInfo;
- BYTE type= GetCardType(cbBomoCardData, cbBomoCardCount, cbLevel, BomoInfo);
-
- if (type != CT_BOMB_LINK&& type != CT_BOMB_XIAN)
- {
- return FALSE;
- }
- //比较2付牌的 大小 不考虑王的情况
- // 如果当前线级 小于上家的 则放弃
- if (stLastCardsInfo.BomoInfo.Level>BomoInfo.Level)
- {
- return FALSE;
- }
- if (stLastCardsInfo.BomoInfo.Level==BomoInfo.Level)
- {
-
- //如果线级相同 按照牌的数量比较
- //数量少的大于属相大的
- if (stLastCardsInfo.cbCardCount<BomoInfo.CbBomoCount)
- {
- return FALSE;
- }
-
- if (stLastCardsInfo.cbCardCount>BomoInfo.CbBomoCount)
- {
- HitStruct st;
- st.cbCardCount = cbBomoCardCount;
- CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
- st.cbCardType = BomoInfo.BomoTypes;
- ListHit.push_back(st);
- return TRUE;
- }
- if (stLastCardsInfo.cbCardCount==BomoInfo.CbBomoCount)
- {
- //如果数量相同 则按照最大牌比较
- BYTE cbMaxLogicCard = GetMaxLogicValue(stLastCardsInfo.cbCards, stLastCardsInfo.cbCardCount);
-
- BYTE cbCurrentMaxLogicCard = GetMaxLogicValue(cbBomoCardData, cbBomoCardCount);
-
- if (cbMaxLogicCard >= cbCurrentMaxLogicCard)
- {
- return FALSE;
- }
-
- HitStruct st;
- st.cbCardCount = cbBomoCardCount;
- CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
- st.cbCardType = BomoInfo.BomoTypes;
- ListHit.push_back(st);
- }
-
- }
-
- if (stLastCardsInfo.BomoInfo.Level < BomoInfo.Level)
- {
- HitStruct st;
- st.cbCardCount = cbBomoCardCount;
- CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
- st.cbCardType = BomoInfo.BomoTypes;
- ListHit.push_back(st);
- }
-
- }
- else
- {
-
-
- if (CurrentCount + cbMagicCardCont<cbNeedCount)
- {
- return FALSE;
- }
-
- //cbBomoCardData 里面存的是替换了王的牌
-
- BYTE cbNoHaveJokerData[MAX_COUNT_Poker] = { 0 };
- CopyMemory(cbNoHaveJokerData, cbBomoCardData, cbBomoCardCount);
-
- //把王替换成 对应的牌 然后计算是否 能够大于上一家
- BYTE RelpaceCount = 0;
- for (int i = 0; i < cbBomoCardCount; i++)
- {
- if (cbNoHaveJokerData[i] == 0)
- {
- break;
- }
- if (cbNoHaveJokerData[i] == GetCardLogicValue(0x4e) || cbNoHaveJokerData[i] == GetCardLogicValue(0x4f))
- {
- cbNoHaveJokerData[i] = cbMagicReplaceCardNotColorCardValue[RelpaceCount++];
- }
- }
- BYTE cbLevel = 0;
- BomoType BomoInfo;
- BYTE type = GetCardType(cbNoHaveJokerData, cbBomoCardCount, cbLevel, BomoInfo);
-
- if (type != CT_BOMB_LINK&& type != CT_BOMB_XIAN)
- {
- return FALSE;
- }
- //比较2付牌的 大小 不考虑王的情况
- // 如果当前线级 小于上家的 则放弃
- if (stLastCardsInfo.BomoInfo.Level > BomoInfo.Level)
- {
- return FALSE;
- }
- if (stLastCardsInfo.BomoInfo.Level == BomoInfo.Level)
- {
- //如果线级相同 按照牌的数量比较
- if (stLastCardsInfo.cbCardCount < BomoInfo.CbBomoCount)
- {
- return FALSE;
- }
- if (stLastCardsInfo.cbCardCount > BomoInfo.CbBomoCount)
- {
- HitStruct st;
- st.cbCardCount = cbBomoCardCount;
- CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
- st.cbCardType = BomoInfo.BomoTypes;
- ListHit.push_back(st);
- return TRUE;
- }
- if (stLastCardsInfo.cbCardCount == BomoInfo.CbBomoCount)
- {
- //如果数量相同 则按照最大牌比较
- BYTE cbMaxLogicCard = GetMaxLogicValue(stLastCardsInfo.cbCards, stLastCardsInfo.cbCardCount);
-
- BYTE cbCurrentMaxLogicCard = GetMaxLogicValue(cbBomoCardData, cbBomoCardCount);
-
- if (cbMaxLogicCard >= cbCurrentMaxLogicCard)
- {
- return FALSE;
- }
-
- HitStruct st;
- st.cbCardCount = cbBomoCardCount;
- CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
- st.cbCardType = BomoInfo.BomoTypes;
- ListHit.push_back(st);
- }
-
- }
-
- if (stLastCardsInfo.BomoInfo.Level < BomoInfo.Level)
- {
- HitStruct st;
- st.cbCardCount = cbBomoCardCount;
- CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
- st.cbCardType = BomoInfo.BomoTypes;
- ListHit.push_back(st);
- }
- }
-
- return FALSE;
- }
- //检测 我的大于 last
- BOOL CGameLogic_Poker::CompareCardBigLastCards(BomoType lastUserBomoInfo, BYTE cbLastCards[], BYTE cbLastCardCount, BomoType MyBomoTypeFInfo, BYTE cbCards[], BYTE cbCardCount)
- {
- if (MyBomoTypeFInfo.Level>lastUserBomoInfo.Level)
- {
- return TRUE;
- }
- if (MyBomoTypeFInfo.Level < lastUserBomoInfo.Level)
- {
- return FALSE;
- }
- if (MyBomoTypeFInfo.Level==lastUserBomoInfo.Level)
- {
- if (MyBomoTypeFInfo.CbBomoCount<lastUserBomoInfo.CbBomoCount)
- {
- return TRUE;
- }
- if (MyBomoTypeFInfo.CbBomoCount > lastUserBomoInfo.CbBomoCount)
- {
- return FALSE;
- }
- if (MyBomoTypeFInfo.CbBomoCount == lastUserBomoInfo.CbBomoCount)
- {
- //如果数量相同 则按照最大牌比较
- //分别去2个牌的 最大值
- BYTE cbMaxLogicCard = GetMaxLogicValue(cbLastCards, cbLastCardCount);
-
- BYTE cbMyMaxLogicCard = GetMaxLogicValue(cbCards, cbCardCount);
- if (cbMyMaxLogicCard>cbMaxLogicCard)
- {
- return TRUE;
- }
- return FALSE;
-
- }
- }
-
-
- return FALSE;
- }
-
- BOOL CGameLogic_Poker::GetAllSameCards(BYTE StartLevel, std::vector<HitStruct> &ListHit, tagDistributing tagDsit)
- {
- for (int CardCount = StartLevel; CardCount <= 12; CardCount++)
- {
- for (int index = 0; index < 13; index++)
- {
- if (tagDsit.cbDistributing[index][5] == CardCount)
- {
- HitStruct st;
- st.cbCardCount = CardCount;
- st.cbCardType = CT_BOMB;
- CopyOneCardToArry(st.cbHintLogicCardData, st.cbCardCount, TagIndexToNoColorCardValue(index + 3));
- ListHit.push_back(st);
- }
- }
- }
-
- BYTE cbMagicCards[4] = { 0 };
- int MagicCount = GetMagicJokerCount(tagDsit, cbMagicCards);
- if (MagicCount==0)
- {
- return FALSE;
- }
- for (int CardCount = StartLevel; CardCount <= 12; CardCount++)
- {
- for (int index = 0; index < 13; index++)
- {
- byte curCount = tagDsit.cbDistributing[index][5];
- if (curCount < CardCount&&curCount + MagicCount >= CardCount)
- {
-
- HitStruct st;
-
- CopyOneCardToArry(st.cbHintLogicCardData, curCount, TagIndexToNoColorCardValue(index + 3));
- CopyJokerCardToArry(&st.cbHintLogicCardData[curCount], CardCount - curCount, cbMagicCards);
- st.cbCardCount = CardCount;
- st.cbCardType = CT_BOMB;
- ListHit.push_back(st);
- }
- }
- }
- return TRUE;
- }
-
- void CGameLogic_Poker::CopyOneCardToArry(BYTE cbDstCards[], BYTE CopyCount, BYTE cbCard)
- {
- for (int i = 0; i < CopyCount; i++){
- cbDstCards[i] = cbCard;
- }
- }
-
- void CGameLogic_Poker::CopyJokerCardToArry(BYTE cbDstCards[], BYTE cbCopyCount, BYTE cbJokerCards[4])
- {
- BYTE AddCount=0;
- for (int i = 0; i < cbCopyCount;i++)
- {
- if (cbJokerCards[AddCount]==0)
- {
- break;
- }
- cbDstCards[i] = GetCardLogicValue(cbJokerCards[AddCount++]);
- }
- }
-
- BOOL CGameLogic_Poker::NoJokerBigUserCards(BYTE TagIndex, BYTE cbCardCount, const BYTE cbUserCards[], BYTE cbcCount)
- {
- if (cbCardCount>cbcCount)
- {
- return TRUE;
- }
- if (cbCardCount==cbcCount)
- {
- BYTE LogicValue = GetCardLogicValue(TagIndex + 3);
- BYTE UserLogicCardValue = GetCardLogicValue(cbUserCards[0]);
- if (UserLogicCardValue<LogicValue)
- {
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
-
-
- void CGameLogic_Poker::SetBomoLevel(BomoType & BomoInfo)
- {
- if (BomoInfo.BomoTypes==BomoTypeXian)
- {
- switch (BomoInfo.xian)
- {
- case 4:
- BomoInfo.Level = BomoInfo.fu + 1;
- break;
- case 5:
- BomoInfo.Level = BomoInfo.fu + 4;
- break;
- case 6:
- case 7:
- case 8:
- case 9:{
- BomoInfo.Level = BomoInfo.fu + BomoInfo.xian;
- break;
- }
-
- default:
- break;
- }
- }
- else if(BomoInfo.BomoTypes == BomoTypeLian)
- {
- if (BomoInfo.tong > 4)
- {
- BomoInfo.Level = BomoInfo.tong + BomoInfo.lian + 1;
- }
- else{
- BomoInfo.Level = BomoInfo.tong + BomoInfo.lian;
- }
- }
- }
-
|