诸暨麻将添加redis
您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 
 
 
 

4140 行
104 KiB

  1. #include "Stdafx.h"
  2. #include "GameLogic_poker.h"
  3. #include<algorithm>
  4. //////////////////////////////////////////////////////////////////////////
  5. //静态变量
  6. //索引变量
  7. const BYTE cbIndexCount=5;
  8. //扑克数据
  9. const BYTE CGameLogic_Poker::m_cbCardData[FULL_COUNT_Poker] =
  10. {
  11. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D, //方块 A - K
  12. 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D, //梅花 A - K
  13. 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D, //红桃 A - K
  14. 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D, //黑桃 A - K
  15. 0x4E,0x4F,
  16. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D, //方块 A - K
  17. 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D, //梅花 A - K
  18. 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D, //红桃 A - K
  19. 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D, //黑桃 A - K
  20. 0x4E,0x4F,
  21. };
  22. //////////////////////////////////////////////////////////////////////////
  23. //构造函数
  24. CGameLogic_Poker::CGameLogic_Poker()
  25. {
  26. m_GameMagicMode = 2;
  27. }
  28. //析构函数
  29. CGameLogic_Poker::~CGameLogic_Poker()
  30. {
  31. }
  32. //获取类型
  33. BYTE CGameLogic_Poker::GetCardType(const BYTE cbCardData[], BYTE cbCardCount, BYTE &cbStarLevel, BomoType&BomoInfo)
  34. {
  35. BYTE cbTmpCardData[MAX_COUNT_Poker] = { 0 };
  36. CopyMemory(cbTmpCardData, cbCardData,cbCardCount);
  37. SortCardList(cbTmpCardData, cbCardCount, ST_ORDER, ORDERBY_DES);
  38. //变量初始化
  39. cbStarLevel=0;
  40. //简单牌型
  41. switch (cbCardCount)
  42. {
  43. case 0: //空牌
  44. {
  45. return CT_ERROR;
  46. }
  47. case 1: //单牌
  48. {
  49. return CT_SINGLE;
  50. }
  51. }
  52. //排炸类型
  53. if (cbCardCount>=12)
  54. {
  55. //变量定义
  56. BYTE cbCardIndex=0;
  57. BYTE cbBlockCount=0;//同牌个数
  58. BYTE cbBombCardData[MAX_COUNT_Poker/4];//炸弹单牌 按照顺序存储
  59. BYTE cbSmallCount=0;//最小的同牌个数
  60. BYTE cbMaxCount=0;//最大的同牌个数
  61. ZeroMemory(cbBombCardData,sizeof(cbBombCardData));
  62. //扑克分析
  63. do
  64. {
  65. //变量定义
  66. BYTE cbSameCount=1;
  67. BYTE cbCardValue = GetCardLogicValue(cbTmpCardData[cbCardIndex]);
  68. //同牌搜索
  69. for (BYTE i=cbCardIndex+1;i<cbCardCount;i++)
  70. {
  71. if (GetCardLogicValue(cbTmpCardData[i]) == cbCardValue)
  72. {
  73. cbSameCount++;
  74. }
  75. else break;
  76. }
  77. //连牌判断
  78. if (cbSameCount>=4)
  79. {
  80. cbBombCardData[cbBlockCount] = cbTmpCardData[cbCardIndex];
  81. cbBlockCount++;
  82. cbCardIndex+=cbSameCount;
  83. if(cbSmallCount==0)
  84. cbSmallCount=cbSameCount;
  85. else
  86. cbSmallCount=min(cbSameCount,cbSmallCount);
  87. if(cbMaxCount==0)
  88. cbMaxCount=cbSameCount;
  89. else
  90. cbMaxCount=max(cbMaxCount,cbSameCount);
  91. }
  92. else break;
  93. } while (cbCardIndex<cbCardCount);
  94. //结果判断
  95. if ((cbBlockCount >= 3) && (cbCardIndex == cbCardCount) && (cbCardCount%cbBlockCount == 0) && IsStructureLink(cbTmpCardData, cbCardCount, cbCardCount / cbBlockCount, true) && (cbSmallCount == cbMaxCount))
  96. {
  97. BomoInfo.tong = cbCardCount / cbBlockCount;
  98. BomoInfo.lian = cbBlockCount;
  99. BomoInfo.BomoTypes = BomoTypeLian;
  100. BomoInfo.CbBomoCount = BomoInfo.tong*BomoInfo.lian;
  101. SetBomoLevel(BomoInfo);
  102. cbStarLevel = BomoInfo.Level;
  103. return CT_BOMB_LINK;
  104. }
  105. if ((cbBlockCount >= 3) && (cbCardIndex == cbCardCount) && (IsStructureLink(cbTmpCardData, cbCardCount, cbCardCount / cbBlockCount, true) == FALSE && (cbSmallCount == cbMaxCount)))
  106. {
  107. cbStarLevel=cbBlockCount+cbSmallCount;
  108. BomoInfo.BomoTypes = BomoTypeXian;
  109. BomoInfo.fu = cbBlockCount;
  110. BomoInfo.xian = cbCardCount / cbBlockCount;
  111. SetBomoLevel(BomoInfo);
  112. cbStarLevel = BomoInfo.Level;
  113. BomoInfo.CbBomoCount = BomoInfo.fu*BomoInfo.xian;
  114. if (BomoInfo.fu==3||(BomoInfo.fu==4&&BomoInfo.xian==4))
  115. {
  116. ZeroMemory(&BomoInfo, sizeof(BomoInfo));
  117. return CT_ERROR;
  118. }
  119. return CT_BOMB_XIAN;
  120. }
  121. }
  122. //分析扑克
  123. tagAnalyseResult_Poker AnalyseResult;
  124. AnalysebCardData(cbTmpCardData, cbCardCount, AnalyseResult);
  125. if (GetMagicType() != NoHaveMagic)
  126. {
  127. //3王炸弹
  128. if ((cbCardCount == 3) )
  129. {
  130. BOOL bFindNoJoker = FALSE;
  131. for (int i = 0; i < 3; i++)
  132. {
  133. if (cbTmpCardData[i] != 0x4E && cbTmpCardData[i] != 0x4F)
  134. {
  135. bFindNoJoker = TRUE;
  136. break;
  137. }
  138. }
  139. if ( bFindNoJoker == FALSE)
  140. {
  141. cbStarLevel = 6;
  142. BomoInfo.Level = cbStarLevel;
  143. return CT_BOMB_3W;
  144. }
  145. }
  146. }
  147. //同牌判断
  148. if ((cbCardCount==3)&&(AnalyseResult.cbBlockCount[2]==1)) return CT_THREE; //3张同牌
  149. if ((cbCardCount==2)&&(AnalyseResult.cbBlockCount[1]==1)) return CT_DOUBLE;//对子牌型
  150. //判断是否是 大小王对子
  151. if (cbCardCount == 2 && GetMagicType()!= NoHaveMagic)
  152. {
  153. if (cbCardData[0]==0x4f&&cbCardData[1]==0x4e)
  154. {
  155. return CT_DOUBLE;
  156. }
  157. }
  158. //天王炸弹
  159. if ((cbCardCount == 4))
  160. {
  161. BYTE MagicCount = 0;
  162. for (int i = 0; i < 4;i++)
  163. {
  164. if (cbCardData[i]==0x4e||cbCardData[i]==0x4f)
  165. {
  166. MagicCount++;
  167. }
  168. }
  169. if (MagicCount==4)
  170. {
  171. if (GetMagicType() == NoHaveMagic)
  172. {
  173. cbStarLevel = 8;//4王炸弹7星级 最大
  174. }
  175. else
  176. {
  177. cbStarLevel = 7;//4王炸弹7星级 最大
  178. }
  179. BomoInfo.Level = cbStarLevel;
  180. return CT_BOMB_TW;
  181. }
  182. }
  183. //炸弹类型
  184. if ((cbCardCount>=4)&&(cbCardCount<=12)&&(AnalyseResult.cbBlockCount[cbCardCount-1]==1))
  185. {
  186. cbStarLevel= cbCardCount;
  187. return CT_BOMB;
  188. }
  189. //对连类型
  190. if ((cbCardCount>=6)&&((AnalyseResult.cbBlockCount[1]*2)==cbCardCount))
  191. {
  192. BYTE cbDoubleCount=AnalyseResult.cbBlockCount[1]*2;
  193. if (IsStructureLink(AnalyseResult.cbCardData[1],cbDoubleCount,2)==true) return CT_DOUBLE_LINK;
  194. }
  195. //三连类型
  196. if ((cbCardCount>=9)&&((AnalyseResult.cbBlockCount[2]*3)==cbCardCount))
  197. {
  198. BYTE cbThreeCount=AnalyseResult.cbBlockCount[2]*3;
  199. if (IsStructureLink(AnalyseResult.cbCardData[2],cbThreeCount,3)==true) return CT_THREE_LINK;
  200. }
  201. //顺子类型
  202. if ((cbCardCount>=5)&&AnalyseResult.cbBlockCount[0]==cbCardCount)
  203. {
  204. if (IsStructureLink(AnalyseResult.cbCardData[0],cbCardCount,1)==true) return CT_SHUNZI;
  205. }
  206. return CT_ERROR;
  207. }
  208. //排列扑克
  209. VOID CGameLogic_Poker::SortCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbSortType,BYTE OrderByType)
  210. {
  211. //数目过虑
  212. if (cbCardCount==0) return;
  213. //转换数值
  214. BYTE cbSortValue[MAX_COUNT_Poker];
  215. for (BYTE i=0;i<cbCardCount;i++)
  216. {
  217. if (cbSortType==ST_VALUE)
  218. {
  219. cbSortValue[i]=GetCardValue(cbCardData[i]);
  220. }
  221. else
  222. {
  223. cbSortValue[i]=GetCardLogicValue(cbCardData[i]);
  224. }
  225. }
  226. if (OrderByType==ORDERBY_ASE)
  227. {
  228. //排序操作 升序
  229. bool bSorted = true;
  230. BYTE cbSwitchData = 0, cbLast = cbCardCount - 1;
  231. do
  232. {
  233. bSorted = true;
  234. for (BYTE i = 0; i < cbLast; i++)
  235. {
  236. if ((cbSortValue[i] > cbSortValue[i + 1]) ||
  237. ((cbSortValue[i] == cbSortValue[i + 1]) && (cbCardData[i] > cbCardData[i + 1])))
  238. {
  239. //设置标志
  240. bSorted = false;
  241. //扑克数据
  242. cbSwitchData = cbCardData[i];
  243. cbCardData[i] = cbCardData[i + 1];
  244. cbCardData[i + 1] = cbSwitchData;
  245. //排序权位
  246. cbSwitchData = cbSortValue[i];
  247. cbSortValue[i] = cbSortValue[i + 1];
  248. cbSortValue[i + 1] = cbSwitchData;
  249. }
  250. }
  251. cbLast--;
  252. } while (bSorted == false);
  253. }
  254. else
  255. {
  256. //降序
  257. bool bSorted = true;
  258. BYTE cbSwitchData = 0, cbLast = cbCardCount - 1;
  259. do
  260. {
  261. bSorted = true;
  262. for (BYTE i = 0; i < cbLast; i++)
  263. {
  264. if ((cbSortValue[i] < cbSortValue[i + 1]) ||
  265. ((cbSortValue[i] == cbSortValue[i + 1]) && (cbCardData[i] < cbCardData[i + 1])))
  266. {
  267. //设置标志
  268. bSorted = false;
  269. //扑克数据
  270. cbSwitchData = cbCardData[i];
  271. cbCardData[i] = cbCardData[i + 1];
  272. cbCardData[i + 1] = cbSwitchData;
  273. //排序权位
  274. cbSwitchData = cbSortValue[i];
  275. cbSortValue[i] = cbSortValue[i + 1];
  276. cbSortValue[i + 1] = cbSwitchData;
  277. }
  278. }
  279. cbLast--;
  280. } while (bSorted == false);
  281. }
  282. //数目排序
  283. if (cbSortType==ST_COUNT)
  284. {
  285. //变量定义
  286. BYTE cbCardIndex=0;
  287. //分析扑克
  288. tagAnalyseResult_Poker AnalyseResult;
  289. AnalysebCardData(&cbCardData[cbCardIndex],cbCardCount-cbCardIndex,AnalyseResult);
  290. //提取扑克
  291. for (BYTE i=0;i<CountArray(AnalyseResult.cbBlockCount);i++)
  292. {
  293. //拷贝扑克
  294. BYTE cbIndex=CountArray(AnalyseResult.cbBlockCount)-i-1;
  295. CopyMemory(&cbCardData[cbCardIndex],AnalyseResult.cbCardData[cbIndex],AnalyseResult.cbBlockCount[cbIndex]*(cbIndex+1)*sizeof(BYTE));
  296. //设置索引
  297. cbCardIndex+=AnalyseResult.cbBlockCount[cbIndex]*(cbIndex+1)*sizeof(BYTE);
  298. }
  299. }
  300. return;
  301. }
  302. //混乱扑克
  303. //OutCardType 3中情况 1张发 3张发 6张发
  304. VOID
  305. CGameLogic_Poker::RandCardList(BYTE cbCardBuffer[], BYTE cbBufferCount, byte OutCardType, WORD wRoomId)
  306. {
  307. //混乱准备
  308. BYTE cbCardData[CountArray(m_cbCardData)];
  309. CopyMemory(cbCardData,m_cbCardData,sizeof(m_cbCardData));
  310. BYTE cbUserCardData[4][27] = { 0 };
  311. BYTE cbUserCardCount[4] = { 0 };
  312. BYTE cbPosition=0;
  313. //混乱扑克
  314. int nCount;
  315. switch (OutCardType)
  316. {
  317. case OneCardDeal:{
  318. nCount = 1;
  319. break;
  320. }
  321. case ThreeCardDeal:{
  322. nCount = 2;
  323. break;
  324. }
  325. case sixCardDeal:
  326. {
  327. nCount = 3;
  328. break;
  329. }
  330. default:
  331. nCount = 3;
  332. break;
  333. }
  334. if (OutCardType == sixCardDeal)
  335. {
  336. srand(time(0) * wRoomId); //随机种子由当前时间和房间ID生成
  337. vector<vector<BYTE>> AllCards;//保存所有扑克
  338. for (int i = 0; i < 15; i++)
  339. {
  340. vector<BYTE> tmp;
  341. AllCards.push_back(tmp);
  342. }
  343. for (int i = 0; i < 108; i++)
  344. {
  345. BYTE Value = GetCardValue(m_cbCardData[i]);
  346. AllCards[Value - 1].push_back(m_cbCardData[i]);
  347. }
  348. BYTE cbLeftCount = 108;
  349. BYTE RandValue, RandCount;
  350. //先将4个人的index随机排序
  351. BYTE NewUserIndexNum[4] = { 0 };
  352. {
  353. BYTE UserIndexNum[] = { 0, 1, 2, 3 };
  354. BYTE cbUserRandCount = 0;
  355. BYTE cbPosition = 0;
  356. BYTE cbBufferCount = 4;
  357. do
  358. {
  359. BYTE cbUserBufferCount = 4;
  360. BYTE cbTempRandCount = 0;
  361. cbPosition = rand() % (cbUserBufferCount - cbUserRandCount);
  362. NewUserIndexNum[cbUserRandCount++] = UserIndexNum[cbPosition];
  363. UserIndexNum[cbPosition] = UserIndexNum[cbBufferCount - cbUserRandCount];
  364. cbTempRandCount++;
  365. } while (cbUserRandCount < cbBufferCount);
  366. }
  367. //随机出每个人妹没个炸弹的个数以及牌值
  368. struct RandCardInfos
  369. {
  370. BYTE userID;
  371. BYTE BomoCount;
  372. BYTE BomoCardValue[4];//每幅炸的牌值
  373. BYTE BomoCardCount[4];//每幅炸弹的张数
  374. };
  375. vector<RandCardInfos> vBomoInfos;
  376. for (int UserIndex = 0; UserIndex < 4; UserIndex++)
  377. {
  378. RandCardInfos CardInfo;
  379. ZeroMemory(&CardInfo, sizeof(RandCardInfos));
  380. CardInfo.userID = NewUserIndexNum[UserIndex];
  381. BYTE cbBomoCountArr[] = {1,2,3,4 };
  382. int BomoCount = rand() % 4;
  383. CardInfo.BomoCount = cbBomoCountArr[BomoCount];
  384. for (int TmpBomoCount = 0; TmpBomoCount < CardInfo.BomoCount; TmpBomoCount++)
  385. {
  386. srand((unsigned)time(0)*CardInfo.userID);
  387. BYTE cbCardCountArr[] = { 4, 5, 6, 7, 8 };
  388. BYTE CardIndex = rand() % 12;
  389. BYTE CardCount = rand() % 5;
  390. CardInfo.BomoCardValue[TmpBomoCount] = CardIndex;
  391. CardInfo.BomoCardCount[TmpBomoCount] = cbCardCountArr[CardCount];
  392. }
  393. vBomoInfos.push_back(CardInfo);
  394. // CString outstr;
  395. // outstr.Format(_T("UserIndex=%d BomoCount=%d\r\n"),CardInfo.userID,CardInfo.BomoCount);
  396. // OutputDebugString(outstr);
  397. }
  398. //OutputDebugString(_T("--------------------------------------\r\n"));
  399. //把每个牌取出来
  400. vector<RandCardInfos>::iterator it = vBomoInfos.begin();
  401. for (; it != vBomoInfos.end();it++)
  402. {
  403. for (int BomoCount = 0; BomoCount < it->BomoCount; BomoCount++)
  404. {
  405. BYTE index = it->BomoCardValue[BomoCount];
  406. //牌堆里面的牌 如果允许用户全部拿走
  407. if (AllCards[index].size()>=it->BomoCardCount[BomoCount])
  408. {
  409. for (int CopyCard = 0; CopyCard < it->BomoCardCount[BomoCount];CopyCard++)
  410. {
  411. if (cbUserCardCount[it->userID]>=27)
  412. {
  413. break;
  414. }
  415. cbUserCardData[it->userID][cbUserCardCount[it->userID]++] = AllCards[index][0];
  416. AllCards[index].erase(AllCards[index].begin());
  417. }
  418. }
  419. }
  420. }
  421. //剩余牌随机
  422. BYTE cbBufferAllCards[108] = { 0 };
  423. BYTE cbBufferAllCardsCount = 0;
  424. for (int i = 0; i < AllCards.size(); i++)
  425. {
  426. for (int j = 0; j < AllCards[i].size(); j++)
  427. {
  428. cbBufferAllCards[cbBufferAllCardsCount++] = AllCards[i][j];
  429. }
  430. }
  431. //洗牌之后的
  432. BYTE cbRandedCards[108] = { 0 };
  433. BYTE cbRandedCardCount = cbBufferAllCardsCount;
  434. nCount = 4;
  435. while (nCount > 0)
  436. {
  437. srand(time(0) * wRoomId); //随机种子由当前时间和房间ID生成
  438. BYTE cbRandCount = 0, cbTempRandCount = 0;
  439. nCount--;
  440. do
  441. {
  442. cbTempRandCount = 0;
  443. cbPosition = rand() % (cbRandedCardCount - cbRandCount);
  444. cbRandedCards[cbRandCount++] = cbBufferAllCards[cbPosition];
  445. cbBufferAllCards[cbPosition] = cbBufferAllCards[cbRandedCardCount - cbRandCount];
  446. cbTempRandCount++;
  447. while ((cbPosition < cbRandedCardCount - cbRandCount) && (cbTempRandCount < 4))
  448. {
  449. cbPosition++;
  450. cbRandedCards[cbRandCount++] = cbBufferAllCards[cbPosition];
  451. cbBufferAllCards[cbPosition] = cbBufferAllCards[cbRandedCardCount - cbRandCount];
  452. cbTempRandCount++;
  453. }
  454. } while (cbRandCount < cbRandedCardCount);
  455. CopyMemory(cbBufferAllCards, cbRandedCards, 108);
  456. }
  457. //每人27张
  458. BYTE StartIndex = 0;
  459. BYTE *TmpPointCardBuffer = cbCardBuffer;
  460. for (int index = 0; index < 4;index++)
  461. {
  462. if (cbUserCardCount[index]==0)
  463. {
  464. CopyMemory(TmpPointCardBuffer, &cbRandedCards[StartIndex], 27);
  465. StartIndex += 27;
  466. TmpPointCardBuffer += 27;
  467. }
  468. else{
  469. CopyMemory(TmpPointCardBuffer, &cbUserCardData[index], cbUserCardCount[index]);
  470. TmpPointCardBuffer += cbUserCardCount[index];
  471. BYTE CopyDataCount = 27 - cbUserCardCount[index];
  472. CopyMemory(TmpPointCardBuffer, &cbRandedCards[StartIndex], CopyDataCount);
  473. StartIndex += CopyDataCount;
  474. TmpPointCardBuffer += CopyDataCount;
  475. }
  476. }
  477. }
  478. else
  479. {
  480. while (nCount > 0)
  481. {
  482. nCount--;
  483. srand(time(0) * wRoomId); //随机种子由当前时间和房间ID生成
  484. BYTE cbRandCount = 0, cbTempRandCount = 0;
  485. do
  486. {
  487. cbTempRandCount = 0;
  488. cbPosition = rand() % (cbBufferCount - cbRandCount);
  489. cbCardBuffer[cbRandCount++] = cbCardData[cbPosition];
  490. cbCardData[cbPosition] = cbCardData[cbBufferCount - cbRandCount];
  491. cbTempRandCount++;
  492. while ((cbPosition < cbBufferCount - cbRandCount) && (cbTempRandCount < 4))
  493. {
  494. cbPosition++;
  495. cbCardBuffer[cbRandCount++] = cbCardData[cbPosition];
  496. cbCardData[cbPosition] = cbCardData[cbBufferCount - cbRandCount];
  497. cbTempRandCount++;
  498. }
  499. } while (cbRandCount < cbBufferCount);
  500. CopyMemory(cbCardData, cbCardBuffer,108);
  501. }
  502. }
  503. return;
  504. }
  505. //删除扑克
  506. bool CGameLogic_Poker::RemoveCard(const BYTE cbRemoveCard[], BYTE cbRemoveCount, BYTE cbCardData[], BYTE cbCardCount)
  507. {
  508. //检验数据
  509. ASSERT(cbRemoveCount<=cbCardCount);
  510. //定义变量
  511. BYTE cbDeleteCount=0,cbTempCardData[MAX_COUNT_Poker];
  512. if (cbCardCount > CountArray(cbTempCardData))
  513. {
  514. OutputDebugString(L"RemoveCard CountArray ");
  515. return false;
  516. }
  517. CopyMemory(cbTempCardData,cbCardData,cbCardCount*sizeof(cbCardData[0]));
  518. //置零扑克
  519. for (BYTE i=0;i<cbRemoveCount;i++)
  520. {
  521. for (BYTE j=0;j<cbCardCount;j++)
  522. {
  523. if (cbRemoveCard[i]==cbTempCardData[j])
  524. {
  525. cbDeleteCount++;
  526. cbTempCardData[j]=0;
  527. break;
  528. }
  529. }
  530. }
  531. ASSERT(cbDeleteCount==cbRemoveCount);
  532. if (cbDeleteCount != cbRemoveCount)
  533. {
  534. OutputDebugString(L"Delete Count 不相等 ");
  535. return false;
  536. }
  537. ZeroMemory(cbCardData, cbCardCount);
  538. //清理扑克
  539. BYTE cbCardPos=0;
  540. for (BYTE i=0;i<cbCardCount;i++)
  541. {
  542. if (cbTempCardData[i]!=0)
  543. cbCardData[cbCardPos++]=cbTempCardData[i];
  544. }
  545. return true;
  546. }
  547. //有效判断
  548. bool CGameLogic_Poker::IsValidCard(BYTE cbCardData)
  549. {
  550. //获取属性
  551. BYTE cbCardColor=GetCardColor(cbCardData);
  552. BYTE cbCardValue=GetCardValue(cbCardData);
  553. //有效判断
  554. if ((cbCardColor<=0x30)&&(cbCardValue>=0x01)&&(cbCardValue<=0x0D)) return true;
  555. if(cbCardData==0x4F||cbCardData==0x4E) return true;
  556. return false;
  557. }
  558. //逻辑数值
  559. BYTE CGameLogic_Poker::GetCardLogicValue(BYTE cbCardData)
  560. {
  561. //扑克属性
  562. BYTE cbCardColor=GetCardColor(cbCardData);
  563. BYTE cbCardValue=GetCardValue(cbCardData);
  564. //王牌扑克
  565. if (cbCardValue>=0x0E) return cbCardValue+2;
  566. //转换数值
  567. return (cbCardValue<=2)?(cbCardValue+13):cbCardValue;
  568. }
  569. BYTE CGameLogic_Poker::GetMaxLogicValue(const BYTE cbCarddata[], BYTE cbCardCount)
  570. {
  571. BYTE szCardData[MAX_COUNT_Poker] = { 0 };
  572. CopyMemory(szCardData, cbCarddata, cbCardCount);
  573. SortCardList(szCardData, cbCardCount, ST_ORDER, ORDERBY_DES);
  574. return GetCardLogicValue(szCardData[0]);
  575. }
  576. //只支持 2-A 的转换
  577. BYTE CGameLogic_Poker::TagIndexToNoColorCardValue(BYTE cbCardData){
  578. if (cbCardData < 14)
  579. {
  580. return cbCardData;
  581. }
  582. CString strRet;
  583. switch (cbCardData)
  584. {
  585. case 14:
  586. case 15:
  587. return cbCardData % 13;
  588. break;
  589. case 16:
  590. case 17:
  591. return cbCardData;
  592. break;
  593. default:
  594. return cbCardData;
  595. break;
  596. }
  597. return 0;
  598. }
  599. CString CGameLogic_Poker::LogicValueToString(BYTE cbCardData)
  600. {
  601. //1-15 3-KA2
  602. //16 17 小王 大王
  603. if (cbCardData<11)
  604. {
  605. CString str;
  606. str.Format(L"%d", cbCardData);
  607. return str;
  608. }
  609. CString strRet;
  610. switch (cbCardData)
  611. {
  612. case 11:
  613. strRet = L"J";
  614. break;
  615. case 12:
  616. strRet = L"Q";
  617. break;
  618. case 13:
  619. strRet = L"K";
  620. break;
  621. case 1:
  622. strRet = L"A";
  623. break;
  624. case 2:
  625. strRet = L"2";
  626. break;
  627. case 14:
  628. case 16:
  629. strRet = L"XW";
  630. break;
  631. case 15:
  632. case 17:
  633. strRet = L"DW";
  634. break;
  635. default:
  636. break;
  637. }
  638. return strRet;
  639. }
  640. //对比扑克
  641. //cbFirstCard 上家的牌
  642. //cbNextCard 本家的牌
  643. //比较前 应该是逆序排列 最大的牌值放在最前面
  644. bool CGameLogic_Poker::CompareCard( BYTE cbFirstCard[], BYTE cbNextCard[], BYTE cbFirstCount, BYTE cbNextCount)
  645. {
  646. SortCardList(cbFirstCard, cbFirstCount, ST_ORDER, ORDERBY_DES);
  647. SortCardList(cbNextCard, cbNextCount, ST_ORDER, ORDERBY_DES);
  648. //引用变量
  649. BYTE cbFirstStarLevel;
  650. BYTE cbNextStarLevel;
  651. //类型判断
  652. BomoType bomoinfo,bomoinfo2;
  653. BYTE cbNextType = GetCardType(cbNextCard, cbNextCount, cbNextStarLevel, bomoinfo);
  654. BYTE cbFirstType = GetCardType(cbFirstCard, cbFirstCount, cbFirstStarLevel, bomoinfo2);
  655. //炸弹过虑
  656. if ((cbFirstType>=CT_BOMB)||(cbNextType>=CT_BOMB))
  657. {
  658. //炸弹类型
  659. if (cbNextType<CT_BOMB) return false;
  660. if (cbFirstType<CT_BOMB) return true;
  661. //星级比较
  662. if (cbFirstStarLevel != cbNextStarLevel)
  663. {
  664. return cbNextStarLevel>cbFirstStarLevel;
  665. }
  666. else
  667. {
  668. if (cbFirstType == CT_BOMB_3W || cbNextType==CT_BOMB_3W)
  669. {
  670. if (cbFirstType==CT_BOMB_3W)
  671. {
  672. return cbNextStarLevel >= 6;
  673. }
  674. if (cbNextType==CT_BOMB_3W)
  675. {
  676. return false;
  677. }
  678. }
  679. if (cbFirstType == CT_BOMB_TW || cbNextType == CT_BOMB_TW)
  680. {
  681. //无论是否来自天王炸都是同线级别最大的
  682. if (cbFirstType == CT_BOMB_TW)
  683. {
  684. return false;
  685. }
  686. if (cbNextType == CT_BOMB_TW)
  687. {
  688. return true;
  689. }
  690. }
  691. //线级别相同,按照张数比较大小
  692. if (cbFirstCount!=cbNextCount)
  693. {
  694. return cbNextCount < cbFirstCount;
  695. }
  696. BYTE cbConsultNext = GetCardLogicValue(cbNextCard[0]);
  697. BYTE cbConsultFirst = GetCardLogicValue(cbFirstCard[0]);
  698. return cbConsultNext > cbConsultFirst;
  699. }
  700. }
  701. //不同类型
  702. if (cbFirstType!=cbNextType) return false;
  703. //相同类型
  704. switch (cbFirstType)
  705. {
  706. case CT_SINGLE: //单牌类型
  707. case CT_DOUBLE: //对子类型
  708. case CT_THREE: //三条类型
  709. case CT_SHUNZI: //顺子类型
  710. {
  711. //数目判断
  712. if (cbFirstCount!=cbNextCount) return false;
  713. //变量定义
  714. BYTE cbConsultNext=GetCardLogicValue(cbNextCard[0]);
  715. BYTE cbConsultFirst=GetCardLogicValue(cbFirstCard[0]);
  716. return cbConsultNext>cbConsultFirst;
  717. }
  718. case CT_DOUBLE_LINK: //对连类型
  719. case CT_THREE_LINK: //三连类型
  720. {
  721. //数目判断
  722. if (cbFirstCount!=cbNextCount) return false;
  723. //变量定义
  724. BYTE cbConsultNext=GetCardValue(cbNextCard[0]);
  725. BYTE cbConsultFirst=GetCardValue(cbFirstCard[0]);
  726. //数值转换
  727. if (cbConsultNext!=2)
  728. {
  729. //设置变量
  730. cbConsultNext=0;
  731. //扑克搜索
  732. for (BYTE i=0;i<cbNextCount;i++)
  733. {
  734. BYTE cbLogicValue=GetCardLogicValue(cbNextCard[i]);
  735. if (cbLogicValue>cbConsultNext) cbConsultNext=cbLogicValue;
  736. }
  737. }
  738. //数值转换
  739. if (cbConsultFirst!=2)
  740. {
  741. //设置变量
  742. cbConsultFirst=0;
  743. //扑克搜索
  744. for (BYTE i=0;i<cbFirstCount;i++)
  745. {
  746. BYTE cbLogicValue=GetCardLogicValue(cbFirstCard[i]);
  747. if (cbLogicValue>cbConsultFirst) cbConsultFirst=cbLogicValue;
  748. }
  749. }
  750. return cbConsultNext>cbConsultFirst;
  751. }
  752. }
  753. //错误断言
  754. ASSERT(FALSE);
  755. return false;
  756. }
  757. //对比扑克
  758. bool CGameLogic_Poker::CompareCard(BYTE cbFirstCard, BYTE cbNextCard)
  759. {
  760. //获取数值
  761. BYTE cbNextValue=GetCardLogicValue(cbNextCard);
  762. BYTE cbFirstValue=GetCardLogicValue(cbFirstCard);
  763. //比较大小
  764. return (cbNextValue>cbFirstValue);
  765. }
  766. BYTE CGameLogic_Poker::FindHaveCardCount(const BYTE cbCardBuffer[], BYTE cbCardCount, BYTE cbCardData, BYTE cbCardPosition[2])
  767. {
  768. BYTE CbCardHaveCount=0;
  769. for (BYTE i = 0; i < cbCardCount; i++){
  770. if (cbCardBuffer[i]==cbCardData)
  771. {
  772. cbCardPosition[CbCardHaveCount] = i;
  773. CbCardHaveCount++;
  774. }
  775. }
  776. return CbCardHaveCount;
  777. }
  778. //变幻扑克
  779. bool CGameLogic_Poker::MagicCardData(BYTE cbCardData[], BYTE cbCardCount, BYTE cbResultCard[MAX_COUNT_Poker])
  780. {
  781. //变量定义
  782. BYTE cbNormalCard[MAX_COUNT_Poker];
  783. BYTE cbMagicCardCount=0,cbNormalCardCount=0;
  784. if (m_GameMagicMode==NoHaveMagic)
  785. {
  786. CopyMemory(cbResultCard, cbCardData, cbCardCount*sizeof(BYTE));
  787. return false;
  788. }
  789. //变幻准备
  790. for (BYTE i=0;i<cbCardCount;i++)
  791. {
  792. switch (m_GameMagicMode)
  793. {
  794. case TwoMagicMode:{
  795. if (cbCardData[i] == 0x4F || cbCardData[i] == 0x4E) cbMagicCardCount++;
  796. else cbNormalCard[cbNormalCardCount++] = cbCardData[i];
  797. }
  798. break;
  799. case OneMagicMode:{
  800. if (cbCardData[i] == 0x4F) cbMagicCardCount++;
  801. else cbNormalCard[cbNormalCardCount++] = cbCardData[i];
  802. }
  803. break;
  804. case NoHaveMagic:
  805. cbNormalCard[cbNormalCardCount++] = cbCardData[i];
  806. break;
  807. default:
  808. break;
  809. }
  810. }
  811. //失败判断
  812. if ((cbMagicCardCount==0)||(cbNormalCardCount==0))
  813. {
  814. CopyMemory(cbResultCard,cbCardData,cbCardCount*sizeof(BYTE));
  815. return false;
  816. }
  817. //获取数值
  818. BYTE cbLogicValue=GetCardLogicValue(cbNormalCard[0]);
  819. //同牌变幻
  820. for (BYTE i=1;i<cbNormalCardCount;i++)
  821. {
  822. if (GetCardLogicValue(cbNormalCard[i])!=cbLogicValue) break;
  823. //特殊判断
  824. if(1 == cbNormalCardCount)
  825. {
  826. i=cbNormalCardCount;
  827. }
  828. if (i==cbNormalCardCount)
  829. {
  830. //设置结果
  831. for (BYTE j=0;j<cbMagicCardCount;j++) cbResultCard[j]=cbNormalCard[0];
  832. for (BYTE j=0;j<cbNormalCardCount;j++) cbResultCard[j+cbMagicCardCount]=cbNormalCard[j];
  833. return true;
  834. }
  835. }
  836. //扑克分析
  837. BYTE cbMaxSameCount=1,cbSameCount=1,cbBlock=0;
  838. for (BYTE i=1;i<cbNormalCardCount;i++)
  839. {
  840. //获取扑克
  841. BYTE cbCardValueTemp=GetCardLogicValue(cbNormalCard[i]);
  842. if (cbCardValueTemp==cbLogicValue) cbSameCount++;
  843. //结果处理
  844. if ((cbCardValueTemp!=cbLogicValue)||(i==(cbNormalCardCount-1)))
  845. {
  846. cbMaxSameCount=__max(cbSameCount,cbMaxSameCount);
  847. cbBlock++;
  848. }
  849. //恢复变量
  850. if ((cbCardValueTemp!=cbLogicValue)&&(i!=(cbNormalCardCount-1)))
  851. {
  852. cbSameCount=1;
  853. cbLogicValue=cbCardValueTemp;
  854. }
  855. }
  856. //等同变换
  857. if((cbCardCount>=12)&&(cbCardCount%cbBlock==0)&&(cbBlock>=3))
  858. {
  859. //最大牌数
  860. BYTE cbMaxSameCount1=cbCardCount/cbBlock;
  861. //连炸判断
  862. if(cbMaxSameCount1>=4)
  863. {
  864. //分析分布
  865. tagDistributing Distributing;
  866. AnalysebDistributing(cbNormalCard,cbNormalCardCount,Distributing);
  867. //变量定义
  868. BYTE cbFillCount=0;
  869. BYTE cbLeaveCount=cbNormalCardCount;
  870. BYTE cbUseableCount=cbMagicCardCount;
  871. //填充状态
  872. BYTE cbFillStatus[13];
  873. ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
  874. //填充扑克
  875. for (BYTE i=0;i<13;i++)
  876. {
  877. //变量定义
  878. BYTE cbIndex=i;
  879. //填充判断
  880. if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
  881. {
  882. //失败判断
  883. if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<cbMaxSameCount1) break;
  884. //变量定义
  885. BYTE cbTurnFillCount=0;
  886. //常规扑克
  887. for (BYTE j=0;j<4;j++)
  888. {
  889. for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
  890. {
  891. cbLeaveCount--;
  892. cbTurnFillCount++;
  893. cbResultCard[cbFillCount++]=MakeCardData(cbIndex,j);
  894. }
  895. }
  896. //填充变幻
  897. for (BYTE i=cbTurnFillCount;i<cbMaxSameCount1;i++)
  898. {
  899. cbUseableCount--;
  900. cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
  901. }
  902. //设置变量
  903. cbFillStatus[cbIndex]=cbMaxSameCount;
  904. }
  905. }
  906. //成功判断
  907. if ((cbUseableCount==0)&&(cbLeaveCount==0))
  908. {
  909. SortCardList(cbResultCard,cbCardCount,ST_ORDER);
  910. return true;
  911. }
  912. }
  913. }
  914. //等同变换
  915. if((cbCardCount>=12)&&(cbCardCount%cbBlock==0)&&(cbBlock>=3))
  916. {
  917. //最大牌数
  918. BYTE cbMaxSameCount1=cbCardCount/cbBlock;
  919. //连炸判断
  920. if(cbMaxSameCount1>=4)
  921. {
  922. //分析分布
  923. tagDistributing Distributing;
  924. AnalyseRealDistributing(cbNormalCard,cbNormalCardCount,Distributing);
  925. //变量定义
  926. BYTE cbFillCount=0;
  927. BYTE cbLeaveCount=cbNormalCardCount;
  928. BYTE cbUseableCount=cbMagicCardCount;
  929. //填充状态
  930. BYTE cbFillStatus[13];
  931. ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
  932. //填充扑克
  933. for (BYTE i=0;i<13;i++)
  934. {
  935. //变量定义
  936. BYTE cbIndex=i;
  937. //填充判断
  938. if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
  939. {
  940. //失败判断
  941. if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<cbMaxSameCount) break;
  942. //变量定义
  943. BYTE cbTurnFillCount=0;
  944. //常规扑克
  945. for (BYTE j=0;j<4;j++)
  946. {
  947. for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
  948. {
  949. cbLeaveCount--;
  950. cbTurnFillCount++;
  951. cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,j);
  952. }
  953. }
  954. //填充变幻
  955. for (BYTE i=cbTurnFillCount;i<cbMaxSameCount1;i++)
  956. {
  957. cbUseableCount--;
  958. cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,0);
  959. }
  960. //设置变量
  961. cbFillStatus[cbIndex]=cbMaxSameCount;
  962. }
  963. }
  964. //成功判断
  965. if ((cbUseableCount==0)&&(cbLeaveCount==0))
  966. {
  967. SortCardList(cbResultCard,cbCardCount,ST_ORDER);
  968. return true;
  969. }
  970. }
  971. }
  972. //不等变换
  973. if((cbMaxSameCount>=4)&&(cbBlock>=3)&&(cbCardCount>=12)) //3连排炸
  974. {
  975. //分析分布
  976. tagDistributing Distributing;
  977. AnalysebDistributing(cbNormalCard,cbNormalCardCount,Distributing);
  978. //填充分析
  979. for (BYTE cbTimes=0;cbTimes<2;cbTimes++)
  980. {
  981. //变量定义
  982. BYTE cbFillCount=0;
  983. BYTE cbLeaveCount=cbNormalCardCount;
  984. BYTE cbUseableCount=cbMagicCardCount;
  985. //填充状态
  986. BYTE cbFillStatus[13];
  987. ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
  988. //填充扑克
  989. for (BYTE i=0;i<13;i++)
  990. {
  991. //变量定义
  992. BYTE cbIndex=(cbTimes==1)?(cbIndex=(13-i)%13):i;
  993. //填充判断
  994. if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
  995. {
  996. //过滤炸弹
  997. if(Distributing.cbDistributing[cbIndex][cbIndexCount]>=4)
  998. {
  999. //记录数据
  1000. cbFillStatus[cbIndex]=Distributing.cbDistributing[cbIndex][cbIndexCount];
  1001. }
  1002. //失败判断
  1003. if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<4) break;
  1004. //变量定义
  1005. BYTE cbTurnFillCount=0;
  1006. //常规扑克
  1007. for (BYTE j=0;j<4;j++)
  1008. {
  1009. for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
  1010. {
  1011. cbLeaveCount--;
  1012. cbTurnFillCount++;
  1013. cbResultCard[cbFillCount++]=MakeCardData(cbIndex,j);
  1014. }
  1015. }
  1016. //填充变幻
  1017. for (BYTE i=cbTurnFillCount;i<4;i++)
  1018. {
  1019. cbUseableCount--;
  1020. cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
  1021. }
  1022. //设置变量
  1023. if(cbTurnFillCount<4)
  1024. cbFillStatus[cbIndex]=4;
  1025. else
  1026. cbFillStatus[cbIndex]=cbTurnFillCount;
  1027. }
  1028. }
  1029. //剩余填充
  1030. if ((cbLeaveCount==0)&&(cbUseableCount>0))
  1031. {
  1032. //现在先查找最小填充数
  1033. BYTE cbMinFillCount=0;
  1034. BYTE cbMaxFillCount=0;
  1035. BYTE cbMinIndex=0;//最小索引
  1036. for (BYTE i=0;i<13;i++)
  1037. {
  1038. if (cbFillStatus[i]==0) continue;//过滤没有填充的
  1039. if(cbMinIndex==0 &&cbMinFillCount==0)
  1040. {
  1041. cbMinFillCount=cbFillStatus[i];
  1042. cbMinIndex=i;
  1043. }
  1044. //开始寻找 取大
  1045. if(cbFillStatus[i]<cbMinFillCount)
  1046. {
  1047. cbMinFillCount=cbFillStatus[i];
  1048. cbMinIndex=i;
  1049. }
  1050. cbMaxFillCount=max(cbMaxFillCount,cbFillStatus[i]);
  1051. }
  1052. for (BYTE i=cbMinIndex;i<13;i++)
  1053. {
  1054. //变量定义
  1055. BYTE cbIndex=(cbTimes==1)?(cbIndex=(13-i)%13):i;
  1056. if (cbFillStatus[cbIndex]==0) continue;//过滤没有填充的
  1057. //填充扑克
  1058. for (BYTE j=cbFillStatus[cbIndex];j<cbMaxFillCount;j++)
  1059. {
  1060. cbUseableCount--;
  1061. cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
  1062. //完成判断
  1063. if (cbUseableCount==0) break;
  1064. }
  1065. //完成判断
  1066. if (cbUseableCount==0) break;
  1067. }
  1068. //如果都填充满了 还有多余的王 那就从大到小的填充 毕竟王牌只有2个 一次就够了阿
  1069. if(cbUseableCount>0)
  1070. {
  1071. for (BYTE i=12;i>=0;i--)
  1072. {
  1073. //填充扑克
  1074. if(cbFillStatus[i]>0)
  1075. {
  1076. cbUseableCount--;
  1077. cbResultCard[cbFillCount++]=MakeCardData(i,0);
  1078. cbFillStatus[i]++;
  1079. }
  1080. //完成判断
  1081. if (cbUseableCount==0) break;
  1082. }
  1083. }
  1084. }
  1085. //成功判断
  1086. if ((cbUseableCount==0)&&(cbLeaveCount==0))
  1087. {
  1088. SortCardList(cbResultCard,cbCardCount,ST_ORDER);
  1089. return true;
  1090. }
  1091. }
  1092. }
  1093. //不等变换
  1094. if((cbMaxSameCount>=4)&&(cbBlock>=3)&&(cbCardCount>=12)) //3连排炸
  1095. {
  1096. //分析分布
  1097. tagDistributing Distributing;
  1098. AnalyseRealDistributing(cbNormalCard,cbNormalCardCount,Distributing);
  1099. //填充分析
  1100. for (BYTE cbTimes=0;cbTimes<2;cbTimes++)
  1101. {
  1102. //变量定义
  1103. BYTE cbFillCount=0;
  1104. BYTE cbLeaveCount=cbNormalCardCount;
  1105. BYTE cbUseableCount=cbMagicCardCount;
  1106. //填充状态
  1107. BYTE cbFillStatus[13];
  1108. ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
  1109. //填充扑克
  1110. for (BYTE i=0;i<13;i++)
  1111. {
  1112. //变量定义
  1113. BYTE cbIndex=(cbTimes==1)?(cbIndex=(13-i)%13):i;
  1114. //填充判断
  1115. if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
  1116. {
  1117. //过滤炸弹
  1118. if(Distributing.cbDistributing[cbIndex][cbIndexCount]>=4)
  1119. {
  1120. //记录数据
  1121. cbFillStatus[cbIndex]=Distributing.cbDistributing[cbIndex][cbIndexCount];
  1122. }
  1123. //失败判断
  1124. if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<4) break;
  1125. //变量定义
  1126. BYTE cbTurnFillCount=0;
  1127. //常规扑克
  1128. for (BYTE j=0;j<4;j++)
  1129. {
  1130. for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
  1131. {
  1132. cbLeaveCount--;
  1133. cbTurnFillCount++;
  1134. cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,j);
  1135. }
  1136. }
  1137. //填充变幻
  1138. for (BYTE i=cbTurnFillCount;i<4;i++)
  1139. {
  1140. cbUseableCount--;
  1141. cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,0);
  1142. }
  1143. //设置变量
  1144. if(cbTurnFillCount<4)
  1145. cbFillStatus[cbIndex]=4;
  1146. else
  1147. cbFillStatus[cbIndex]=cbTurnFillCount;
  1148. }
  1149. }
  1150. //剩余填充
  1151. if ((cbLeaveCount==0)&&(cbUseableCount>0))
  1152. {
  1153. //现在先查找最小填充数
  1154. BYTE cbMinFillCount=0;
  1155. BYTE cbMaxFillCount=0;
  1156. BYTE cbMinIndex=0;//最小索引
  1157. for (BYTE i=0;i<13;i++)
  1158. {
  1159. if (cbFillStatus[i]==0) continue;//过滤没有填充的
  1160. if(cbMinIndex==0 &&cbMinFillCount==0)
  1161. {
  1162. cbMinFillCount=cbFillStatus[i];
  1163. cbMinIndex=i;
  1164. }
  1165. //开始寻找 取大
  1166. if(cbFillStatus[i]<cbMinFillCount)
  1167. {
  1168. cbMinFillCount=cbFillStatus[i];
  1169. cbMinIndex=i;
  1170. }
  1171. cbMaxFillCount=max(cbMaxFillCount,cbFillStatus[i]);
  1172. }
  1173. for (BYTE i=cbMinIndex;i<13;i++)
  1174. {
  1175. //变量定义
  1176. BYTE cbIndex=(cbTimes==1)?(cbIndex=(13-i)%13):i;
  1177. if (cbFillStatus[cbIndex]==0) continue;//过滤没有填充的
  1178. //填充扑克
  1179. for (BYTE j=cbFillStatus[cbIndex];j<cbMaxFillCount;j++)
  1180. {
  1181. cbUseableCount--;
  1182. cbResultCard[cbFillCount++]=MakeRealCardData(cbIndex,0);
  1183. //完成判断
  1184. if (cbUseableCount==0) break;
  1185. }
  1186. //完成判断
  1187. if (cbUseableCount==0) break;
  1188. }
  1189. //如果都填充满了 还有多余的王 那就从大到小的填充 毕竟王牌只有2个 一次就够了阿
  1190. if(cbUseableCount>0)
  1191. {
  1192. for (BYTE i=12;i>=0;i--)
  1193. {
  1194. //填充扑克
  1195. if(cbFillStatus[i]>0)
  1196. {
  1197. cbUseableCount--;
  1198. cbResultCard[cbFillCount++]=MakeRealCardData(i,0);
  1199. cbFillStatus[i]++;
  1200. }
  1201. //完成判断
  1202. if (cbUseableCount==0) break;
  1203. }
  1204. }
  1205. }
  1206. //成功判断
  1207. if ((cbUseableCount==0)&&(cbLeaveCount==0))
  1208. {
  1209. SortCardList(cbResultCard,cbCardCount,ST_ORDER);
  1210. return true;
  1211. }
  1212. }
  1213. }
  1214. //连牌变幻
  1215. if ((cbMaxSameCount<=3)&&((cbCardCount%cbMaxSameCount)==0)&&(cbCardCount/cbMaxSameCount<=13))
  1216. {
  1217. //分析分布
  1218. tagDistributing Distributing;
  1219. AnalysebDistributing(cbNormalCard,cbNormalCardCount,Distributing);
  1220. //填充分析
  1221. for (BYTE cbTimes=0;cbTimes<2;cbTimes++)
  1222. {
  1223. //变量定义
  1224. BYTE cbFillCount=0;
  1225. BYTE cbLeaveCount=cbNormalCardCount;
  1226. BYTE cbUseableCount=cbMagicCardCount;
  1227. //填充状态
  1228. BYTE cbFillStatus[13];
  1229. ZeroMemory(cbFillStatus,sizeof(cbFillStatus));
  1230. //填充扑克
  1231. for (BYTE i=0;i<12;i++)
  1232. {
  1233. //变量定义
  1234. BYTE cbIndex=(cbTimes==1)?(cbIndex=(11-i)%12):i;
  1235. //填充判断
  1236. if ((cbLeaveCount!=cbNormalCardCount)||(Distributing.cbDistributing[cbIndex][cbIndexCount]!=0))
  1237. {
  1238. //失败判断
  1239. if ((Distributing.cbDistributing[cbIndex][cbIndexCount]+cbUseableCount)<cbMaxSameCount) break;
  1240. //变量定义
  1241. BYTE cbTurnFillCount=0;
  1242. //常规扑克
  1243. for (BYTE j=0;j<4;j++)
  1244. {
  1245. for (BYTE k=0;k<Distributing.cbDistributing[cbIndex][j];k++)
  1246. {
  1247. cbLeaveCount--;
  1248. cbTurnFillCount++;
  1249. cbResultCard[cbFillCount++]=MakeCardData(cbIndex,j);
  1250. }
  1251. }
  1252. //填充变幻
  1253. for (BYTE i=cbTurnFillCount;i<cbMaxSameCount;i++)
  1254. {
  1255. cbUseableCount--;
  1256. cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
  1257. }
  1258. //设置变量
  1259. cbFillStatus[cbIndex]=cbMaxSameCount;
  1260. }
  1261. }
  1262. //剩余填充
  1263. if ((cbLeaveCount==0)&&(cbUseableCount>0))
  1264. {
  1265. for (BYTE i=0;i<12;i++)
  1266. {
  1267. //变量定义
  1268. BYTE cbIndex=(cbTimes==0)?(cbIndex=(11-i)%12):i;
  1269. //填充扑克
  1270. for (BYTE j=cbFillStatus[cbIndex];j<cbMaxSameCount;j++)
  1271. {
  1272. cbUseableCount--;
  1273. cbResultCard[cbFillCount++]=MakeCardData(cbIndex,0);
  1274. }
  1275. //完成判断
  1276. if (cbUseableCount==0) break;
  1277. }
  1278. }
  1279. //成功判断
  1280. if ((cbUseableCount==0)&&(cbLeaveCount==0))
  1281. {
  1282. SortCardList(cbResultCard,cbCardCount,ST_ORDER);
  1283. return true;
  1284. }
  1285. }
  1286. }
  1287. //设置扑克
  1288. CopyMemory(cbResultCard,cbCardData,cbCardCount*sizeof(BYTE));
  1289. return false;
  1290. }
  1291. BOOL CGameLogic_Poker::ReplaceWangCards(BYTE OldCards[], BYTE cbCount, BYTE ReplacCards[4], OUT BYTE cbNoMagicCards[MAX_COUNT_Poker])
  1292. {
  1293. CopyMemory(cbNoMagicCards, OldCards, cbCount);
  1294. byte mode = GetMagicType();
  1295. if (mode==NoHaveMagic||ReplacCards[0]==0)
  1296. {
  1297. return FALSE;
  1298. }
  1299. for (int i = 0; i < 4;i++)
  1300. {
  1301. if (ReplacCards[i]==0)
  1302. {
  1303. break;
  1304. }
  1305. for (BYTE j = 0; j < cbCount; j++)
  1306. {
  1307. BOOL bFind = FALSE;
  1308. switch (mode){
  1309. case OneMagicMode:{
  1310. if (cbNoMagicCards[j] == 0x4f)
  1311. {
  1312. bFind = TRUE;
  1313. cbNoMagicCards[j] = ReplacCards[i];
  1314. }
  1315. break;
  1316. }
  1317. case TwoMagicMode:{
  1318. if (cbNoMagicCards[j] == 0x4f || cbNoMagicCards[j] == 0x4e)
  1319. {
  1320. bFind = TRUE;
  1321. cbNoMagicCards[j] = ReplacCards[i];
  1322. break;
  1323. }
  1324. }
  1325. }
  1326. if (bFind)
  1327. {
  1328. break;
  1329. }
  1330. }
  1331. }
  1332. return TRUE;
  1333. }
  1334. //分析扑克
  1335. VOID CGameLogic_Poker::AnalysebCardData(const BYTE cbCardData[], BYTE cbCardCount, tagAnalyseResult_Poker & AnalyseResult)
  1336. {
  1337. //设置结果
  1338. ZeroMemory(&AnalyseResult,sizeof(AnalyseResult));
  1339. //扑克分析
  1340. for (BYTE i=0;i<cbCardCount;i++)
  1341. {
  1342. //变量定义
  1343. BYTE cbSameCount=1,cbCardValueTemp=0;
  1344. BYTE cbLogicValue=GetCardLogicValue(cbCardData[i]);
  1345. //搜索同牌
  1346. for (BYTE j=i+1;j<cbCardCount;j++)
  1347. {
  1348. //获取扑克
  1349. if (GetCardLogicValue(cbCardData[j])!=cbLogicValue) break;
  1350. //设置变量
  1351. cbSameCount++;
  1352. }
  1353. //设置结果
  1354. BYTE cbIndex=AnalyseResult.cbBlockCount[cbSameCount-1]++;
  1355. for (BYTE j=0;j<cbSameCount;j++)
  1356. AnalyseResult.cbCardData[cbSameCount-1][cbIndex*cbSameCount+j]=cbCardData[i+j];
  1357. //设置索引
  1358. i+=cbSameCount-1;
  1359. }
  1360. return;
  1361. }
  1362. //分析分布
  1363. VOID CGameLogic_Poker::AnalysebDistributing(const BYTE cbCardData[], BYTE cbCardCount, tagDistributing & Distributing)
  1364. {
  1365. //设置变量
  1366. ZeroMemory(&Distributing,sizeof(Distributing));
  1367. //设置变量
  1368. for (BYTE i=0;i<cbCardCount;i++)
  1369. {
  1370. if (cbCardData[i]==0) continue;
  1371. //获取属性
  1372. BYTE cbCardColor=GetCardColor(cbCardData[i]);
  1373. BYTE cbLogicValue=GetCardLogicValue(cbCardData[i]);
  1374. //分布信息
  1375. Distributing.cbCardCount++;
  1376. Distributing.cbDistributing[cbLogicValue-3][cbIndexCount]++;
  1377. Distributing.cbDistributing[cbLogicValue-3][cbCardColor>>4]++;
  1378. }
  1379. return;
  1380. }
  1381. //分析分布
  1382. VOID CGameLogic_Poker::AnalyseRealDistributing(const BYTE cbCardData[], BYTE cbCardCount, tagDistributing & Distributing)
  1383. {
  1384. //设置变量
  1385. ZeroMemory(&Distributing,sizeof(Distributing));
  1386. //设置变量
  1387. for (BYTE i=0;i<cbCardCount;i++)
  1388. {
  1389. if (cbCardData[i]==0) continue;
  1390. //获取属性
  1391. BYTE cbCardColor=GetCardColor(cbCardData[i]);
  1392. BYTE cbCardValue=GetCardValue(cbCardData[i]);
  1393. //分布信息
  1394. Distributing.cbCardCount++;
  1395. Distributing.cbDistributing[cbCardValue-1][cbIndexCount]++;
  1396. Distributing.cbDistributing[cbCardValue-1][cbCardColor>>4]++;
  1397. }
  1398. }
  1399. //出牌搜索
  1400. bool CGameLogic_Poker::SearchOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagOutCardResult & OutCardResult)
  1401. {
  1402. //设置结果
  1403. ZeroMemory(&OutCardResult,sizeof(OutCardResult));
  1404. //构造扑克
  1405. BYTE cbCardData[MAX_COUNT_Poker];
  1406. BYTE cbCardCount=cbHandCardCount;
  1407. CopyMemory(cbCardData,cbHandCardData,sizeof(BYTE)*cbHandCardCount);
  1408. //排列扑克
  1409. SortCardList(cbCardData,cbCardCount,ST_ORDER);
  1410. //获取类型
  1411. BYTE cbStarLevel;
  1412. BomoType bomoinfo;
  1413. BYTE cbTurnOutType = GetCardType(cbTurnCardData, cbTurnCardCount, cbStarLevel,bomoinfo);
  1414. //出牌分析
  1415. switch (cbTurnOutType)
  1416. {
  1417. case CT_ERROR: //错误类型
  1418. {
  1419. //获取数值
  1420. BYTE cbLogicValue=GetCardLogicValue(cbCardData[cbCardCount-1]);
  1421. //多牌判断
  1422. BYTE cbSameCount=1;
  1423. for (BYTE i=1;i<cbCardCount;i++)
  1424. {
  1425. if (GetCardLogicValue(cbCardData[cbCardCount-i-1])==cbLogicValue) cbSameCount++;
  1426. else break;
  1427. }
  1428. //完成处理
  1429. if (cbSameCount>1)
  1430. {
  1431. OutCardResult.cbCardCount=cbSameCount;
  1432. for (BYTE j=0;j<cbSameCount;j++) OutCardResult.cbResultCard[j]=cbCardData[cbCardCount-1-j];
  1433. return true;
  1434. }
  1435. //单牌处理
  1436. OutCardResult.cbCardCount=1;
  1437. OutCardResult.cbResultCard[0]=cbCardData[cbCardCount-1];
  1438. return true;
  1439. }
  1440. }
  1441. return false;
  1442. }
  1443. //搜索顺子
  1444. bool CGameLogic_Poker::SearchLinkCard( const BYTE cbHandCardData[],BYTE cbHandCardCount,const BYTE cbFirstCardData,const BYTE cbLastCardData,tagOutCardResult &OutCardResult )
  1445. {
  1446. ASSERT( IsValidCard(cbFirstCardData) && IsValidCard(cbLastCardData) );
  1447. //获取首位
  1448. BYTE byFirstCardValue = GetCardLogicValue(cbFirstCardData);
  1449. BYTE byLastCardValue = GetCardLogicValue(cbLastCardData);
  1450. //交换数据
  1451. if( byFirstCardValue > byLastCardValue )
  1452. {
  1453. BYTE byTemp = byFirstCardValue;
  1454. byFirstCardValue = byLastCardValue;
  1455. byLastCardValue = byTemp;
  1456. }
  1457. //判断顺子
  1458. if( byFirstCardValue > 14 || byLastCardValue > 14 || byLastCardValue-byFirstCardValue<4 )
  1459. return false;
  1460. //定义变量
  1461. tagDistributing Distribute;
  1462. BYTE byCardData[MAX_COUNT_Poker],byCardCount = cbHandCardCount;
  1463. CopyMemory(byCardData,cbHandCardData,sizeof(BYTE)*byCardCount);
  1464. ZeroMemory(&OutCardResult,sizeof(OutCardResult));
  1465. //分析扑克
  1466. AnalysebDistributing(byCardData,byCardCount,Distribute);
  1467. //变幻准备
  1468. BYTE cbMagicCardCount=0;
  1469. for (BYTE i=0;i<byCardCount;i++)
  1470. {
  1471. if (byCardData[i]==0x4F) cbMagicCardCount++;
  1472. }
  1473. //构造数据
  1474. OutCardResult.cbResultCard[OutCardResult.cbCardCount++] = cbFirstCardData;
  1475. OutCardResult.cbResultCard[OutCardResult.cbCardCount++] = cbLastCardData;
  1476. for( BYTE i = byFirstCardValue-2; i < byLastCardValue-3; i++ )
  1477. {
  1478. if( Distribute.cbDistributing[i][cbIndexCount] > 0 )
  1479. {
  1480. //获取花色
  1481. BYTE cbHeadColor=0xFF;
  1482. for (BYTE cbColorIndex=0;cbColorIndex<4;cbColorIndex++)
  1483. {
  1484. if (Distribute.cbDistributing[i][3-cbColorIndex]>0)
  1485. {
  1486. cbHeadColor=3-cbColorIndex;
  1487. break;
  1488. }
  1489. }
  1490. ASSERT(cbHeadColor!=0xFF);
  1491. OutCardResult.cbResultCard[OutCardResult.cbCardCount++] = MakeCardData(i,cbHeadColor);
  1492. }
  1493. else
  1494. {
  1495. //王牌替换
  1496. if(cbMagicCardCount>0)
  1497. {
  1498. OutCardResult.cbResultCard[OutCardResult.cbCardCount++] = 0x4F;
  1499. //王牌递减
  1500. cbMagicCardCount--;
  1501. }
  1502. else
  1503. break;
  1504. }
  1505. if (i == byLastCardValue - 3)
  1506. {
  1507. SortCardList(OutCardResult.cbResultCard, OutCardResult.cbCardCount);
  1508. return true;
  1509. }
  1510. }
  1511. //结果清零
  1512. ZeroMemory(&OutCardResult,sizeof(OutCardResult));
  1513. return false;
  1514. }
  1515. void CGameLogic_Poker::SetMagicType(BYTE nMode)
  1516. {
  1517. m_GameMagicMode = nMode;
  1518. }
  1519. BYTE CGameLogic_Poker::GetMagicType()
  1520. {
  1521. return m_GameMagicMode;
  1522. }
  1523. BYTE CGameLogic_Poker::GetCardCount(const BYTE cbCardData[], BYTE MAX_CardNum /*= MAX_COUNT_Poker*/)
  1524. {
  1525. for (BYTE i = 1; i <= MAX_CardNum; ++i)
  1526. {
  1527. if (cbCardData[i] == 0)
  1528. return i;
  1529. }
  1530. return MAX_CardNum;
  1531. }
  1532. BYTE CGameLogic_Poker::GetCardMagicCount(const BYTE cbCardData[], BYTE CardCount)
  1533. {
  1534. BYTE cbMagicCardCount = 0;
  1535. switch (m_GameMagicMode)
  1536. {
  1537. case TwoMagicMode:{
  1538. for (int i = 0; i < CardCount;i++)
  1539. {
  1540. if (cbCardData[i] == 0x4F || cbCardData[i] == 0x4E)
  1541. cbMagicCardCount++;
  1542. }
  1543. }
  1544. break;
  1545. case OneMagicMode:{
  1546. for (int i = 0; i < CardCount; i++)
  1547. {
  1548. if (cbCardData[i] == 0x4F)
  1549. cbMagicCardCount++;
  1550. }
  1551. }
  1552. break;
  1553. case NoHaveMagic:
  1554. cbMagicCardCount=0;
  1555. break;
  1556. default:
  1557. break;
  1558. }
  1559. return cbMagicCardCount;
  1560. }
  1561. bool HitComp(HitStruct & h1, HitStruct h2){
  1562. return h1.cbCardCount<h2.cbCardCount;
  1563. }
  1564. BOOL CGameLogic_Poker::bCanOutCard(const BYTE cbCardDatas[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  1565. {
  1566. BYTE cbCardData[MAX_COUNT_Poker] = { 0 };
  1567. CopyMemory(cbCardData, cbCardDatas, cbCount);
  1568. SortCardList(cbCardData, cbCount, ST_ORDER, ORDERBY_DES);
  1569. if (cbCount==0)
  1570. {
  1571. return TRUE;
  1572. }
  1573. ListHit.clear();
  1574. //先获取用户出牌的数据类型
  1575. BYTE cbLevel;
  1576. BomoType BomoInfo;
  1577. BYTE type = GetCardType(cbCardData, cbCount, cbLevel, BomoInfo);
  1578. tagDistributing tag;
  1579. AnalysebDistributing(UserCards, cbUserCount, tag);
  1580. tagAnalyseResult_Poker tagResult;
  1581. AnalysebCardData(UserCards, cbUserCount, tagResult);
  1582. LastCardsInfo lstCardsInfo;
  1583. lstCardsInfo.CardType = type;
  1584. lstCardsInfo.cbCardCount = cbCount;
  1585. CopyMemory(lstCardsInfo.cbCards, cbCardData, cbCount);
  1586. lstCardsInfo.BomoInfo = BomoInfo;
  1587. switch(type){
  1588. case CT_SINGLE:{
  1589. //1-8张的牌 全部取一张
  1590. HintSignle(cbCardData, cbCount, UserCards, cbUserCount, ListHit);
  1591. //查找 可以组成4张牌的炸弹
  1592. //HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
  1593. AllSameBomos(cbCardData, cbCount,4, type, UserCards, cbUserCount, ListHit, TRUE);
  1594. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1595. Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1596. Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1597. //所有特殊牌 5-8X相炸弹
  1598. //所有特殊牌 5-12线连 炸弹
  1599. //HintBoomWithXian(cbCardData, cbCount, BomoInfo, UserCards, cbUserCount, ListHit, TRUE);
  1600. break;
  1601. }
  1602. //5张或5张以上才可能是顺子
  1603. case CT_SHUNZI:{
  1604. HintSHUNZI(cbCardData, cbCount, UserCards, cbUserCount, ListHit);
  1605. HintShunWithJoker(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit);
  1606. HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
  1607. AllSameBomos(cbCardData, cbCount,4, type, UserCards, cbUserCount, ListHit, TRUE);
  1608. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1609. Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1610. Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1611. break;
  1612. }
  1613. case CT_DOUBLE:{
  1614. HintSameCardCount(cbCardData, cbCount, cbCount, UserCards, cbUserCount, ListHit, FALSE);
  1615. //从3-8 中 找对子
  1616. HintSameCardCount_WithFindCount(cbCardData, cbCount, 2, UserCards, cbUserCount, ListHit);
  1617. //HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
  1618. AllSameBomos(cbCardData, cbCount, 4, type, UserCards, cbUserCount, ListHit, TRUE);
  1619. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1620. Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1621. Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1622. break;
  1623. }
  1624. //连对3或3以上个对子
  1625. case CT_DOUBLE_LINK:{
  1626. HintDOUBLE_LINK(cbCardData, cbCount, UserCards, cbUserCount, ListHit);
  1627. HintShunWithJoker(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit);
  1628. //HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
  1629. AllSameBomos(cbCardData, cbCount,4, type, UserCards, cbUserCount, ListHit, TRUE);
  1630. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1631. Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1632. Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1633. break;
  1634. }
  1635. case CT_THREE:{
  1636. HintSameCardCount(cbCardData, cbCount, cbCount,UserCards, cbUserCount, ListHit, FALSE);
  1637. HintSameCardCount_WithFindCount(cbCardData, cbCount, 3, UserCards, cbUserCount, ListHit);
  1638. HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
  1639. AllSameBomos(cbCardData, cbCount, 4, type, UserCards, cbUserCount, ListHit, TRUE);
  1640. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1641. Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1642. Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1643. break;
  1644. }
  1645. //连三张 或者叫飞机 555666777 最少9张
  1646. case CT_THREE_LINK:{
  1647. HintTHREE_LINK(cbCardData, cbCount, UserCards, cbUserCount, ListHit);
  1648. HintShunWithJoker(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit);
  1649. HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
  1650. AllSameBomos(cbCardData, cbCount,4, type, UserCards, cbUserCount, ListHit, TRUE);
  1651. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1652. Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1653. Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1654. break;
  1655. }
  1656. case CT_BOMB:{
  1657. lstCardsInfo.BomoInfo.Level = cbLevel;
  1658. BomoInfo.Level = cbLevel;
  1659. //4 5 6 7 8 都叫X相炸弹
  1660. //if (cbCount==4 )
  1661. //{
  1662. // HintBoom(cbCardData, cbCount, type, UserCards, cbUserCount, ListHit, TRUE);
  1663. //}
  1664. AllSameBomos(cbCardData, cbCount, cbCount,type, UserCards, cbUserCount, ListHit, TRUE);
  1665. //查找5-12线炸弹
  1666. HintBomoWithXian(cbCardData, cbCount, type,BomoInfo, UserCards, cbUserCount, ListHit);
  1667. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1668. Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1669. Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1670. break;
  1671. }
  1672. case CT_BOMB_3W:{
  1673. //3王炸 仅癞子玩法有此牌 最小的6线
  1674. GetAllSameCards(6, ListHit, tag);
  1675. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1676. break;
  1677. }
  1678. case CT_BOMB_TW:{
  1679. //天王炸 4个王 癞子算7线 非癞子 算最大牌(8线)
  1680. if (GetMagicType()==NoHaveMagic)
  1681. {
  1682. GetAllSameCards(9, ListHit, tag);
  1683. }
  1684. else
  1685. {
  1686. GetAllSameCards(8, ListHit, tag);
  1687. }
  1688. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1689. break;
  1690. }
  1691. case CT_BOMB_LINK:
  1692. case CT_BOMB_XIAN:
  1693. {
  1694. FindAllPaiBomoCards(tag, tagResult, lstCardsInfo, ListHit);
  1695. //根据当前线级别 找对应 同级别的
  1696. if (BomoInfo.Level<12)
  1697. {
  1698. GetAllSameCards(BomoInfo.Level, ListHit, tag);
  1699. }
  1700. Find3WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1701. Find4WBomo(cbCardData, cbCount, type, BomoInfo, tag, UserCards, cbUserCount, ListHit);
  1702. break;
  1703. }
  1704. }
  1705. //sort(ListHit.begin(), ListHit.end(), HitComp);
  1706. //vector 排序 根据牌的个数
  1707. if (ListHit.size()>0)
  1708. {
  1709. return TRUE;
  1710. }
  1711. return FALSE;
  1712. }
  1713. BOOL CGameLogic_Poker::HaveCanOutCard(BYTE cbCardLogicValue, BYTE SameCardCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  1714. {
  1715. tagDistributing tagDsit;
  1716. AnalysebDistributing(UserCards, cbUserCount, tagDsit);
  1717. for (int CardCount = SameCardCount; CardCount > 0; CardCount--){
  1718. //找逻辑值比他大的牌
  1719. for (int i = cbCardLogicValue - 3 + 1; i < 16; i++)
  1720. {
  1721. if (tagDsit.cbDistributing[i][5] >= CardCount)
  1722. {
  1723. HitStruct st;
  1724. st.cbCardType = CT_SINGLE;
  1725. st.cbHintLogicCardData[0] = GetCardLogicValue(UserCards[i]);
  1726. ListHit.push_back(st);
  1727. }
  1728. }
  1729. BYTE MagicCount = GetCardMagicCount(UserCards, cbUserCount);
  1730. if (MagicCount >= CardCount)
  1731. {
  1732. return TRUE;
  1733. }
  1734. for (int Count = MagicCount; Count > 0; Count--){
  1735. for (int i = cbCardLogicValue - 3 + 1; i < 16; i++)
  1736. {
  1737. if (tagDsit.cbDistributing[i][5] >= CardCount-Count)
  1738. {
  1739. return TRUE;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. return FALSE;
  1745. }
  1746. //构造扑克
  1747. BYTE CGameLogic_Poker::MakeCardData(BYTE cbValueIndex, BYTE cbColorIndex)
  1748. {
  1749. //构造扑克
  1750. switch (cbValueIndex)
  1751. {
  1752. case 11: //A 扑克
  1753. {
  1754. return (cbColorIndex<<4)|0x01;
  1755. }
  1756. case 12: //2 扑克
  1757. {
  1758. return (cbColorIndex<<4)|0x02;
  1759. }
  1760. case 13: //小鬼扑克
  1761. {
  1762. return (4<<4)|0x0E;
  1763. }
  1764. case 14: //大鬼扑克
  1765. {
  1766. return (4<<4)|0x0F;
  1767. }
  1768. default: //其他扑克
  1769. {
  1770. return (cbColorIndex<<4)|(cbValueIndex+3);
  1771. }
  1772. }
  1773. return 0x00;
  1774. }
  1775. //构造扑克
  1776. BYTE CGameLogic_Poker::MakeRealCardData(BYTE cbValueIndex, BYTE cbColorIndex)
  1777. {
  1778. //构造扑克
  1779. switch (cbValueIndex)
  1780. {
  1781. case 13: //小鬼扑克
  1782. {
  1783. return (4<<4)|0x0E;
  1784. }
  1785. case 14: //大鬼扑克
  1786. {
  1787. return (4<<4)|0x0F;
  1788. }
  1789. default: //其他扑克
  1790. {
  1791. return (cbColorIndex<<4)|(cbValueIndex+1);
  1792. }
  1793. }
  1794. return 0x00;
  1795. }
  1796. //是否连牌
  1797. bool CGameLogic_Poker::IsStructureLink(const BYTE cbCardData[], BYTE cbCardCount, BYTE cbCellCount,bool bSpecial)
  1798. {
  1799. //数目判断
  1800. ASSERT((cbCardCount%cbCellCount)==0);
  1801. if ((cbCardCount%cbCellCount)!=0) return false;
  1802. //变量定义
  1803. BYTE cbBlockCount=cbCardCount/cbCellCount;
  1804. BYTE cbFirstValue=GetCardLogicValue(cbCardData[0]);
  1805. if(bSpecial)
  1806. {
  1807. //特殊处理 2在连炸中
  1808. if (cbFirstValue==15)
  1809. {
  1810. for (BYTE i=1;i<cbBlockCount;i++)
  1811. {
  1812. //获取数值
  1813. BYTE cbLogicValue=GetCardLogicValue(cbCardData[i*cbCellCount]);
  1814. //连牌判断
  1815. if ((cbFirstValue!=(cbLogicValue+i))&&(cbFirstValue!=(cbLogicValue+i+(15-cbBlockCount-2)))) return false;
  1816. }
  1817. return true;
  1818. }
  1819. }
  1820. //大牌过滤
  1821. if(cbFirstValue>14) return false;
  1822. //分析处理
  1823. for (BYTE i=1;i<cbBlockCount;i++)
  1824. {
  1825. BYTE NextCardValue = (GetCardLogicValue(cbCardData[i*cbCellCount]) + i);
  1826. if (cbFirstValue != NextCardValue){
  1827. return false;
  1828. }
  1829. }
  1830. return true;
  1831. }
  1832. bool CGameLogic_Poker::IsStructureLink_zhengxu(const BYTE cbCardData[], BYTE cbCardCount, BYTE cbCellCount, bool bSpecial /*= false*/)
  1833. {
  1834. //数目判断
  1835. ASSERT((cbCardCount%cbCellCount) == 0);
  1836. if ((cbCardCount%cbCellCount) != 0) return false;
  1837. //变量定义
  1838. BYTE cbBlockCount = cbCardCount / cbCellCount;
  1839. BYTE cbFirstValue = GetCardLogicValue(cbCardData[0]);
  1840. if (bSpecial)
  1841. {
  1842. //特殊处理 2在连炸中
  1843. if (cbFirstValue == 15)
  1844. {
  1845. for (BYTE i = 1; i < cbBlockCount; i++)
  1846. {
  1847. //获取数值
  1848. BYTE cbLogicValue = GetCardLogicValue(cbCardData[i*cbCellCount]);
  1849. //连牌判断
  1850. if ((cbFirstValue != (cbLogicValue - i)) && (cbFirstValue != (cbLogicValue - i + (15 - cbBlockCount - 2))))
  1851. return false;
  1852. }
  1853. return true;
  1854. }
  1855. }
  1856. //大牌过滤
  1857. if (cbFirstValue > 14) return false;
  1858. //分析处理
  1859. for (BYTE i = 1; i < cbBlockCount; i++)
  1860. {
  1861. BYTE NextCardValue = (GetCardLogicValue(cbCardData[i*cbCellCount])-i );
  1862. if (cbFirstValue != NextCardValue){
  1863. return false;
  1864. }
  1865. }
  1866. return true;
  1867. }
  1868. void CGameLogic_Poker::HintSignle(const BYTE cbCardData[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  1869. {
  1870. tagDistributing tag;
  1871. AnalysebDistributing(UserCards, cbUserCount, tag);
  1872. BYTE cbLogicCardValue = GetCardLogicValue(cbCardData[0]);
  1873. //所有单牌 找到所有牌中的 单张
  1874. for (int j = 1; j <= 3;j++) // 优化后 单张 只从 1 2 3 张中寻找 [1/29/2019 Zoro]
  1875. {
  1876. for (int i = cbLogicCardValue - 3 + 1; i < 15; i++)
  1877. {
  1878. if (tag.cbDistributing[i][5] == j)
  1879. {
  1880. HitStruct st;
  1881. st.cbCardType = CT_SINGLE;
  1882. st.cbCardCount = 1;
  1883. st.cbHintLogicCardData[0] = TagIndexToNoColorCardValue(i + 3);
  1884. ListHit.push_back(st);
  1885. }
  1886. }
  1887. }
  1888. }
  1889. void CGameLogic_Poker::HintSameCardCount(const BYTE cbCardData[], BYTE cbCardDataCount, BYTE NeedFindCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit, BOOL IsAll)
  1890. {
  1891. tagDistributing tag;
  1892. AnalysebDistributing(UserCards, cbUserCount, tag);
  1893. BYTE cbLogicCardValue = 2;//应该是3 但是下面循环+1 了 所以写2
  1894. if (!IsAll)
  1895. {
  1896. cbLogicCardValue=GetCardLogicValue(cbCardData[0]);
  1897. }
  1898. for (int i = cbLogicCardValue - 3 + 1; i < 15; i++)
  1899. {
  1900. BOOL bPusthHisList = TRUE;
  1901. if (tag.cbDistributing[i][5] == NeedFindCount)
  1902. {
  1903. HitStruct st;
  1904. st.cbCardCount = NeedFindCount;
  1905. switch (NeedFindCount)
  1906. {
  1907. case 1:
  1908. st.cbCardType = CT_SINGLE;
  1909. break;
  1910. case 2:
  1911. st.cbCardType = CT_DOUBLE;
  1912. break;
  1913. case 3:
  1914. st.cbCardType = CT_THREE;
  1915. break;
  1916. case 4:
  1917. case 5:
  1918. case 6:
  1919. case 7:
  1920. case 8:
  1921. st.cbCardType = CT_BOMB;
  1922. break;
  1923. default:
  1924. break;
  1925. }
  1926. for (int j = 0; j< NeedFindCount; j++)
  1927. {
  1928. st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
  1929. }
  1930. //如果当前是炸弹,计算是否比上家的炸弹大
  1931. if (st.cbCardType==CT_BOMB)
  1932. {
  1933. BYTE cbLastLevel = 0;
  1934. BomoType LastBomo;
  1935. int nOldType=GetCardType(cbCardData, cbCardDataCount, cbLastLevel, LastBomo);
  1936. if (nOldType==CT_BOMB)
  1937. {
  1938. LastBomo.Level = cbLastLevel;
  1939. }
  1940. BYTE cbLevel=0;
  1941. BomoType BomoInfo;
  1942. int nNewType=GetCardType(st.cbHintLogicCardData, st.cbCardCount, cbLevel, BomoInfo);
  1943. if (nNewType == CT_BOMB)
  1944. {
  1945. BomoInfo.Level = cbLevel;
  1946. }
  1947. if (cbLevel>cbLastLevel)
  1948. {
  1949. bPusthHisList = TRUE;
  1950. }
  1951. else
  1952. {
  1953. if (cbLevel >= 4 && cbLastLevel >= 4)
  1954. {
  1955. bPusthHisList = CompareCardBigLastCards(LastBomo, (BYTE*)cbCardData, cbCardDataCount, BomoInfo, st.cbHintLogicCardData, st.cbCardCount);
  1956. }
  1957. }
  1958. }
  1959. if (bPusthHisList)
  1960. {
  1961. ListHit.push_back(st);
  1962. }
  1963. }
  1964. }
  1965. //计算magic 所处位置
  1966. BYTE cbCardMagic[4] = { 0 };
  1967. BYTE nMagicCount = GetMagicJokerCount(UserCards, cbUserCount,cbCardMagic);
  1968. for (BYTE NeedMagicConut = 1; NeedMagicConut <= nMagicCount;NeedMagicConut++)
  1969. {
  1970. int MaxIndex = 13;
  1971. for (int i = cbLogicCardValue - 3 + 1; i < MaxIndex; i++)
  1972. {
  1973. BOOL bPusthHisList = TRUE;
  1974. if (tag.cbDistributing[i][5] != 0 && tag.cbDistributing[i][5] == NeedFindCount - NeedMagicConut && (NoJokerBigUserCards(i, tag.cbDistributing[i][5], cbCardData, cbCardDataCount) == FALSE || ListHit.size()==0))
  1975. {
  1976. HitStruct st;
  1977. st.cbCardCount = NeedFindCount;
  1978. switch (NeedFindCount)
  1979. {
  1980. case 1:
  1981. st.cbCardType = CT_SINGLE;
  1982. break;
  1983. case 2:
  1984. st.cbCardType = CT_DOUBLE;
  1985. break;
  1986. case 3:
  1987. st.cbCardType = CT_THREE;
  1988. break;
  1989. case 4:
  1990. case 5:
  1991. case 6:
  1992. case 7:
  1993. case 8:
  1994. st.cbCardType = CT_BOMB;
  1995. break;
  1996. default:
  1997. break;
  1998. }
  1999. BYTE cbReplacedCards[MAX_COUNT_Poker] = { 0 };
  2000. for (int j = 0; j < NeedFindCount - NeedMagicConut; j++)
  2001. {
  2002. st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);
  2003. cbReplacedCards[j] = TagIndexToNoColorCardValue(i + 3);
  2004. }
  2005. BYTE WithMagicCount = 0;
  2006. for (int magicindex = NeedFindCount - NeedMagicConut; magicindex < NeedFindCount; magicindex++)
  2007. {
  2008. st.cbHintLogicCardData[magicindex] = GetCardLogicValue(cbCardMagic[WithMagicCount]);
  2009. cbReplacedCards[magicindex] = TagIndexToNoColorCardValue(i + 3);
  2010. WithMagicCount++;
  2011. }
  2012. //如果当前是炸弹,计算是否比上家的炸弹大
  2013. // if (st.cbCardType == CT_BOMB)
  2014. // {
  2015. // BYTE NoColorCardValue = i + 3;
  2016. // BYTE LastCard = GetCardLogicValue(cbCardData[0]);
  2017. // if (NoColorCardValue<=LastCard)
  2018. // {
  2019. // bPusthHisList = FALSE;
  2020. // }
  2021. // }
  2022. //如果当前是炸弹,计算是否比上家的炸弹大
  2023. if (st.cbCardType == CT_BOMB)
  2024. {
  2025. BYTE cbLastLevel = 0;
  2026. BomoType LastBomo;
  2027. int nOldType = GetCardType(cbCardData, cbCardDataCount, cbLastLevel, LastBomo);
  2028. if (nOldType == CT_BOMB)
  2029. {
  2030. LastBomo.Level = cbLastLevel;
  2031. }
  2032. BYTE cbLevel = 0;
  2033. BomoType BomoInfo;
  2034. int nNewType = GetCardType(cbReplacedCards, st.cbCardCount, cbLevel, BomoInfo);
  2035. if (nNewType == CT_BOMB)
  2036. {
  2037. BomoInfo.Level = cbLevel;
  2038. }
  2039. if (cbLevel>cbLastLevel)
  2040. {
  2041. bPusthHisList = TRUE;
  2042. }
  2043. else
  2044. {
  2045. if (cbLevel >= 4 && cbLastLevel >= 4)
  2046. {
  2047. bPusthHisList = CompareCardBigLastCards(LastBomo, (BYTE*)cbCardData, cbCardDataCount, BomoInfo, cbReplacedCards, st.cbCardCount);
  2048. }
  2049. }
  2050. }
  2051. if (bPusthHisList)
  2052. {
  2053. ListHit.push_back(st);
  2054. }
  2055. }
  2056. }
  2057. }
  2058. }
  2059. void CGameLogic_Poker::HintSameCardCount_WithFindCount(const BYTE cbCardData[], BYTE cbCount, BYTE nFindCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2060. {
  2061. tagDistributing tag;
  2062. AnalysebDistributing(UserCards, cbUserCount, tag);
  2063. BYTE cbLogicCardValue = GetCardLogicValue(cbCardData[0]);
  2064. for (int Count = nFindCount; Count <= 8; Count++){
  2065. for (int i = cbLogicCardValue - 3 + 1; i < 15; i++)
  2066. {
  2067. if (tag.cbDistributing[i][5] > Count&&tag.cbDistributing[i][5]<4)
  2068. {
  2069. HitStruct st;
  2070. st.cbCardCount = Count;
  2071. switch (Count)
  2072. {
  2073. case 1:
  2074. st.cbCardType = CT_SINGLE;
  2075. break;
  2076. case 2:
  2077. st.cbCardType = CT_DOUBLE;
  2078. break;
  2079. case 3:
  2080. st.cbCardType = CT_THREE;
  2081. break;
  2082. case 4:
  2083. case 5:
  2084. case 6:
  2085. case 7:
  2086. case 8:
  2087. st.cbCardType = CT_BOMB;
  2088. break;
  2089. default:
  2090. break;
  2091. }
  2092. if (Count == 3 && cbCount==2)
  2093. {
  2094. continue;
  2095. }
  2096. for (int j = 0; j < Count; j++)
  2097. {
  2098. st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
  2099. }
  2100. ListHit.push_back(st);
  2101. }
  2102. }
  2103. }
  2104. //计算magic 所处位置
  2105. BYTE cbCardMagic[4] = { 0 };
  2106. BYTE nMagicCount = GetMagicJokerCount(UserCards, cbUserCount, cbCardMagic);
  2107. for (int Count = nFindCount; Count <= 8; Count++){
  2108. for (BYTE NeedMagicConut = 1; NeedMagicConut <= nMagicCount; NeedMagicConut++)
  2109. {
  2110. for (int i = cbLogicCardValue - 3 + 1; i < 13; i++)
  2111. {
  2112. if (tag.cbDistributing[i][5] == Count - NeedMagicConut&&tag.cbDistributing[i][5] != 0 && tag.cbDistributing[i][5]<4)
  2113. {
  2114. HitStruct st;
  2115. st.cbCardCount = cbCount;
  2116. switch (cbCount)
  2117. {
  2118. case 1:
  2119. st.cbCardType = CT_SINGLE;
  2120. break;
  2121. case 2:
  2122. st.cbCardType = CT_DOUBLE;
  2123. break;
  2124. case 3:
  2125. st.cbCardType = CT_THREE;
  2126. break;
  2127. case 4:
  2128. case 5:
  2129. case 6:
  2130. case 7:
  2131. case 8:
  2132. st.cbCardType = CT_BOMB;
  2133. break;
  2134. default:
  2135. break;
  2136. }
  2137. for (int j = 0; j < cbCount - NeedMagicConut; j++)
  2138. {
  2139. st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
  2140. }
  2141. BYTE WithMagicCount = 0;
  2142. for (int magicindex = cbCount - NeedMagicConut; magicindex < cbCount; magicindex++)
  2143. {
  2144. st.cbHintLogicCardData[magicindex] = GetCardLogicValue(cbCardMagic[WithMagicCount++]);
  2145. }
  2146. ListHit.push_back(st);
  2147. }
  2148. }
  2149. }
  2150. }
  2151. }
  2152. void CGameLogic_Poker::HintDOUBLE_LINK(const BYTE cbCardData[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2153. {
  2154. cbCount = cbCount / 2;
  2155. if (cbUserCount < cbCount)
  2156. {
  2157. return;
  2158. }
  2159. BYTE szcbCardData[MAX_COUNT_Poker] = { 0 };
  2160. CopyMemory(szcbCardData, cbCardData, cbCount*2);
  2161. SortCardList(szcbCardData, cbCount*2, ST_ORDER, ORDERBY_ASE);
  2162. BYTE MinCardLogic = GetCardLogicValue(szcbCardData[0]);
  2163. BYTE szTmpUserCards[MAX_COUNT_Poker] = { 0 };
  2164. CopyMemory(szTmpUserCards, UserCards, cbUserCount);
  2165. SortCardList(szTmpUserCards, cbUserCount, ST_ORDER, ORDERBY_ASE);
  2166. tagDistributing tag;
  2167. AnalysebDistributing(szTmpUserCards, cbUserCount, tag);
  2168. BYTE OneCardArray[MAX_COUNT_Poker] = { 0 };
  2169. BYTE OneCardCount = 0;
  2170. //顺子 2不能再其中 所以12 即可
  2171. for (int i = 0; i < 12; i++)
  2172. {
  2173. if (tag.cbDistributing[i][5] >= 2)
  2174. {
  2175. if (MinCardLogic >= i + 3)
  2176. {
  2177. continue;
  2178. }
  2179. OneCardArray[OneCardCount++] = TagIndexToNoColorCardValue(i + 3);;
  2180. }
  2181. }
  2182. if (OneCardCount < cbCount)
  2183. {
  2184. return;
  2185. }
  2186. vector<vector<BYTE>> vShunNoJoker;
  2187. SortCardList(OneCardArray, OneCardCount, ST_ORDER, ORDERBY_ASE);
  2188. FindShunZI(OneCardArray, OneCardCount, cbCount, vShunNoJoker);
  2189. if (vShunNoJoker.size()>0)
  2190. {
  2191. vector<vector<BYTE>>::iterator oneSt = vShunNoJoker.begin();
  2192. for (; oneSt != vShunNoJoker.end(); oneSt++)
  2193. {
  2194. HitStruct hit;
  2195. hit.cbCardCount = cbCount;
  2196. hit.cbCardType = CT_DOUBLE_LINK;
  2197. for (int i = 0; i < hit.cbCardCount; i++)
  2198. {
  2199. hit.cbHintLogicCardData[hit.cbCardCount - i - 1] = (*oneSt)[i];
  2200. hit.cbHintLogicCardData[2*hit.cbCardCount - i - 1] = (*oneSt)[i];
  2201. }
  2202. hit.cbCardCount = cbCount*2;
  2203. SortCardList(hit.cbHintLogicCardData, hit.cbCardCount, ST_ORDER, ORDERBY_ASE);
  2204. ListHit.push_back(hit);
  2205. }
  2206. }
  2207. }
  2208. void CGameLogic_Poker::HintTHREE_LINK(const BYTE cbCardData[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2209. {
  2210. cbCount = cbCount / 3;
  2211. if (cbUserCount < cbCount)
  2212. {
  2213. return;
  2214. }
  2215. BYTE szcbCardData[MAX_COUNT_Poker] = { 0 };
  2216. CopyMemory(szcbCardData, cbCardData, cbCount * 3);
  2217. SortCardList(szcbCardData, cbCount * 3, ST_ORDER, ORDERBY_ASE);
  2218. BYTE MinCardLogic = GetCardLogicValue(szcbCardData[0]);
  2219. BYTE szTmpUserCards[MAX_COUNT_Poker] = { 0 };
  2220. CopyMemory(szTmpUserCards, UserCards, cbUserCount);
  2221. SortCardList(szTmpUserCards, cbUserCount, ST_ORDER, ORDERBY_ASE);
  2222. tagDistributing tag;
  2223. AnalysebDistributing(szTmpUserCards, cbUserCount, tag);
  2224. BYTE OneCardArray[MAX_COUNT_Poker] = { 0 };
  2225. BYTE OneCardCount = 0;
  2226. //顺子 2不能再其中 所以12 即可
  2227. for (int i = 0; i < 12; i++)
  2228. {
  2229. if (tag.cbDistributing[i][5] >= 3)
  2230. {
  2231. if (MinCardLogic >= i + 3)
  2232. {
  2233. continue;
  2234. }
  2235. OneCardArray[OneCardCount++] = TagIndexToNoColorCardValue(i + 3);;
  2236. }
  2237. }
  2238. if (OneCardCount < cbCount)
  2239. {
  2240. return;
  2241. }
  2242. vector<vector<BYTE>> vShunNoJoker;
  2243. SortCardList(OneCardArray, OneCardCount, ST_ORDER, ORDERBY_ASE);
  2244. FindShunZI(OneCardArray, OneCardCount, cbCount, vShunNoJoker);
  2245. if (vShunNoJoker.size()>0)
  2246. {
  2247. vector<vector<BYTE>>::iterator oneSt = vShunNoJoker.begin();
  2248. for (; oneSt != vShunNoJoker.end(); oneSt++)
  2249. {
  2250. HitStruct hit;
  2251. hit.cbCardCount = cbCount;
  2252. hit.cbCardType = CT_THREE_LINK;
  2253. for (int i = 0; i < hit.cbCardCount; i++)
  2254. {
  2255. hit.cbHintLogicCardData[hit.cbCardCount - i - 1] = (*oneSt)[i];
  2256. hit.cbHintLogicCardData[2 * hit.cbCardCount - i - 1] = (*oneSt)[i];
  2257. hit.cbHintLogicCardData[3 * hit.cbCardCount - i - 1] = (*oneSt)[i];
  2258. }
  2259. hit.cbCardCount = cbCount * 3;
  2260. SortCardList(hit.cbHintLogicCardData, hit.cbCardCount, ST_ORDER, ORDERBY_ASE);
  2261. ListHit.push_back(hit);
  2262. }
  2263. }
  2264. }
  2265. //顺子
  2266. void CGameLogic_Poker::HintSHUNZI(const BYTE cbCardData[], BYTE cbCount, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2267. {
  2268. if (cbUserCount<cbCount)
  2269. {
  2270. return;
  2271. }
  2272. BYTE szcbCardData[MAX_COUNT_Poker] = { 0 };
  2273. CopyMemory(szcbCardData, cbCardData, cbCount);
  2274. SortCardList(szcbCardData, cbCount, ST_ORDER, ORDERBY_ASE);
  2275. BYTE MinCardLogic = GetCardLogicValue(szcbCardData[0]);
  2276. BYTE szTmpUserCards[MAX_COUNT_Poker] = { 0 };
  2277. CopyMemory(szTmpUserCards, UserCards, cbUserCount);
  2278. SortCardList(szTmpUserCards, cbUserCount, ST_ORDER, ORDERBY_ASE);
  2279. tagDistributing tag;
  2280. AnalysebDistributing(szTmpUserCards, cbUserCount, tag);
  2281. BYTE OneCardArray[MAX_COUNT_Poker] = { 0 };
  2282. BYTE OneCardCount = 0;
  2283. //顺子 2不能再其中 所以12 即可
  2284. for (int i = 0; i < 12;i++)
  2285. {
  2286. if (tag.cbDistributing[i][5] != 0)
  2287. {
  2288. if (MinCardLogic>=i+3)
  2289. {
  2290. continue;
  2291. }
  2292. OneCardArray[OneCardCount++] = TagIndexToNoColorCardValue(i + 3);;
  2293. }
  2294. }
  2295. if (OneCardCount<cbCount)
  2296. {
  2297. return;
  2298. }
  2299. vector<vector<BYTE>> vShunNoJoker;
  2300. SortCardList(OneCardArray, OneCardCount, ST_ORDER, ORDERBY_ASE);
  2301. FindShunZI(OneCardArray, OneCardCount, cbCount, vShunNoJoker);
  2302. if (vShunNoJoker.size()>0)
  2303. {
  2304. vector<vector<BYTE>>::iterator oneSt = vShunNoJoker.begin();
  2305. for (; oneSt!=vShunNoJoker.end();oneSt++)
  2306. {
  2307. HitStruct hit;
  2308. hit.cbCardCount = cbCount;
  2309. hit.cbCardType = CT_SHUNZI;
  2310. for (int i = 0; i <hit.cbCardCount; i++)
  2311. {
  2312. hit.cbHintLogicCardData[hit.cbCardCount-i-1] = (*oneSt)[i];
  2313. }
  2314. ListHit.push_back(hit);
  2315. }
  2316. }
  2317. }
  2318. void CGameLogic_Poker::HintBoom(const BYTE cbCardData[], BYTE cbCount, BYTE cbCardType, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit,BOOL WithJoker)
  2319. {
  2320. tagDistributing tag;
  2321. AnalysebDistributing(UserCards, cbUserCount, tag);
  2322. BYTE cbLogicCardValue = GetCardLogicValue(cbCardData[0]);
  2323. int FromIndex = 0;
  2324. if (cbCardType<7)
  2325. {
  2326. FromIndex = 0;
  2327. }
  2328. else
  2329. {
  2330. if (cbCount!=4)
  2331. {
  2332. //OutputDebugString(L"HintBoom 只处理4张的炸 和小牌");
  2333. return;
  2334. }
  2335. FromIndex = cbLogicCardValue - 3 + 1;
  2336. }
  2337. for (int i = FromIndex; i < 13; i++)
  2338. {
  2339. BYTE ThisCardCount = tag.cbDistributing[i][5];
  2340. if (ThisCardCount == 4)
  2341. {
  2342. HitStruct st;
  2343. st.cbCardCount = ThisCardCount;
  2344. st.cbCardType = CT_BOMB;
  2345. for (int j = 0; j < ThisCardCount; j++)
  2346. {
  2347. st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
  2348. }
  2349. ListHit.push_back(st);
  2350. }
  2351. }
  2352. //如果带王 则找到 需要1个王 2个王 三个王 4个王的
  2353. BYTE MagicCount=0;
  2354. if (WithJoker)
  2355. {
  2356. BYTE MagicCards[4] = { 0 };
  2357. BYTE ReplaceConut = 0;
  2358. MagicCount = GetMagicJokerCount(UserCards, cbUserCount, MagicCards);
  2359. if (MagicCount>3)
  2360. {
  2361. return;
  2362. }
  2363. for (int JokerCount = 1; JokerCount <= MagicCount;JokerCount++)
  2364. {
  2365. for (int i = FromIndex; i < 13; i++)
  2366. {
  2367. ReplaceConut = 0;
  2368. BYTE ThisCardCount = tag.cbDistributing[i][5];
  2369. if (ThisCardCount + JokerCount == 4/* && (i + 3)>cbLogicCardValue*/)
  2370. {
  2371. HitStruct st;
  2372. st.cbCardCount = ThisCardCount + JokerCount;
  2373. st.cbCardType = CT_BOMB;
  2374. for (int j = 0; j < ThisCardCount; j++)
  2375. {
  2376. st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
  2377. }
  2378. for (int lastIndex = 4 - JokerCount; lastIndex < 4; lastIndex++)
  2379. {
  2380. st.cbHintLogicCardData[lastIndex] = GetCardLogicValue(MagicCards[ReplaceConut++]);
  2381. }
  2382. ListHit.push_back(st);
  2383. }
  2384. }
  2385. }
  2386. }
  2387. }
  2388. void CGameLogic_Poker::AllSameBomos(const BYTE cbCardData[], BYTE cbCount, BYTE FromIndex,BYTE cbCardType, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit, BOOL WithJoker)
  2389. {
  2390. for (int i = FromIndex; i < 14; i++)
  2391. {
  2392. if (i==0)
  2393. {
  2394. continue;
  2395. }
  2396. HintSameCardCount(cbCardData, cbCount, i, UserCards, cbUserCount, ListHit, TRUE);
  2397. }
  2398. }
  2399. void CGameLogic_Poker::HintBomoWithXian(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType BomoInfo, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2400. {
  2401. //如果上家出的牌不是炸弹 则 直接从0找 5-12线炸弹
  2402. tagDistributing tag;
  2403. AnalysebDistributing(UserCards, cbUserCount, tag);
  2404. tagAnalyseResult_Poker tagResult;
  2405. AnalysebCardData(UserCards, cbUserCount, tagResult);
  2406. if (cbCount<6)
  2407. {
  2408. FindAll5XianBomo(cbCardData, cbCount, type, BomoInfo, tag, tagResult, ListHit, UserCards, cbUserCount);
  2409. }
  2410. }
  2411. void CGameLogic_Poker::HintBomoWithLian(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType BomoInfo, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2412. {
  2413. cbCount = cbCount / BomoInfo.tong;
  2414. if (cbUserCount < cbCount)
  2415. {
  2416. return;
  2417. }
  2418. BYTE szcbCardData[MAX_COUNT_Poker] = { 0 };
  2419. CopyMemory(szcbCardData, cbCardData, cbCount * BomoInfo.tong);
  2420. SortCardList(szcbCardData, cbCount * BomoInfo.tong, ST_ORDER, ORDERBY_ASE);
  2421. BYTE MinCardLogic = GetCardLogicValue(szcbCardData[0]);
  2422. BYTE szTmpUserCards[MAX_COUNT_Poker] = { 0 };
  2423. CopyMemory(szTmpUserCards, UserCards, cbUserCount);
  2424. SortCardList(szTmpUserCards, cbUserCount, ST_ORDER, ORDERBY_ASE);
  2425. tagDistributing tag;
  2426. AnalysebDistributing(szTmpUserCards, cbUserCount, tag);
  2427. BYTE OneCardArray[MAX_COUNT_Poker] = { 0 };
  2428. BYTE OneCardCount = 0;
  2429. //顺子 2不能再其中 所以12 即可
  2430. for (int i = 0; i < 12; i++)
  2431. {
  2432. if (tag.cbDistributing[i][5] >= BomoInfo.tong)
  2433. {
  2434. if (MinCardLogic >= i + BomoInfo.tong)
  2435. {
  2436. continue;
  2437. }
  2438. OneCardArray[OneCardCount++] = TagIndexToNoColorCardValue(i + 3);
  2439. }
  2440. }
  2441. if (OneCardCount < cbCount)
  2442. {
  2443. return;
  2444. }
  2445. vector<vector<BYTE>> vShunNoJoker;
  2446. SortCardList(OneCardArray, OneCardCount, ST_ORDER, ORDERBY_ASE);
  2447. FindShunZI(OneCardArray, OneCardCount, cbCount, vShunNoJoker);
  2448. if (vShunNoJoker.size()>0)
  2449. {
  2450. vector<vector<BYTE>>::iterator oneSt = vShunNoJoker.begin();
  2451. for (; oneSt != vShunNoJoker.end(); oneSt++)
  2452. {
  2453. HitStruct hit;
  2454. hit.cbCardCount = cbCount;
  2455. hit.cbCardType = CT_BOMB_LINK;
  2456. for (int i = 0; i < hit.cbCardCount; i++)
  2457. {
  2458. for (int j = 1; j <= BomoInfo.tong;j++)
  2459. {
  2460. hit.cbHintLogicCardData[j*hit.cbCardCount - i - 1] = (*oneSt)[i];
  2461. }
  2462. }
  2463. hit.cbCardCount = cbCount * BomoInfo.tong;
  2464. SortCardList(hit.cbHintLogicCardData, hit.cbCardCount, ST_ORDER, ORDERBY_ASE);
  2465. ListHit.push_back(hit);
  2466. }
  2467. }
  2468. }
  2469. BYTE CGameLogic_Poker::GetMagicJokerCount(const BYTE cbCardData[], BYTE cbCount,BYTE cbMagicCards[4])
  2470. {
  2471. BYTE MagicJokerCount = 0;
  2472. for (int i = 0; i < cbCount;i++)
  2473. {
  2474. if (CardIsMagicJoker(cbCardData[i]))
  2475. {
  2476. cbMagicCards[MagicJokerCount++] = cbCardData[i];
  2477. }
  2478. }
  2479. return MagicJokerCount;
  2480. }
  2481. BYTE CGameLogic_Poker::GetMagicJokerCount(tagDistributing tag, BYTE MagicCards[4])
  2482. {
  2483. BYTE MagicType = GetMagicType();
  2484. //BYTE nCount = tag.cbDistributing[13][5] + tag.cbDistributing[14][5];
  2485. BYTE magicCount = 0;
  2486. if (MagicType==OneMagicMode)
  2487. {
  2488. for (int i = 0; i < tag.cbDistributing[14][5]; i++)
  2489. {
  2490. MagicCards[magicCount++] = 0x4f;
  2491. }
  2492. }
  2493. if (MagicType==TwoMagicMode)
  2494. {
  2495. for (int i = 0; i < tag.cbDistributing[13][5]; i++)
  2496. {
  2497. MagicCards[magicCount++] = 0x4e;
  2498. }
  2499. for (int i = 0; i < tag.cbDistributing[14][5]; i++)
  2500. {
  2501. MagicCards[magicCount++] = 0x4f;
  2502. }
  2503. }
  2504. return magicCount;
  2505. }
  2506. BOOL CGameLogic_Poker::CardIsMagicJoker(BYTE cbCard)
  2507. {
  2508. BYTE MagicType= GetMagicType();
  2509. if (MagicType==OneMagicMode)
  2510. {
  2511. if (cbCard==0x4f)
  2512. {
  2513. return TRUE;
  2514. }
  2515. }
  2516. else if (MagicType==TwoMagicMode)
  2517. {
  2518. if (cbCard==0x4e ||cbCard==0x4f)
  2519. {
  2520. return TRUE;
  2521. }
  2522. }
  2523. return FALSE;
  2524. }
  2525. BOOL CGameLogic_Poker::FindSameXianBomo(const BYTE cbCardData[], BYTE cbCount, BomoType bomoinfo, tagDistributing tagDsit, std::vector<HitStruct> &ListHit)
  2526. {
  2527. int BomoIndex = 0;
  2528. if (bomoinfo.BomoTypes == 0)
  2529. {
  2530. BYTE cbLogicCardValue = GetCardLogicValue(cbCardData[0]);
  2531. BomoIndex = cbLogicCardValue - 3 + 1;
  2532. }
  2533. //5线 正规5张一样的
  2534. for (BYTE i = BomoIndex; i < 13; i++)
  2535. {
  2536. BYTE cbCardCount = tagDsit.cbDistributing[i][5];
  2537. if (cbCardCount == 5)
  2538. {
  2539. HitStruct st;
  2540. st.cbCardCount = cbCardCount;
  2541. st.cbCardType = CT_BOMB;
  2542. for (int j = 0; j < cbCardCount; j++)
  2543. {
  2544. st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(i + 3);;
  2545. }
  2546. ListHit.push_back(st);
  2547. }
  2548. }
  2549. return TRUE;
  2550. }
  2551. BOOL CGameLogic_Poker::FindSameXianBomoWithJoker(const BYTE cbCardData[], BYTE cbCount,BYTE xian, BYTE type, BomoType bomoinfo, tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, std::vector<HitStruct> &ListHit)
  2552. {
  2553. BYTE cbCards[4] = { 0 };
  2554. BYTE nMagicCount = GetMagicJokerCount(tagDsit, cbCards);
  2555. for (int i = 0; i < 11;i++)
  2556. {
  2557. for (int j = 0; j < 27;j++)
  2558. {
  2559. if (tagReslt.cbCardData[i][j]==0x4e||tagReslt.cbCardData[i][j]==0x4f)
  2560. {
  2561. tagReslt.cbCardData[i][j] = 0;
  2562. }
  2563. }
  2564. BYTE cbTmpCardData[MAX_COUNT_Poker] = { 0 };
  2565. BYTE cbTmpCardCount = 0;
  2566. for (int CarCount = 0; CarCount < 27; CarCount++)
  2567. {
  2568. if (tagReslt.cbCardData[i][CarCount] != 0)
  2569. {
  2570. cbTmpCardData[cbTmpCardCount++] = tagReslt.cbCardData[i][CarCount];
  2571. }
  2572. }
  2573. if (cbTmpCardCount > 0)
  2574. {
  2575. ZeroMemory(tagReslt.cbCardData[i], MAX_COUNT_Poker);
  2576. memcpy(tagReslt.cbCardData[i], cbTmpCardData, cbTmpCardCount);
  2577. }
  2578. }
  2579. //带王的 五张
  2580. BYTE cbMaxCardCount = xian;
  2581. for (BYTE CurrentMagicCount = 1; CurrentMagicCount <= nMagicCount; CurrentMagicCount++)
  2582. {
  2583. byte cbFinSameCount = cbMaxCardCount - CurrentMagicCount;
  2584. //4张同牌的 一共有多少
  2585. BYTE cbZuHeCount = tagReslt.cbBlockCount[cbFinSameCount - 1];
  2586. for (int OneCard = 0; OneCard < cbZuHeCount; OneCard++)
  2587. {
  2588. if (type == CT_BOMB)
  2589. {
  2590. BYTE cbCard = GetCardLogicValue(tagReslt.cbCardData[cbFinSameCount - 1][OneCard * cbFinSameCount]);
  2591. BYTE LastCard = GetCardLogicValue(cbCardData[0]);
  2592. if (cbCard < LastCard)
  2593. {
  2594. continue;
  2595. }
  2596. }
  2597. HitStruct st;
  2598. st.cbCardCount = cbMaxCardCount;
  2599. st.cbCardType = CT_BOMB;
  2600. for (int j = 0; j < cbMaxCardCount - CurrentMagicCount; j++)
  2601. {
  2602. st.cbHintLogicCardData[j] = TagIndexToNoColorCardValue(GetCardLogicValue(tagReslt.cbCardData[cbFinSameCount - 1][OneCard * cbFinSameCount + j]));
  2603. }
  2604. for (int j = 1; j <= CurrentMagicCount; j++)
  2605. {
  2606. st.cbHintLogicCardData[cbMaxCardCount - j] = TagIndexToNoColorCardValue(GetCardLogicValue(cbCards[j - 1]));
  2607. }
  2608. ListHit.push_back(st);
  2609. }
  2610. }
  2611. return TRUE;
  2612. }
  2613. BOOL CGameLogic_Poker::Find4Fu4xian(const BYTE cbCardData[], BYTE cbCount, BYTE xian, BYTE type, BomoType bomoinfo, tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, std::vector<HitStruct> &ListHit)
  2614. {
  2615. //5线 正规 4付4线
  2616. BYTE cbMaxCardLogicValue = 0;
  2617. if (bomoinfo.BomoTypes == BomoTypeXian)
  2618. {
  2619. //要比较我方是否有比对方最大值还大的 线牌
  2620. cbMaxCardLogicValue = GetMaxLogicValue(cbCardData,cbCount);
  2621. }
  2622. //保存无花色 牌的逻辑值
  2623. BYTE cbBomoCards[16] = { 0 };
  2624. BYTE cbBomoCardCount = 0;
  2625. for (BYTE i = 0; i < 13; i++)
  2626. {
  2627. BYTE cbCardCount = tagDsit.cbDistributing[i][5];
  2628. if (cbCardCount >= 4)
  2629. {
  2630. cbBomoCards[cbBomoCardCount++] = TagIndexToNoColorCardValue(i + 3);;
  2631. }
  2632. }
  2633. //进行排列组合
  2634. if (cbMaxCardLogicValue!=0)
  2635. {
  2636. BOOL bFind = FALSE;//是否有比上家4f4线大的牌
  2637. for (int i = 0; i < 16; i++ )
  2638. {
  2639. if (cbBomoCards[i]==0)
  2640. {
  2641. break;
  2642. }
  2643. if (cbBomoCards[i]>cbMaxCardLogicValue)
  2644. {
  2645. bFind = TRUE;
  2646. break;
  2647. }
  2648. }
  2649. if (bFind==FALSE)
  2650. {
  2651. return FALSE;
  2652. }
  2653. //现在比上次最大的牌大的 有了。
  2654. vector<vector<BYTE>> allHits = CardSecret(cbBomoCards, cbBomoCardCount, 4, cbMaxCardLogicValue);
  2655. vector<vector<BYTE>>::iterator it = allHits.begin();
  2656. for (it; it!=allHits.end();it++)
  2657. {
  2658. HitStruct st;
  2659. st.cbCardCount = 4 * 4;
  2660. st.cbCardType = CT_BOMB_XIAN;
  2661. BYTE CardIndex = 0;
  2662. vector<BYTE>::iterator OneValue = it->begin();
  2663. for (; OneValue != it->end(); OneValue++)
  2664. {
  2665. //将4个值赋值到st中
  2666. for (BYTE index = 0; index < 4; index++)
  2667. {
  2668. st.cbHintLogicCardData[CardIndex * 4 + index] = *OneValue;
  2669. }
  2670. CardIndex++;
  2671. }
  2672. //不是连排 可以加入 连排 让后面的处理 不属于5线
  2673. if (IsStructureLink(st.cbHintLogicCardData, st.cbCardCount, 4) == FALSE)
  2674. {
  2675. ListHit.push_back(st);
  2676. }
  2677. }
  2678. }
  2679. return TRUE;
  2680. }
  2681. //根据手牌
  2682. BOOL CGameLogic_Poker::Find4Fu4xianWithJoker(const BYTE cbCardData[], BYTE cbCount, BYTE xian, BYTE type, BomoType bomoinfo, tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, std::vector<HitStruct> &ListHit)
  2683. {
  2684. BYTE FindFu = 4;
  2685. BYTE cbMagicData[4] = { 0 };
  2686. BYTE cbMaxMagicCount = GetMagicJokerCount(tagDsit, cbMagicData);
  2687. BYTE cbMaxCardLogicValue = 0;
  2688. if (bomoinfo.BomoTypes!=0)
  2689. {
  2690. cbMaxCardLogicValue = GetMaxLogicValue(cbCardData, cbCount);
  2691. }
  2692. if (tagDsit.cbCardCount<16)
  2693. {
  2694. return FALSE;
  2695. }
  2696. // 取消掉0张牌的。
  2697. BYTE cbIndex[MAX_COUNT_Poker] = { 0 };
  2698. BYTE cbIndexCount = 0;
  2699. for (int i = 0; i < 13;i++)
  2700. {
  2701. if (tagDsit.cbDistributing[i][5]==0)
  2702. {
  2703. continue;
  2704. }
  2705. cbIndex[cbIndexCount++] = i;
  2706. }
  2707. //然后所有牌进行4张的排列组合。
  2708. vector<vector<BYTE>> AllHitsIndex = CardSecret(cbIndex, cbIndexCount, 4, 0);
  2709. //写一个函数 查看其4种牌的组合+王 是否能够组成4付4线
  2710. //oneHitIndex(vector<BYTE> vIndex,tagDistributing tagDsit,std::vector<HitStruct> &ListHit);
  2711. vector<vector<BYTE>>::iterator OneItem = AllHitsIndex.begin();
  2712. for (; OneItem != AllHitsIndex.end();OneItem++)
  2713. {
  2714. if (cbCount==5)
  2715. {
  2716. BOOL bCanNext = FALSE;
  2717. //判定4付4线中最大的牌 是否大于当前玩家的牌
  2718. BYTE CbCard = cbCardData[0];
  2719. BYTE CardLogicValue = GetCardLogicValue(CbCard);
  2720. for (int i = 0; i < 4; i++){
  2721. if ((*OneItem)[i] + 3>CardLogicValue)
  2722. {
  2723. bCanNext = TRUE;
  2724. break;
  2725. }
  2726. }
  2727. if (bCanNext==FALSE)
  2728. {
  2729. continue;
  2730. }
  2731. }
  2732. //组合后 将牌大于4张的变为4张。
  2733. //然后根据每个组合确认癞子牌是否足够
  2734. //足够的 将癞子牌替换之
  2735. CanZuCheng44(*OneItem, tagDsit, ListHit);
  2736. }
  2737. return TRUE;
  2738. }
  2739. BOOL CGameLogic_Poker::CanZuCheng44(vector<BYTE> vIndex, tagDistributing tagDsitA, std::vector<HitStruct> &ListHit)
  2740. {
  2741. tagDistributing tagDsit ;
  2742. CopyMemory(&tagDsit, &tagDsitA, sizeof(tagDistributing));
  2743. int nCont = vIndex.size();
  2744. int nAllCardCount=0;
  2745. for (int i = 0; i < nCont;i++)
  2746. {
  2747. int nTmpCount = tagDsit.cbDistributing[vIndex[i]][5];
  2748. if (nTmpCount>=4)
  2749. {
  2750. nTmpCount = 4;
  2751. }
  2752. nAllCardCount += nTmpCount;
  2753. }
  2754. if (nAllCardCount==16)
  2755. {
  2756. //无需癞子的 忽略
  2757. return TRUE;
  2758. }
  2759. if (GetMagicType()==MagicMode::NoHaveMagic)
  2760. {
  2761. return FALSE;
  2762. }
  2763. int AllMagicCount = 0;
  2764. for (int i = 0; i < 2;i++)
  2765. {
  2766. int nTmpCount = tagDsit.cbDistributing[13+i][5];
  2767. AllMagicCount += nTmpCount;
  2768. }
  2769. if (nAllCardCount + AllMagicCount<16)
  2770. {
  2771. return FALSE;
  2772. }
  2773. //
  2774. HitStruct st;
  2775. st.cbCardCount = 16;
  2776. st.cbCardType = CT_BOMB_XIAN;
  2777. int cbCardCountIndex = 0;
  2778. int MagicCount = 0;
  2779. for (size_t i = 0; i < 4; i++)
  2780. {
  2781. int nTmpCount = tagDsit.cbDistributing[vIndex[i]][5];
  2782. if (nTmpCount>4)
  2783. {
  2784. nTmpCount = 4;
  2785. }
  2786. for (int count = 0; count < nTmpCount; count++)
  2787. {
  2788. st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(vIndex[i] + 3);
  2789. }
  2790. if (nTmpCount<4)
  2791. {
  2792. //用王填充
  2793. int Need = 4 - nTmpCount;
  2794. INT xJoker = tagDsit.cbDistributing[13][5];
  2795. if (xJoker>0)
  2796. {
  2797. if (xJoker>=Need)
  2798. {
  2799. for (int j = 0; j < Need; j++)
  2800. {
  2801. st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(16);//小王
  2802. tagDsit.cbDistributing[13][5]--;
  2803. }
  2804. }
  2805. else
  2806. {
  2807. for (int j = 0; j < xJoker; j++)
  2808. {
  2809. st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(16);//小王
  2810. tagDsit.cbDistributing[13][5]--;
  2811. }
  2812. Need = Need - xJoker;
  2813. INT DJoker = tagDsit.cbDistributing[15][5];
  2814. if (DJoker>=Need)
  2815. {
  2816. for (int j = 0; j < Need; j++)
  2817. {
  2818. st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(17);//大王
  2819. tagDsit.cbDistributing[14][5]--;
  2820. }
  2821. }
  2822. else{
  2823. for (int j = 0; j < xJoker; j++)
  2824. {
  2825. st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(17);//大王
  2826. tagDsit.cbDistributing[14][5]--;
  2827. }
  2828. }
  2829. }
  2830. }
  2831. else
  2832. {
  2833. //没有小王
  2834. INT DJoker = tagDsit.cbDistributing[15][5];
  2835. for (int j = 0; j < Need; j++)
  2836. {
  2837. st.cbHintLogicCardData[cbCardCountIndex++] = TagIndexToNoColorCardValue(17);//大王
  2838. tagDsit.cbDistributing[14][5]--;
  2839. }
  2840. }
  2841. }
  2842. }
  2843. ListHit.push_back(st);
  2844. return TRUE;
  2845. }
  2846. BOOL CGameLogic_Poker::Find3WBomo(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType BomoInfo, tagDistributing tag, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2847. {
  2848. if (GetMagicType() == MagicMode::NoHaveMagic)
  2849. {
  2850. return FALSE;
  2851. }
  2852. if (BomoInfo.Level < 6)
  2853. {
  2854. //查找3W炸弹
  2855. BYTE cbMagicCards[4] = { 0 };
  2856. BYTE nCount = GetMagicJokerCount(tag, cbMagicCards);
  2857. if (nCount < 3)
  2858. {
  2859. return FALSE;
  2860. }
  2861. HitStruct st;
  2862. st.cbCardCount = 3;
  2863. st.cbCardType = CT_BOMB_3W;
  2864. for (int i = 0; i < 3; i++)
  2865. {
  2866. st.cbHintLogicCardData[i] = TagIndexToNoColorCardValue(GetCardLogicValue(cbMagicCards[i]));
  2867. }
  2868. ListHit.push_back(st);
  2869. }
  2870. }
  2871. BOOL CGameLogic_Poker::Find4WBomo(const BYTE cbCardData[], BYTE cbCount, BYTE type, BomoType BomoInfo, tagDistributing tag, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2872. {
  2873. BYTE MagicType = GetMagicType();
  2874. BYTE cbMagicCards[4] = { 0 };
  2875. BYTE nCount=0;// = GetMagicJokerCount(tag, cbMagicCards);
  2876. for (int i = 0; i < cbUserCount;i++)
  2877. {
  2878. if (UserCards[i]==0x4e||UserCards[i]==0x4f)
  2879. {
  2880. cbMagicCards[nCount++] = UserCards[i];
  2881. }
  2882. }
  2883. if (nCount!=4)
  2884. {
  2885. return FALSE;
  2886. }
  2887. if (MagicType == MagicMode::NoHaveMagic)
  2888. {
  2889. HitStruct st;
  2890. st.cbCardCount = 4;
  2891. st.cbCardType = CT_BOMB_TW;
  2892. for (int i = 0; i < 4; i++)
  2893. {
  2894. st.cbHintLogicCardData[i] = TagIndexToNoColorCardValue(GetCardLogicValue(cbMagicCards[i]));
  2895. }
  2896. ListHit.push_back(st);
  2897. }
  2898. else
  2899. {
  2900. if (BomoInfo.Level < 8)
  2901. {
  2902. HitStruct st;
  2903. st.cbCardCount = 4;
  2904. st.cbCardType = CT_BOMB_TW;
  2905. for (int i = 0; i < 4; i++)
  2906. {
  2907. st.cbHintLogicCardData[i] = TagIndexToNoColorCardValue(GetCardLogicValue(cbMagicCards[i]));
  2908. }
  2909. ListHit.push_back(st);
  2910. }
  2911. }
  2912. }
  2913. BOOL CGameLogic_Poker::FindAllHit(const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  2914. {
  2915. tagAnalyseResult_Poker tagResult;
  2916. AnalysebCardData(UserCards, cbUserCount, tagResult);
  2917. for (int i = 1; i < 8;i++)
  2918. {
  2919. byte CardCount = tagResult.cbBlockCount[i - 1];
  2920. if (CardCount==0)
  2921. {
  2922. continue;
  2923. }
  2924. if (i>=4)
  2925. {
  2926. if (ListHit.size()>0)
  2927. {
  2928. break;
  2929. }
  2930. }
  2931. for (int cbCount = 1; cbCount <= CardCount;cbCount++)
  2932. {
  2933. HitStruct hit;
  2934. hit.cbCardCount = i;
  2935. switch (hit.cbCardCount)
  2936. {
  2937. case 1:
  2938. hit.cbCardType = CT_SINGLE;
  2939. break;
  2940. case 2:
  2941. hit.cbCardType = CT_DOUBLE;
  2942. break;
  2943. case 3:
  2944. hit.cbCardType = CT_THREE;
  2945. break;
  2946. case 4:
  2947. case 5:
  2948. case 6:
  2949. case 7:
  2950. case 8:
  2951. hit.cbCardType = CT_BOMB;
  2952. break;
  2953. default:
  2954. break;
  2955. }
  2956. for (BYTE cbCardIndex = 0; cbCardIndex < hit.cbCardCount;cbCardIndex++)
  2957. {
  2958. hit.cbHintLogicCardData[cbCardIndex] = TagIndexToNoColorCardValue(GetCardLogicValue(tagResult.cbCardData[i - 1][(cbCount - 1)*i + cbCardIndex]));
  2959. }
  2960. ListHit.push_back(hit);
  2961. }
  2962. }
  2963. return 0;
  2964. }
  2965. int CGameLogic_Poker::rand9xianInfo(BomoType &info)
  2966. {
  2967. //5付5线等同9线;4线5连等同9线;3付6线等同9线,5线3连等同9线
  2968. int Bomo = 0;
  2969. int nType = rand() % 3;
  2970. switch (nType){
  2971. case 0:{
  2972. info.Level = 9;
  2973. info.BomoTypes = BomoTypeXian;
  2974. info.fu = 5;
  2975. info.xian = 5;
  2976. Bomo = TRUE;
  2977. break;
  2978. }
  2979. case 1:{
  2980. info.Level = 9;
  2981. info.BomoTypes = BomoTypeLian;
  2982. info.tong = 4;
  2983. info.lian = 5;
  2984. Bomo = 1;
  2985. break;
  2986. }
  2987. case 2:{
  2988. Bomo = 2;
  2989. break;
  2990. }
  2991. }
  2992. return Bomo;
  2993. }
  2994. BOOL CGameLogic_Poker::bFind9xianCards(vector<vector<BYTE>> &AllCards, BYTE cbCardBuffer[], BYTE &cbBufferCount, BomoType& Bomo, BOOL isXian)
  2995. {
  2996. if (isXian)
  2997. {
  2998. int XianCount = 0;
  2999. vector<BYTE> vCardIndexs;
  3000. for (BYTE i = 0; i < AllCards.size(); i++)
  3001. {
  3002. if (AllCards[i].size()>=Bomo.xian)
  3003. {
  3004. XianCount++;
  3005. vCardIndexs.push_back(i);
  3006. }
  3007. }
  3008. if (XianCount<Bomo.fu)
  3009. {
  3010. return FALSE;
  3011. }
  3012. for (int nFu = 0; nFu < Bomo.fu; nFu++)
  3013. {
  3014. BYTE cbCardIndex = RandIndexAndDelIt(vCardIndexs);
  3015. for (int nXian = 0; nXian < Bomo.xian; nXian++){
  3016. cbCardBuffer[cbBufferCount++] = AllCards[cbCardIndex][0];
  3017. AllCards[cbCardIndex].erase(AllCards[cbCardIndex].begin());
  3018. }
  3019. }
  3020. return TRUE;
  3021. }
  3022. else
  3023. {
  3024. //随机一个数据 判断从这个值开始连续M连 是否可行,可行继续 不可行 忽略。
  3025. BYTE cbStartIndex = rand() % 7;
  3026. for (BYTE i = cbStartIndex; i < AllCards.size(); i++)
  3027. {
  3028. if (i>=13)
  3029. {
  3030. continue;
  3031. }
  3032. if (AllCards[i].size()<Bomo.tong)
  3033. {
  3034. return FALSE;
  3035. }
  3036. }
  3037. for (int nLian = 0; nLian < Bomo.lian;nLian++)
  3038. {
  3039. for (int nTong = 0; nTong < Bomo.tong; nTong++)
  3040. {
  3041. cbCardBuffer[cbBufferCount++] = AllCards[cbStartIndex + nLian][0];
  3042. AllCards[cbStartIndex + nLian].erase(AllCards[cbStartIndex + nLian].begin());
  3043. }
  3044. }
  3045. return TRUE;
  3046. }
  3047. }
  3048. BYTE CGameLogic_Poker::RandIndexAndDelIt(vector<BYTE>& CardIndex)
  3049. {
  3050. BYTE cbIndex = rand() % CardIndex.size();
  3051. BYTE cbCardIndex = CardIndex[cbIndex];
  3052. CardIndex.erase(CardIndex.begin()+cbIndex);
  3053. return cbCardIndex;
  3054. }
  3055. 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)
  3056. {
  3057. // 正规 N付M线
  3058. BYTE cbMaxCardLogicValue = 0;
  3059. if (bomoinfo.BomoTypes == BomoTypeXian)
  3060. {
  3061. //要比较我方是否有比对方最大值还大的 线牌
  3062. cbMaxCardLogicValue = GetMaxLogicValue(cbCardData, cbCount);
  3063. }
  3064. //保存无花色 牌的逻辑值
  3065. BYTE cbBomoCards[16] = { 0 };
  3066. BYTE cbBomoCardCount = 0;
  3067. for (BYTE i = 0; i < 13; i++)
  3068. {
  3069. BYTE cbCardCount = tagDsit.cbDistributing[i][5];
  3070. if (cbCardCount >= xian)
  3071. {
  3072. cbBomoCards[cbBomoCardCount++] = TagIndexToNoColorCardValue(i + 3);;
  3073. }
  3074. }
  3075. //进行排列组合
  3076. if (cbMaxCardLogicValue != 0)
  3077. {
  3078. BOOL bFind = FALSE;//是否有比上家4f4线大的牌
  3079. for (int i = 0; i < 16; i++)
  3080. {
  3081. if (cbBomoCards[i] == 0)
  3082. {
  3083. break;
  3084. }
  3085. if (cbBomoCards[i] > cbMaxCardLogicValue)
  3086. {
  3087. bFind = TRUE;
  3088. break;
  3089. }
  3090. }
  3091. if (bFind == FALSE)
  3092. {
  3093. return FALSE;
  3094. }
  3095. //现在比上次最大的牌大的 有了。
  3096. vector<vector<BYTE>> allHits = CardSecret(cbBomoCards, cbBomoCardCount, xian, cbMaxCardLogicValue);
  3097. vector<vector<BYTE>>::iterator it = allHits.begin();
  3098. for (it; it != allHits.end(); it++)
  3099. {
  3100. HitStruct st;
  3101. st.cbCardCount = Fu * xian;
  3102. st.cbCardType = CT_BOMB_XIAN;
  3103. BYTE CardIndex = 0;
  3104. vector<BYTE>::iterator OneValue = it->begin();
  3105. for (; OneValue != it->end(); OneValue++)
  3106. {
  3107. //将4个值赋值到st中
  3108. for (BYTE index = 0; index < xian; index++)
  3109. {
  3110. st.cbHintLogicCardData[CardIndex * Fu + index] = *OneValue;
  3111. }
  3112. CardIndex++;
  3113. }
  3114. //不是连排 可以加入 连排 让后面的处理 不属于5线
  3115. if (IsStructureLink(st.cbHintLogicCardData, st.cbCardCount, xian) == FALSE)
  3116. {
  3117. ListHit.push_back(st);
  3118. }
  3119. }
  3120. }
  3121. return TRUE;
  3122. }
  3123. 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)
  3124. {
  3125. // if (cbCount==5)
  3126. // {
  3127. // //正规5相炸弹
  3128. // FindSameXianBomo(cbCardData, cbCount, bomoinfo, tagDsit, ListHit);
  3129. // }
  3130. //FindNFuMxian(cbCardData, cbCount, 4, 4, type, bomoinfo, tagDsit, tagReslt, ListHit);
  3131. if (cbCount==5)
  3132. {
  3133. HintSameCardCount(cbCardData, cbCount, 5, cbUserCardData, cbUserCount, ListHit, TRUE);
  3134. }
  3135. //带王的 4付4线
  3136. //Find4Fu4xianWithJoker(cbCardData, cbCount, 4, type, bomoinfo, tagDsit, tagReslt, ListHit);
  3137. return TRUE;
  3138. }
  3139. void CGameLogic_Poker::FindShunZI(const BYTE cbCardData[], BYTE bCount, BYTE nFindCount, vector<vector<BYTE>>& result)
  3140. {
  3141. //4 5 6 7 8 9 10
  3142. for (int index = 0; index <= bCount - nFindCount; index++)
  3143. {
  3144. BOOL isShun = IsStructureLink_zhengxu(&cbCardData[index], nFindCount, 1);
  3145. if (isShun)
  3146. {
  3147. vector<BYTE> vCards;
  3148. for (int i = 0; i < nFindCount;i++)
  3149. {
  3150. vCards.push_back(cbCardData[index+i]);
  3151. }
  3152. result.push_back(vCards);
  3153. }
  3154. }
  3155. }
  3156. BOOL CGameLogic_Poker::HintShunWithJoker(const BYTE cbCardData[], BYTE cbCount, BYTE type, const BYTE UserCards[], BYTE cbUserCount, std::vector<HitStruct> &ListHit)
  3157. {
  3158. BYTE tmpCardData[MAX_COUNT_Poker] = { 0 };
  3159. CopyMemory(tmpCardData, cbCardData, cbCount);
  3160. SortCardList(tmpCardData, cbCount, ST_ORDER, ORDERBY_ASE);
  3161. tagDistributing tag;
  3162. AnalysebDistributing(UserCards, cbUserCount, tag);
  3163. BYTE LianCount = 0;
  3164. BYTE TypeCount;
  3165. BYTE MinCard = GetCardLogicValue(tmpCardData[0]);
  3166. BYTE cbMagic[4] = { 0 };
  3167. int MagicCount = GetMagicJokerCount(tag, cbMagic);
  3168. if (MagicCount==0)
  3169. {
  3170. return 0;
  3171. }
  3172. switch (type)
  3173. {
  3174. case CT_SHUNZI:
  3175. LianCount = cbCount;
  3176. TypeCount = 1;
  3177. break;
  3178. case CT_DOUBLE_LINK:
  3179. LianCount = cbCount/2;
  3180. TypeCount = 2;
  3181. break;
  3182. case CT_THREE_LINK:
  3183. LianCount = cbCount/3;
  3184. TypeCount = 3;
  3185. break;
  3186. default:
  3187. break;
  3188. }
  3189. int nStartIndex = MinCard - 3 + 1;
  3190. int MaxIndex = 12 - LianCount;
  3191. for (int StartIndex = nStartIndex; StartIndex <= MaxIndex; StartIndex++)
  3192. {
  3193. BYTE cbReplacCards[MAX_COUNT_Poker] = { 0 }; //替换后的牌值 有王 用于给前端
  3194. memset(cbReplacCards, 0xff, MAX_COUNT_Poker);
  3195. BYTE cbReplacdCardsNoJoker[MAX_COUNT_Poker] = { 0 };//替换后的牌值 无王
  3196. BYTE NeedMagcCount = CalcuTagDistStructureLinkNeedMagicCount(tag, StartIndex, LianCount, TypeCount, cbReplacCards, cbReplacdCardsNoJoker);
  3197. if (NeedMagcCount<=MagicCount)
  3198. {
  3199. HitStruct ST;
  3200. ST.cbCardCount = cbCount;
  3201. ST.cbCardType = type;
  3202. BYTE cbReplacCardCount = 0;
  3203. for (BYTE reIndex = 0; reIndex < ST.cbCardCount; reIndex++)
  3204. {
  3205. if (cbReplacCards[reIndex] == 255)
  3206. {
  3207. cbReplacCards[reIndex] =GetCardLogicValue(cbMagic[cbReplacCardCount++]);
  3208. }
  3209. }
  3210. for (int i = 0; i < MAX_COUNT_Poker; i++)
  3211. {
  3212. if (cbReplacCards[i]==255)
  3213. {
  3214. break;
  3215. }
  3216. ST.cbHintLogicCardData[i] = cbReplacCards[i];
  3217. }
  3218. if (IsStructureLink_zhengxu(cbReplacdCardsNoJoker, ST.cbCardCount, TypeCount))
  3219. {
  3220. ListHit.push_back(ST);
  3221. }
  3222. }
  3223. }
  3224. return TRUE;
  3225. }
  3226. //计算连对 需要magic 个数
  3227. BYTE CGameLogic_Poker::CalcuTagDistStructureLinkNeedMagicCount(tagDistributing tag, BYTE tagIndex, BYTE LianCount, BYTE TypeCount, BYTE cbOutCards[MAX_COUNT_Poker], BYTE cbOutCardsNoJoker[MAX_COUNT_Poker])
  3228. {
  3229. BYTE cbTmpCards[MAX_COUNT_Poker] = { 0 };
  3230. BYTE cbTmpCardCount=0;
  3231. BYTE NeedMagicCount = 0;
  3232. for (BYTE Count = 0; Count < LianCount;Count++)
  3233. {
  3234. BYTE curCardCount = tag.cbDistributing[tagIndex + Count][5];
  3235. if (curCardCount >= TypeCount)
  3236. {
  3237. for (BYTE cardIndex = 0; cardIndex < TypeCount; cardIndex++)
  3238. {
  3239. cbOutCards[Count*TypeCount + cardIndex] = TagIndexToNoColorCardValue(tagIndex + Count + 3);
  3240. cbOutCardsNoJoker[Count*TypeCount + cardIndex]=TagIndexToNoColorCardValue(tagIndex + Count + 3);
  3241. }
  3242. }
  3243. else
  3244. {
  3245. //cbOutCards 里面包含王
  3246. //cbOutCardsNoJoker 无王
  3247. BYTE tmpNeedMagic = TypeCount - curCardCount;
  3248. NeedMagicCount += tmpNeedMagic;
  3249. for (BYTE cardIndex = 0; cardIndex < TypeCount; cardIndex++)
  3250. {
  3251. cbOutCardsNoJoker[Count*TypeCount + cardIndex] = TagIndexToNoColorCardValue(tagIndex + Count + 3);
  3252. }
  3253. for (BYTE cardIndex = 0; cardIndex < TypeCount - tmpNeedMagic; cardIndex++)
  3254. {
  3255. BYTE cbIndex = tagIndex + Count + 3;
  3256. cbOutCards[Count*TypeCount + cardIndex] = TagIndexToNoColorCardValue(cbIndex);
  3257. }
  3258. }
  3259. }
  3260. return NeedMagicCount;
  3261. }
  3262. BYTE CGameLogic_Poker::FindAllPaiBomoCards(tagDistributing tagDsit, tagAnalyseResult_Poker tagReslt, LastCardsInfo stLastCardsInfo, std::vector<HitStruct> &ListHit)
  3263. {
  3264. //3-A 排序前的准备
  3265. BYTE cbAllCardIndex[12] = { 0 };
  3266. for (BYTE i = 0; i < 12;i++)
  3267. {
  3268. cbAllCardIndex[i] = i;
  3269. }
  3270. BYTE cbNotSameCardCount[] = { 3, 4, 5 ,6};
  3271. BYTE cbStartSameCont[] = { 4, 4, 5 ,4};
  3272. BYTE cbSameMaxCount[] = { 9, 6, 5 ,4};
  3273. vector<BomoType> BomoInfos;
  3274. for (int nNotCard = 0; nNotCard < 4;nNotCard++)
  3275. {
  3276. //分析所有不同牌的组合 是否满足 某线某连/ 某付某线
  3277. for (int nStartSameCardCount = cbStartSameCont[nNotCard]; nStartSameCardCount <= cbSameMaxCount[nNotCard];nStartSameCardCount++)
  3278. {
  3279. //n TONG =nStartSameCardCount
  3280. //m NotTong = cbNotSameCardCount[nNotCard]
  3281. vector<vector<BYTE>> resultAll;
  3282. vector<BYTE> tmpVec;
  3283. CardPerm(cbAllCardIndex, 12, cbNotSameCardCount[nNotCard], tmpVec,resultAll, 0);
  3284. //resultAll 中保存了 所有不通牌的 组合 index
  3285. //函数功能 确定这个索引对应的牌 是否可以组成特殊牌,是否能够加入到提示列表
  3286. vector<vector<BYTE>>::iterator OneIndex = resultAll.begin();
  3287. for (; OneIndex != resultAll.end();OneIndex++)
  3288. {
  3289. FromIndexToHitList(*OneIndex, nStartSameCardCount,tagDsit, stLastCardsInfo, ListHit);
  3290. }
  3291. }
  3292. }
  3293. return FALSE;
  3294. }
  3295. std::vector<std::vector<BYTE>> CGameLogic_Poker::CardSecret(const BYTE Cards[], BYTE cbCount, int nLen,BYTE LastMaxCard)
  3296. {
  3297. {
  3298. vector<vector<BYTE>> strVect;
  3299. if (cbCount == 0 || nLen > cbCount) //返回一个空表
  3300. return strVect;
  3301. vector<BYTE> chVect;
  3302. CardPerm(Cards, cbCount, nLen, chVect, strVect, LastMaxCard);
  3303. return strVect;
  3304. }
  3305. }
  3306. void CGameLogic_Poker::CardPerm(const BYTE str[], BYTE strCount, int nLen, vector<BYTE>& ve, vector<vector<BYTE>>& result, BYTE LastMaxCard)
  3307. {
  3308. {
  3309. if (nLen == 0) //已经找到一个全排列的组合,而且这个组合就在ve中
  3310. {
  3311. vector<BYTE> st;
  3312. vector<BYTE>::iterator it = ve.begin();
  3313. for (; it != ve.end(); it++)
  3314. {
  3315. st.push_back(*it);
  3316. }
  3317. //如果最大值 比某个值小 则 不进入
  3318. sort(st.begin(), st.end());
  3319. if (st[st.size()-1]<LastMaxCard)
  3320. {
  3321. return;
  3322. }
  3323. result.push_back(st); //找到了一种组合,将它保存在动态数组中
  3324. return;
  3325. }
  3326. if (strCount == 0)
  3327. return;
  3328. ve.push_back(str[0]);
  3329. CardPerm(str + 1, strCount - 1, nLen - 1, ve, result, LastMaxCard);
  3330. //递归从这里出来的条件只有两种,
  3331. //要么str为空了, 说明当前已经遍历一遍字符串,
  3332. //要么nLen为0了,说明已经找到了一种组合
  3333. ve.pop_back(); //此时要将最后一个字符出栈,然后遍历下一个字符
  3334. CardPerm(str + 1, strCount - 1, nLen, ve, result, LastMaxCard);
  3335. }
  3336. }
  3337. //计算 带癞子 和不带癞子的情况
  3338. BOOL CGameLogic_Poker::FromIndexToHitList(vector<BYTE> cbCardIndexFormTag, BYTE nTongCardCount, tagDistributing tagDsit, LastCardsInfo stLastCardsInfo, std::vector<HitStruct> &ListHit)
  3339. {
  3340. //计算不带癞子的情况
  3341. BYTE mNotSameCount = cbCardIndexFormTag.size();
  3342. BYTE cbNeedCount=mNotSameCount*nTongCardCount;
  3343. BYTE CurrentCount = 0;
  3344. BYTE cbBomoCardData[MAX_COUNT_Poker] = { 0 };
  3345. BYTE cbBomoCardCount = 0;
  3346. BYTE cbMagicReplaceCardNotColorCardValue[MAX_COUNT_Poker] = { 0 };
  3347. BYTE cbReplaceCount=0;
  3348. //牌数不够 用癞子凑
  3349. BYTE cbMagicData[4] = { 0 };
  3350. BYTE cbMagicCardCont = GetMagicJokerCount(tagDsit, cbMagicData);
  3351. for (int i = 0; i < cbCardIndexFormTag.size();i++)
  3352. {
  3353. int TmpCount = tagDsit.cbDistributing[cbCardIndexFormTag[i]][5];
  3354. if (TmpCount >= nTongCardCount)
  3355. {
  3356. CurrentCount += nTongCardCount;
  3357. for (int CopyDataIndex = 0; CopyDataIndex < nTongCardCount; CopyDataIndex++)
  3358. {
  3359. cbBomoCardData[cbBomoCardCount++] = TagIndexToNoColorCardValue(cbCardIndexFormTag[i] + 3);
  3360. }
  3361. }
  3362. else
  3363. {
  3364. CurrentCount += TmpCount;
  3365. if (cbMagicCardCont>0)
  3366. {
  3367. //此时 不够的牌用FF 代替
  3368. for (int CopyDataIndex = 0; CopyDataIndex <TmpCount; CopyDataIndex++)
  3369. {
  3370. cbBomoCardData[cbBomoCardCount++] = TagIndexToNoColorCardValue(cbCardIndexFormTag[i] + 3);
  3371. }
  3372. cbMagicReplaceCardNotColorCardValue[cbReplaceCount] = TagIndexToNoColorCardValue(cbCardIndexFormTag[i] + 3);
  3373. for (int CopyDataIndex = TmpCount; CopyDataIndex < nTongCardCount; CopyDataIndex++)
  3374. {
  3375. cbBomoCardData[cbBomoCardCount++] = GetCardLogicValue(cbMagicData[cbReplaceCount]);
  3376. }
  3377. cbReplaceCount++;
  3378. }
  3379. }
  3380. }
  3381. //不带癞子可以组成的话 就不用计算癞子了组合了,由其他组合计算。
  3382. if (CurrentCount==cbNeedCount)
  3383. {
  3384. //不用癞子就可以组成
  3385. //可以根据牌值 组成2中
  3386. /*
  3387. 【1】 NotSameCount付nTongCardCont 线
  3388. 【2】 nTongCardCount现 NotSameCount 连
  3389. */
  3390. BYTE cbLevel = 0;
  3391. BomoType BomoInfo;
  3392. BYTE type= GetCardType(cbBomoCardData, cbBomoCardCount, cbLevel, BomoInfo);
  3393. if (type != CT_BOMB_LINK&& type != CT_BOMB_XIAN)
  3394. {
  3395. return FALSE;
  3396. }
  3397. //比较2付牌的 大小 不考虑王的情况
  3398. // 如果当前线级 小于上家的 则放弃
  3399. if (stLastCardsInfo.BomoInfo.Level>BomoInfo.Level)
  3400. {
  3401. return FALSE;
  3402. }
  3403. if (stLastCardsInfo.BomoInfo.Level==BomoInfo.Level)
  3404. {
  3405. //如果线级相同 按照牌的数量比较
  3406. //数量少的大于属相大的
  3407. if (stLastCardsInfo.cbCardCount<BomoInfo.CbBomoCount)
  3408. {
  3409. return FALSE;
  3410. }
  3411. if (stLastCardsInfo.cbCardCount>BomoInfo.CbBomoCount)
  3412. {
  3413. HitStruct st;
  3414. st.cbCardCount = cbBomoCardCount;
  3415. CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
  3416. st.cbCardType = BomoInfo.BomoTypes;
  3417. ListHit.push_back(st);
  3418. return TRUE;
  3419. }
  3420. if (stLastCardsInfo.cbCardCount==BomoInfo.CbBomoCount)
  3421. {
  3422. //如果数量相同 则按照最大牌比较
  3423. BYTE cbMaxLogicCard = GetMaxLogicValue(stLastCardsInfo.cbCards, stLastCardsInfo.cbCardCount);
  3424. BYTE cbCurrentMaxLogicCard = GetMaxLogicValue(cbBomoCardData, cbBomoCardCount);
  3425. if (cbMaxLogicCard >= cbCurrentMaxLogicCard)
  3426. {
  3427. return FALSE;
  3428. }
  3429. HitStruct st;
  3430. st.cbCardCount = cbBomoCardCount;
  3431. CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
  3432. st.cbCardType = BomoInfo.BomoTypes;
  3433. ListHit.push_back(st);
  3434. }
  3435. }
  3436. if (stLastCardsInfo.BomoInfo.Level < BomoInfo.Level)
  3437. {
  3438. HitStruct st;
  3439. st.cbCardCount = cbBomoCardCount;
  3440. CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
  3441. st.cbCardType = BomoInfo.BomoTypes;
  3442. ListHit.push_back(st);
  3443. }
  3444. }
  3445. else
  3446. {
  3447. if (CurrentCount + cbMagicCardCont<cbNeedCount)
  3448. {
  3449. return FALSE;
  3450. }
  3451. //cbBomoCardData 里面存的是替换了王的牌
  3452. BYTE cbNoHaveJokerData[MAX_COUNT_Poker] = { 0 };
  3453. CopyMemory(cbNoHaveJokerData, cbBomoCardData, cbBomoCardCount);
  3454. //把王替换成 对应的牌 然后计算是否 能够大于上一家
  3455. BYTE RelpaceCount = 0;
  3456. for (int i = 0; i < cbBomoCardCount; i++)
  3457. {
  3458. if (cbNoHaveJokerData[i] == 0)
  3459. {
  3460. break;
  3461. }
  3462. if (cbNoHaveJokerData[i] == GetCardLogicValue(0x4e) || cbNoHaveJokerData[i] == GetCardLogicValue(0x4f))
  3463. {
  3464. cbNoHaveJokerData[i] = cbMagicReplaceCardNotColorCardValue[RelpaceCount++];
  3465. }
  3466. }
  3467. BYTE cbLevel = 0;
  3468. BomoType BomoInfo;
  3469. BYTE type = GetCardType(cbNoHaveJokerData, cbBomoCardCount, cbLevel, BomoInfo);
  3470. if (type != CT_BOMB_LINK&& type != CT_BOMB_XIAN)
  3471. {
  3472. return FALSE;
  3473. }
  3474. //比较2付牌的 大小 不考虑王的情况
  3475. // 如果当前线级 小于上家的 则放弃
  3476. if (stLastCardsInfo.BomoInfo.Level > BomoInfo.Level)
  3477. {
  3478. return FALSE;
  3479. }
  3480. if (stLastCardsInfo.BomoInfo.Level == BomoInfo.Level)
  3481. {
  3482. //如果线级相同 按照牌的数量比较
  3483. if (stLastCardsInfo.cbCardCount < BomoInfo.CbBomoCount)
  3484. {
  3485. return FALSE;
  3486. }
  3487. if (stLastCardsInfo.cbCardCount > BomoInfo.CbBomoCount)
  3488. {
  3489. HitStruct st;
  3490. st.cbCardCount = cbBomoCardCount;
  3491. CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
  3492. st.cbCardType = BomoInfo.BomoTypes;
  3493. ListHit.push_back(st);
  3494. return TRUE;
  3495. }
  3496. if (stLastCardsInfo.cbCardCount == BomoInfo.CbBomoCount)
  3497. {
  3498. //如果数量相同 则按照最大牌比较
  3499. BYTE cbMaxLogicCard = GetMaxLogicValue(stLastCardsInfo.cbCards, stLastCardsInfo.cbCardCount);
  3500. BYTE cbCurrentMaxLogicCard = GetMaxLogicValue(cbBomoCardData, cbBomoCardCount);
  3501. if (cbMaxLogicCard >= cbCurrentMaxLogicCard)
  3502. {
  3503. return FALSE;
  3504. }
  3505. HitStruct st;
  3506. st.cbCardCount = cbBomoCardCount;
  3507. CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
  3508. st.cbCardType = BomoInfo.BomoTypes;
  3509. ListHit.push_back(st);
  3510. }
  3511. }
  3512. if (stLastCardsInfo.BomoInfo.Level < BomoInfo.Level)
  3513. {
  3514. HitStruct st;
  3515. st.cbCardCount = cbBomoCardCount;
  3516. CopyMemory(st.cbHintLogicCardData, cbBomoCardData, st.cbCardCount);
  3517. st.cbCardType = BomoInfo.BomoTypes;
  3518. ListHit.push_back(st);
  3519. }
  3520. }
  3521. return FALSE;
  3522. }
  3523. //检测 我的大于 last
  3524. BOOL CGameLogic_Poker::CompareCardBigLastCards(BomoType lastUserBomoInfo, BYTE cbLastCards[], BYTE cbLastCardCount, BomoType MyBomoTypeFInfo, BYTE cbCards[], BYTE cbCardCount)
  3525. {
  3526. if (MyBomoTypeFInfo.Level>lastUserBomoInfo.Level)
  3527. {
  3528. return TRUE;
  3529. }
  3530. if (MyBomoTypeFInfo.Level < lastUserBomoInfo.Level)
  3531. {
  3532. return FALSE;
  3533. }
  3534. if (MyBomoTypeFInfo.Level==lastUserBomoInfo.Level)
  3535. {
  3536. if (MyBomoTypeFInfo.CbBomoCount<lastUserBomoInfo.CbBomoCount)
  3537. {
  3538. return TRUE;
  3539. }
  3540. if (MyBomoTypeFInfo.CbBomoCount > lastUserBomoInfo.CbBomoCount)
  3541. {
  3542. return FALSE;
  3543. }
  3544. if (MyBomoTypeFInfo.CbBomoCount == lastUserBomoInfo.CbBomoCount)
  3545. {
  3546. //如果数量相同 则按照最大牌比较
  3547. //分别去2个牌的 最大值
  3548. BYTE cbMaxLogicCard = GetMaxLogicValue(cbLastCards, cbLastCardCount);
  3549. BYTE cbMyMaxLogicCard = GetMaxLogicValue(cbCards, cbCardCount);
  3550. if (cbMyMaxLogicCard>cbMaxLogicCard)
  3551. {
  3552. return TRUE;
  3553. }
  3554. return FALSE;
  3555. }
  3556. }
  3557. return FALSE;
  3558. }
  3559. BOOL CGameLogic_Poker::GetAllSameCards(BYTE StartLevel, std::vector<HitStruct> &ListHit, tagDistributing tagDsit)
  3560. {
  3561. for (int CardCount = StartLevel; CardCount <= 12; CardCount++)
  3562. {
  3563. for (int index = 0; index < 13; index++)
  3564. {
  3565. if (tagDsit.cbDistributing[index][5] == CardCount)
  3566. {
  3567. HitStruct st;
  3568. st.cbCardCount = CardCount;
  3569. st.cbCardType = CT_BOMB;
  3570. CopyOneCardToArry(st.cbHintLogicCardData, st.cbCardCount, TagIndexToNoColorCardValue(index + 3));
  3571. ListHit.push_back(st);
  3572. }
  3573. }
  3574. }
  3575. BYTE cbMagicCards[4] = { 0 };
  3576. int MagicCount = GetMagicJokerCount(tagDsit, cbMagicCards);
  3577. if (MagicCount==0)
  3578. {
  3579. return FALSE;
  3580. }
  3581. for (int CardCount = StartLevel; CardCount <= 12; CardCount++)
  3582. {
  3583. for (int index = 0; index < 13; index++)
  3584. {
  3585. byte curCount = tagDsit.cbDistributing[index][5];
  3586. if (curCount < CardCount&&curCount + MagicCount >= CardCount)
  3587. {
  3588. HitStruct st;
  3589. CopyOneCardToArry(st.cbHintLogicCardData, curCount, TagIndexToNoColorCardValue(index + 3));
  3590. CopyJokerCardToArry(&st.cbHintLogicCardData[curCount], CardCount - curCount, cbMagicCards);
  3591. st.cbCardCount = CardCount;
  3592. st.cbCardType = CT_BOMB;
  3593. ListHit.push_back(st);
  3594. }
  3595. }
  3596. }
  3597. return TRUE;
  3598. }
  3599. void CGameLogic_Poker::CopyOneCardToArry(BYTE cbDstCards[], BYTE CopyCount, BYTE cbCard)
  3600. {
  3601. for (int i = 0; i < CopyCount; i++){
  3602. cbDstCards[i] = cbCard;
  3603. }
  3604. }
  3605. void CGameLogic_Poker::CopyJokerCardToArry(BYTE cbDstCards[], BYTE cbCopyCount, BYTE cbJokerCards[4])
  3606. {
  3607. BYTE AddCount=0;
  3608. for (int i = 0; i < cbCopyCount;i++)
  3609. {
  3610. if (cbJokerCards[AddCount]==0)
  3611. {
  3612. break;
  3613. }
  3614. cbDstCards[i] = GetCardLogicValue(cbJokerCards[AddCount++]);
  3615. }
  3616. }
  3617. BOOL CGameLogic_Poker::NoJokerBigUserCards(BYTE TagIndex, BYTE cbCardCount, const BYTE cbUserCards[], BYTE cbcCount)
  3618. {
  3619. if (cbCardCount>cbcCount)
  3620. {
  3621. return TRUE;
  3622. }
  3623. if (cbCardCount==cbcCount)
  3624. {
  3625. BYTE LogicValue = GetCardLogicValue(TagIndex + 3);
  3626. BYTE UserLogicCardValue = GetCardLogicValue(cbUserCards[0]);
  3627. if (UserLogicCardValue<LogicValue)
  3628. {
  3629. return TRUE;
  3630. }
  3631. }
  3632. return FALSE;
  3633. }
  3634. void CGameLogic_Poker::SetBomoLevel(BomoType & BomoInfo)
  3635. {
  3636. if (BomoInfo.BomoTypes==BomoTypeXian)
  3637. {
  3638. switch (BomoInfo.xian)
  3639. {
  3640. case 4:
  3641. BomoInfo.Level = BomoInfo.fu + 1;
  3642. break;
  3643. case 5:
  3644. BomoInfo.Level = BomoInfo.fu + 4;
  3645. break;
  3646. case 6:
  3647. case 7:
  3648. case 8:
  3649. case 9:{
  3650. BomoInfo.Level = BomoInfo.fu + BomoInfo.xian;
  3651. break;
  3652. }
  3653. default:
  3654. break;
  3655. }
  3656. }
  3657. else if(BomoInfo.BomoTypes == BomoTypeLian)
  3658. {
  3659. if (BomoInfo.tong > 4)
  3660. {
  3661. BomoInfo.Level = BomoInfo.tong + BomoInfo.lian + 1;
  3662. }
  3663. else{
  3664. BomoInfo.Level = BomoInfo.tong + BomoInfo.lian;
  3665. }
  3666. }
  3667. }