//对比扑克 bool CGameLogic::CompareCard(const BYTE bFirstList[], const BYTE bNextList[], BYTE bFirstCount, BYTE bNextCount) { //获取类型 BYTE bNextType=GetCardType(bNextList,bNextCount); BYTE bFirstType=GetCardType(bFirstList,bFirstCount); //类型判断 if (bFirstType==CT_INVALID) return false; if (bFirstType==CT_MISSILE_CARD) return true; //炸弹判断 if ((bFirstType==CT_BOMB_CARD)&&(bNextType!=CT_BOMB_CARD)) return true; if ((bFirstType!=CT_BOMB_CARD)&&(bNextType==CT_BOMB_CARD)) return false; //规则判断 if ((bFirstType!=bNextType)||(bFirstCount!=bNextCount)) return false; //开始对比 switch (bNextType) { case CT_SINGLE: case CT_DOUBLE: case CT_THREE: case CT_ONE_LINE: case CT_DOUBLE_LINE: case CT_THREE_LINE: case CT_BOMB_CARD: { BYTE bFirstLogicValue=GetCardLogicValue(bFirstList[0]); BYTE bNextLogicValue=GetCardLogicValue(bNextList[0]); return bFirstLogicValue>bNextLogicValue; } case CT_THREE_LINE_TAKE_ONE: case CT_THREE_LINE_TAKE_DOUBLE: { tagAnalyseResult NextResult; tagAnalyseResult FirstResult; AnalysebCardData(bNextList,bNextCount,NextResult); AnalysebCardData(bFirstList,bFirstCount,FirstResult); return FirstResult.bThreeLogicVolue[0]>NextResult.bThreeLogicVolue[0]; } case CT_FOUR_LINE_TAKE_ONE: case CT_FOUR_LINE_TAKE_DOUBLE: { tagAnalyseResult NextResult; tagAnalyseResult FirstResult; AnalysebCardData(bNextList,bNextCount,NextResult); AnalysebCardData(bFirstList,bFirstCount,FirstResult); return FirstResult.bFourLogicVolue[0]>NextResult.bFourLogicVolue[0]; } } return false; }
//排列扑克 void CGameLogic::SortCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbSortType) { //数目过虑 if (cbCardCount==0) return; //转换数值 BYTE cbSortValue[MAX_COUNT]; for (BYTE i=0;i<cbCardCount;i++) cbSortValue[i]=GetCardLogicValue(cbCardData[i]); //排序操作 bool bSorted=true; BYTE cbThreeCount,cbLast=cbCardCount-1; do { bSorted=true; for (BYTE i=0;i<cbLast;i++) { if ((cbSortValue[i]<cbSortValue[i+1])|| ((cbSortValue[i]==cbSortValue[i+1])&&(cbCardData[i]<cbCardData[i+1]))) { //交换位置 cbThreeCount=cbCardData[i]; cbCardData[i]=cbCardData[i+1]; cbCardData[i+1]=cbThreeCount; cbThreeCount=cbSortValue[i]; cbSortValue[i]=cbSortValue[i+1]; cbSortValue[i+1]=cbThreeCount; bSorted=false; } } cbLast--; } while(bSorted==false); //数目排序 if (cbSortType==ST_COUNT) { //分析扑克 BYTE cbIndex=0; tagAnalyseResult AnalyseResult; AnalysebCardData(cbCardData,cbCardCount,AnalyseResult); //拷贝四牌 CopyMemory(&cbCardData[cbIndex],AnalyseResult.cbFourCardData,sizeof(BYTE)*AnalyseResult.cbFourCount*4); cbIndex+=AnalyseResult.cbFourCount*4; //拷贝三牌 CopyMemory(&cbCardData[cbIndex],AnalyseResult.cbThreeCardData,sizeof(BYTE)*AnalyseResult.cbThreeCount*3); cbIndex+=AnalyseResult.cbThreeCount*3; //拷贝对牌 CopyMemory(&cbCardData[cbIndex],AnalyseResult.cbDoubleCardData,sizeof(BYTE)*AnalyseResult.cbDoubleCount*2); cbIndex+=AnalyseResult.cbDoubleCount*2; //拷贝单牌 CopyMemory(&cbCardData[cbIndex],AnalyseResult.cbSignedCardData,sizeof(BYTE)*AnalyseResult.cbSignedCount); cbIndex+=AnalyseResult.cbSignedCount; } return; }
//是否为双联 //条件:>= 6 bool CGameLogic::IsShuangLianCardType(const BYTE bCardData[], BYTE bCardCount) { CString strFile,strTemp; CTime tmCur = CTime::GetCurrentTime(); CString strTime = tmCur.Format("%m%d"); strFile.Format("log\\%sIsShuangLianCardType.log",strTime); strTemp.Format("IsShuangLianCardType %d", bCardCount); theApp.WriteLog(strFile, strTemp); bool resultBool = false; // if (bCardCount < 6 || (bCardCount % 2) != 0 ) if (bCardCount < 6 ) { strTemp.Format("(bCardCount=%d % 2 = %d", bCardCount, (bCardCount % 3) ); //theApp.WriteLog(strFile, strTemp); return resultBool; } //其他牌型 if (bCardCount>=6) { //分析扑克 tagAnalyseResult AnalyseResult; AnalysebCardData(bCardData,bCardCount,AnalyseResult); strTemp.Format("AnalyseResult.bDoubleCount=%d", AnalyseResult.bDoubleCount ); theApp.WriteLog(strFile, strTemp); if (AnalyseResult.bDoubleCount>=3) { //二连判断 if (AnalyseResult.bDoubleLogicVolue[0]!=15) { for (BYTE i=1;i<AnalyseResult.bDoubleCount;i++) { if (AnalyseResult.bDoubleLogicVolue[i]!=(AnalyseResult.bDoubleLogicVolue[0]-i)) { return resultBool; } } if (AnalyseResult.bDoubleCount*2==bCardCount) { resultBool = true; return resultBool; } }//End if (AnalyseResult.bDoubleLogicVolue[0]!=15) }//End if (AnalyseResult.bDoubleCount>=3) return resultBool; } return resultBool; }
//是否有对牌 //条件:>= 2 bool CGameLogic::IsHaveDuiCard(const BYTE bCardData[], BYTE bCardCount) { CString strFile,strTemp; CTime tmCur = CTime::GetCurrentTime(); CString strTime = tmCur.Format("%m%d"); strFile.Format("log\\%sIsHaveDuiCard.log",strTime); strTemp.Format("IsHaveDuiCard %d", bCardCount); theApp.WriteLog(strFile, strTemp); bool resultBool = false; if (bCardCount < 2 ) { return resultBool; } //其他牌型 if (bCardCount>=3) { //分析扑克 tagAnalyseResult AnalyseResult; AnalysebCardData(bCardData,bCardCount,AnalyseResult); strTemp.Format("2=%d, 4=%d, 3=%d", AnalyseResult.bDoubleCount, AnalyseResult.bFourCount, AnalyseResult.bThreeCount ); theApp.WriteLog(strFile, strTemp); if ( (AnalyseResult.bDoubleCount > 0) || (AnalyseResult.bFourCount > 0) || (AnalyseResult.bThreeCount > 0) ) { resultBool = true; } }//End if (bCardCount>=3) return resultBool; }
//获取类型 BYTE CGameLogic::GetCardType(const BYTE bCardData[], BYTE bCardCount) { CString strFile,strTemp; CTime tmCur = CTime::GetCurrentTime(); CString strTime = tmCur.Format("%m%d"); strFile.Format("log\\%sGetCardType.log",strTime); strTemp.Format("GetCardType %d", bCardCount); theApp.WriteLog(strFile, strTemp); //开始分析 switch (bCardCount) { case 1: //单牌 { return CT_SINGLE; } case 2: //对牌和火箭 { return (GetCardLogicValue(bCardData[0])==GetCardLogicValue(bCardData[1]))?CT_DOUBLE:CT_INVALID; } case 3: case 4: //连牌和炸弹 { //单张判断 if (IsDanLianCardType( bCardData, bCardCount)) { strTemp.Format("IsDanLianCardType %d", bCardCount); theApp.WriteLog(strFile, strTemp); return CT_ONE_LINE; } BYTE bLogicValue=GetCardLogicValue(bCardData[0]); BYTE i; for ( i=1;i<bCardCount;i++) { if (bLogicValue!=GetCardLogicValue(bCardData[i])) break; } if (i==bCardCount) return (bCardCount==3)?CT_THREE:CT_BOMB_CARD; if (bCardCount==3) return CT_INVALID; break; } case 5: { //单张判断 if (IsDanLianCardType( bCardData, bCardCount)) { strTemp.Format("IsDanLianCardType %d", bCardCount); theApp.WriteLog(strFile, strTemp); return CT_ONE_LINE; } break; } } //其他牌型 if (bCardCount>=4) { //分析扑克 tagAnalyseResult AnalyseResult; AnalysebCardData(bCardData,bCardCount,AnalyseResult); strTemp.Format("AnalyseResult.bFourCount %d, AnalyseResult.bThreeCount=%d, AnalyseResult.bDoubleCount=%d", AnalyseResult.bFourCount, AnalyseResult.bThreeCount,AnalyseResult.bDoubleCount ); theApp.WriteLog(strFile, strTemp); //四牌判断 if (AnalyseResult.bFourCount>0 ) { return CT_INVALID; } //三牌判断 if (AnalyseResult.bThreeCount>0 && bCardCount >= 9 ) { if (IsThreeLianCardType( bCardData, bCardCount)) { return CT_THREE_LINE; } } /* if (AnalyseResult.bThreeCount>0) { //连牌判断 if (AnalyseResult.bThreeCount>1) { if (AnalyseResult.bThreeLogicVolue[0]==15) return CT_INVALID; for (BYTE i=1;i<AnalyseResult.bThreeCount;i++) { if (AnalyseResult.bThreeLogicVolue[i]!=(AnalyseResult.bThreeLogicVolue[0]-i)) return CT_INVALID; } } //牌形判断 if (AnalyseResult.bThreeCount*3==bCardCount) return CT_THREE_LINE; if (AnalyseResult.bThreeCount==(bCardCount-AnalyseResult.bThreeCount*3)) return CT_THREE_LINE_TAKE_ONE; if ((AnalyseResult.bDoubleCount==AnalyseResult.bThreeCount)&&(bCardCount==(AnalyseResult.bThreeCount*3+AnalyseResult.bDoubleCount*2))) return CT_THREE_LINE_TAKE_DOUBLE; return CT_INVALID; } */ //两张类型 if (AnalyseResult.bDoubleCount>=3 && bCardCount >= 6 ) { if ( IsShuangLianCardType( bCardData, bCardCount)) { return CT_DOUBLE_LINE; } } /* if (AnalyseResult.bDoubleCount>=3) { //二连判断 if (AnalyseResult.bDoubleLogicVolue[0]!=15) { for (BYTE i=1;i<AnalyseResult.bDoubleCount;i++) { if (AnalyseResult.bDoubleLogicVolue[i]!=(AnalyseResult.bDoubleLogicVolue[0]-i)) return CT_INVALID; } if (AnalyseResult.bDoubleCount*2==bCardCount) return CT_DOUBLE_LINE; } return CT_INVALID; } */ //单张判断 if ((AnalyseResult.bSignedCount>= 3 )&&(AnalyseResult.bSignedCount==bCardCount) && bCardCount >= 6) { if (IsDanLianCardType( bCardData, bCardCount)) { return CT_ONE_LINE; } } /* if ((AnalyseResult.bSignedCount>= 3 )&&(AnalyseResult.bSignedCount==bCardCount)) { BYTE bLogicValue=GetCardLogicValue(bCardData[0]); if (bLogicValue>=15) return CT_INVALID; for (BYTE i=1;i<AnalyseResult.bSignedCount;i++) { if (GetCardLogicValue(bCardData[i])!=(bLogicValue-i)) return CT_INVALID; } return CT_ONE_LINE; } */ return CT_INVALID; } return CT_INVALID; }
//是否为单联 //条件:>= 3 bool CGameLogic::IsDanLianCardType(const BYTE bCardData[], BYTE bCardCount) { CString strFile,strTemp; CTime tmCur = CTime::GetCurrentTime(); CString strTime = tmCur.Format("%m%d"); strFile.Format("log\\%sIsDanLianCardType.log",strTime); strTemp.Format("IsDanLianCardType %d", bCardCount); theApp.WriteLog(strFile, strTemp); bool resultBool = false; if (bCardCount < 3 ) { return resultBool; } //如果有对牌 if( IsHaveDuiCard( bCardData , bCardCount)) { strTemp.Format("IsHaveDuiCard "); theApp.WriteLog(strFile, strTemp); return resultBool; } //其他牌型 if (bCardCount>=3) { //分析扑克 tagAnalyseResult AnalyseResult; AnalysebCardData(bCardData,bCardCount,AnalyseResult); strTemp.Format("AnalyseResult.bSignedCount=%d, bCardCount=%d ", AnalyseResult.bSignedCount, bCardCount); theApp.WriteLog(strFile, strTemp); //单张判断 if ((AnalyseResult.bSignedCount>=3)&&(AnalyseResult.bSignedCount==bCardCount)) { BYTE bLogicValue=GetCardLogicValue(bCardData[0]); strTemp.Format("bLogicValue =%d ", bLogicValue); theApp.WriteLog(strFile, strTemp); if (bLogicValue>=15) { return resultBool; }//End if for (BYTE i=1;i<AnalyseResult.bSignedCount;i++) { if (GetCardLogicValue(bCardData[i])!=(bLogicValue-i)) { strTemp.Format("GetCardLogicValue(bCardData[i])=%d, (bLogicValue-i)=%d, i=%d", GetCardLogicValue(bCardData[i]), (bLogicValue-i), i); theApp.WriteLog(strFile, strTemp); return resultBool; } }//End for resultBool = true; return resultBool; }//End if ((AnalyseResult.bSignedCount>=3)&&(AnalyseResult.bSignedCount==bCardCount)) }//End if (bCardCount>=3) return resultBool; }
//是否为三联 //条件:>= 9 bool CGameLogic::IsThreeLianCardType(const BYTE bCardData[], BYTE bCardCount) { CString strFile,strTemp; CTime tmCur = CTime::GetCurrentTime(); CString strTime = tmCur.Format("%m%d"); strFile.Format("log\\%sIsThreeLianCardType.log",strTime); strTemp.Format("IsThreeLianCardType %d", bCardCount); theApp.WriteLog(strFile, strTemp); bool resultBool = false; // if (bCardCount < 9 || (bCardCount % 3)!= 0 ) if (bCardCount < 9 ) { strTemp.Format("(bCardCount % 3) = %d", (bCardCount % 3)); //theApp.WriteLog(strFile, strTemp); return resultBool; } //其他牌型 if (bCardCount>=9) { //三牌判断 //分析扑克 tagAnalyseResult AnalyseResult; AnalysebCardData(bCardData,bCardCount,AnalyseResult); strTemp.Format("AnalyseResult.bThreeCount = %d", AnalyseResult.bThreeCount); theApp.WriteLog(strFile, strTemp); if (AnalyseResult.bThreeCount>0) { //连牌判断 if (AnalyseResult.bThreeCount>1) { if (AnalyseResult.bThreeLogicVolue[0]==15) { return resultBool; } for (BYTE i=1;i<AnalyseResult.bThreeCount;i++) { if (AnalyseResult.bThreeLogicVolue[i]!=(AnalyseResult.bThreeLogicVolue[0]-i)) { return resultBool; } } }//End if (AnalyseResult.bThreeCount>1) //牌形判断 if (AnalyseResult.bThreeCount*3==bCardCount) { resultBool = true; } }//End if (AnalyseResult.bThreeCount>0) }//End if (bCardCount>=9) return resultBool; }
//获取类型 BYTE CGameLogic::GetCardGenre(BYTE cbCardData[], BYTE cbCardCount) { //简单牌形 switch (cbCardCount) { case 1: //单牌 { return CT_SINGLE; } case 2: //对牌 { return (GetCardLogicValue(cbCardData[0])==GetCardLogicValue(cbCardData[1]))?CT_ONE_DOUBLE:CT_SINGLE; } } //五条类型 if (cbCardCount>=4) { //变量定义 bool cbSameColor=true,bLineCard=true; BYTE cbFirstColor=GetCardColor(cbCardData[0]); BYTE cbFirstValue=GetCardLogicValue(cbCardData[0]); //牌形分析 for (BYTE i=1;i<cbCardCount;i++) { //数据分析 if (GetCardColor(cbCardData[i])!=cbFirstColor) cbSameColor=false; if (cbFirstValue!=(GetCardLogicValue(cbCardData[i])+i)) bLineCard=false; //结束判断 if ((cbSameColor==false)&&(bLineCard==false)) break; } //特殊 if(!bLineCard) { //A J 10 9 8特殊 for (BYTE i=1;i<cbCardCount;i++) { if ((cbFirstValue-2)!=(GetCardLogicValue(cbCardData[i])+i)) break; } if(i==cbCardCount) bLineCard=true; } //顺子类型 if ((cbSameColor==false)&&(bLineCard==true)) return CT_SHUN_ZI; //同花类型 if ((cbSameColor==true)&&(bLineCard==false)) return CT_TONG_HUA; //同花顺类型 if ((cbSameColor==true)&&(bLineCard==true)) return CT_TONG_HUA_SHUN; } //扑克分析 tagAnalyseResult AnalyseResult; AnalysebCardData(cbCardData,cbCardCount,AnalyseResult); //四条类型 if (AnalyseResult.cbFourCount==1) return CT_TIE_ZHI; //两对类型 if (AnalyseResult.cbDoubleCount==2) return CT_TWO_DOUBLE; //对牌类型 if ((AnalyseResult.cbDoubleCount==1)&&(AnalyseResult.cbThreeCount==0)) return CT_ONE_DOUBLE; //葫芦类型 if (AnalyseResult.cbThreeCount==1) return (AnalyseResult.cbDoubleCount==1)?CT_HU_LU:CT_THREE_TIAO; return CT_SINGLE; }
//对比扑克 bool CGameLogic::CompareCard(BYTE cbFirstCardData[], BYTE cbNextCardData[], BYTE cbCardCount) { //获取类型 BYTE cbNextGenre=GetCardGenre(cbNextCardData,cbCardCount); BYTE cbFirstGenre=GetCardGenre(cbFirstCardData,cbCardCount); //类型判断 if (cbFirstGenre!=cbNextGenre) return (cbFirstGenre>cbNextGenre); //类型对比 switch(cbFirstGenre) { case CT_SINGLE: //单牌 { //对比数值 for (BYTE i=0;i<cbCardCount;i++) { BYTE cbNextValue=GetCardLogicValue(cbNextCardData[i]); BYTE cbFirstValue=GetCardLogicValue(cbFirstCardData[i]); if (cbFirstValue!=cbNextValue) return cbFirstValue>cbNextValue; } //对比花色 return GetCardColor(cbFirstCardData[0])>GetCardColor(cbNextCardData[0]); } case CT_HU_LU: //葫芦 case CT_TIE_ZHI: //铁支 case CT_ONE_DOUBLE: //对子 case CT_TWO_DOUBLE: //两对 case CT_THREE_TIAO: //三条 { //分析扑克 tagAnalyseResult AnalyseResultNext; tagAnalyseResult AnalyseResultFirst; AnalysebCardData(cbNextCardData,cbCardCount,AnalyseResultNext); AnalysebCardData(cbFirstCardData,cbCardCount,AnalyseResultFirst); //四条数值 if (AnalyseResultFirst.cbFourCount>0) { BYTE cbNextValue=AnalyseResultNext.cbFourLogicVolue[0]; BYTE cbFirstValue=AnalyseResultFirst.cbFourLogicVolue[0]; return cbFirstValue>cbNextValue; } //三条数值 if (AnalyseResultFirst.cbThreeCount>0) { BYTE cbNextValue=AnalyseResultNext.cbThreeLogicVolue[0]; BYTE cbFirstValue=AnalyseResultFirst.cbThreeLogicVolue[0]; return cbFirstValue>cbNextValue; } //对子数值 for (BYTE i=0;i<AnalyseResultFirst.cbDoubleCount;i++) { BYTE cbNextValue=AnalyseResultNext.cbDoubleLogicVolue[i]; BYTE cbFirstValue=AnalyseResultFirst.cbDoubleLogicVolue[i]; if (cbFirstValue!=cbNextValue) return cbFirstValue>cbNextValue; } //散牌数值 for (BYTE i=0;i<AnalyseResultFirst.cbSignedCount;i++) { BYTE cbNextValue=AnalyseResultNext.cbSignedLogicVolue[i]; BYTE cbFirstValue=AnalyseResultFirst.cbSignedLogicVolue[i]; if (cbFirstValue!=cbNextValue) return cbFirstValue>cbNextValue; } //对子花色 if (AnalyseResultFirst.cbDoubleCount>0) { BYTE cbNextColor=GetCardColor(AnalyseResultNext.cbDoubleCardData[0]); BYTE cbFirstColor=GetCardColor(AnalyseResultFirst.cbDoubleCardData[0]); return cbFirstColor>cbNextColor; } //散牌花色 if (AnalyseResultFirst.cbSignedCount>0) { BYTE cbNextColor=GetCardColor(AnalyseResultNext.cbSignedCardData[0]); BYTE cbFirstColor=GetCardColor(AnalyseResultFirst.cbSignedCardData[0]); return cbFirstColor>cbNextColor; } break; } case CT_SHUN_ZI: //顺子 case CT_TONG_HUA: //同花 case CT_TONG_HUA_SHUN: //同花顺 { //数值判断 BYTE cbNextValue=GetCardLogicValue(cbNextCardData[0]); BYTE cbFirstValue=GetCardLogicValue(cbFirstCardData[0]); //特殊列:A J 10 9 8 if( cbFirstGenre == CT_SHUN_ZI ) { if( GetCardLogicValue(cbNextCardData[0])-3 == GetCardLogicValue(cbNextCardData[1]) ) cbNextValue = GetCardLogicValue(cbNextCardData[1]); if( GetCardLogicValue(cbFirstCardData[0])-3 == GetCardLogicValue(cbFirstCardData[1]) ) cbFirstValue = GetCardLogicValue(cbFirstCardData[1]); } if (cbFirstValue!=cbNextValue) return (cbFirstValue>cbNextValue); //花色判断 BYTE cbNextColor=GetCardColor(cbNextCardData[0]); BYTE cbFirstColor=GetCardColor(cbFirstCardData[0]); return (cbFirstColor>cbNextColor); } } //错误断言 ASSERT(FALSE); return false; }
//出牌搜索 bool CGameLogic::SearchOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagOutCardResult & OutCardResult) { //设置结果 ZeroMemory(&OutCardResult,sizeof(OutCardResult)); //构造扑克 BYTE cbCardData[MAX_COUNT]; BYTE cbCardCount=cbHandCardCount; CopyMemory(cbCardData,cbHandCardData,sizeof(BYTE)*cbHandCardCount); //排列扑克 SortCardList(cbCardData,cbCardCount,ST_ORDER); //获取类型 BYTE cbTurnOutType=GetCardType(cbTurnCardData,cbTurnCardCount); //出牌分析 switch (cbTurnOutType) { case CT_ERROR: //错误类型 { //获取数值 BYTE cbLogicValue=GetCardLogicValue(cbCardData[cbCardCount-1]); //多牌判断 BYTE cbSameCount=1; for (BYTE i=1;i<cbCardCount;i++) { if (GetCardLogicValue(cbCardData[cbCardCount-i-1])==cbLogicValue) cbSameCount++; else break; } //完成处理 if (cbSameCount>1) { OutCardResult.cbCardCount=cbSameCount; for (BYTE j=0;j<cbSameCount;j++) OutCardResult.cbResultCard[j]=cbCardData[cbCardCount-1-j]; return true; } //单牌处理 OutCardResult.cbCardCount=1; OutCardResult.cbResultCard[0]=cbCardData[cbCardCount-1]; return true; } case CT_SINGLE: //单牌类型 case CT_DOUBLE: //对牌类型 case CT_THREE: //三条类型 { //获取数值 BYTE cbLogicValue=GetCardLogicValue(cbTurnCardData[0]); //分析扑克 tagAnalyseResult AnalyseResult; AnalysebCardData(cbCardData,cbCardCount,AnalyseResult); //寻找单牌 if (cbTurnCardCount<=1) { for (BYTE i=0;i<AnalyseResult.cbSignedCount;i++) { BYTE cbIndex=AnalyseResult.cbSignedCount-i-1; if (GetCardLogicValue(AnalyseResult.cbSignedCardData[cbIndex])>cbLogicValue) { //设置结果 OutCardResult.cbCardCount=cbTurnCardCount; CopyMemory(OutCardResult.cbResultCard,&AnalyseResult.cbSignedCardData[cbIndex],sizeof(BYTE)*cbTurnCardCount); return true; } } } //寻找对牌 if (cbTurnCardCount<=2) { for (BYTE i=0;i<AnalyseResult.cbDoubleCount;i++) { BYTE cbIndex=(AnalyseResult.cbDoubleCount-i-1)*2; if (GetCardLogicValue(AnalyseResult.cbDoubleCardData[cbIndex])>cbLogicValue) { //设置结果 OutCardResult.cbCardCount=cbTurnCardCount; CopyMemory(OutCardResult.cbResultCard,&AnalyseResult.cbDoubleCardData[cbIndex],sizeof(BYTE)*cbTurnCardCount); return true; } } } //寻找三牌 if (cbTurnCardCount<=3) { for (BYTE i=0;i<AnalyseResult.cbThreeCount;i++) { BYTE cbIndex=(AnalyseResult.cbThreeCount-i-1)*3; if (GetCardLogicValue(AnalyseResult.cbThreeCardData[cbIndex])>cbLogicValue) { //设置结果 OutCardResult.cbCardCount=cbTurnCardCount; CopyMemory(OutCardResult.cbResultCard,&AnalyseResult.cbThreeCardData[cbIndex],sizeof(BYTE)*cbTurnCardCount); return true; } } } break; } case CT_SINGLE_LINE: //单连类型 { //长度判断 if (cbCardCount<cbTurnCardCount) break; //获取数值 BYTE cbLogicValue=GetCardLogicValue(cbTurnCardData[0]); //搜索连牌 for (BYTE i=(cbTurnCardCount-1);i<cbCardCount;i++) { //获取数值 BYTE cbHandLogicValue=GetCardLogicValue(cbCardData[cbCardCount-i-1]); //构造判断 if (cbHandLogicValue>=15) break; if (cbHandLogicValue<=cbLogicValue) continue; //搜索连牌 BYTE cbLineCount=0; for (BYTE j=(cbCardCount-i-1);j<cbCardCount;j++) { if ((GetCardLogicValue(cbCardData[j])+cbLineCount)==cbHandLogicValue) { //增加连数 OutCardResult.cbResultCard[cbLineCount++]=cbCardData[j]; //完成判断 if (cbLineCount==cbTurnCardCount) { OutCardResult.cbCardCount=cbTurnCardCount; return true; } } } } break; } case CT_DOUBLE_LINE: //对连类型 { //长度判断 if (cbCardCount<cbTurnCardCount) break; //获取数值 BYTE cbLogicValue=GetCardLogicValue(cbTurnCardData[0]); //搜索连牌 for (BYTE i=(cbTurnCardCount-1);i<cbCardCount;i++) { //获取数值 BYTE cbHandLogicValue=GetCardLogicValue(cbCardData[cbCardCount-i-1]); //构造判断 if (cbHandLogicValue<=cbLogicValue) continue; if ((cbTurnCardCount>1)&&(cbHandLogicValue>=15)) break; //搜索连牌 BYTE cbLineCount=0; for (BYTE j=(cbCardCount-i-1);j<(cbCardCount-1);j++) { if (((GetCardLogicValue(cbCardData[j])+cbLineCount)==cbHandLogicValue) &&((GetCardLogicValue(cbCardData[j+1])+cbLineCount)==cbHandLogicValue)) { //增加连数 OutCardResult.cbResultCard[cbLineCount*2]=cbCardData[j]; OutCardResult.cbResultCard[(cbLineCount++)*2+1]=cbCardData[j+1]; //完成判断 if (cbLineCount*2==cbTurnCardCount) { OutCardResult.cbCardCount=cbTurnCardCount; return true; } } } } break; } case CT_THREE_LINE: //三连类型 case CT_THREE_LINE_TAKE_ONE: //三带一单 case CT_THREE_LINE_TAKE_TWO: //三带一对 { //长度判断 if (cbCardCount<cbTurnCardCount) break; //获取数值 BYTE cbLogicValue=0; for (BYTE i=0;i<cbTurnCardCount-2;i++) { cbLogicValue=GetCardLogicValue(cbTurnCardData[i]); if (GetCardLogicValue(cbTurnCardData[i+1])!=cbLogicValue) continue; if (GetCardLogicValue(cbTurnCardData[i+2])!=cbLogicValue) continue; break; } //属性数值 BYTE cbTurnLineCount=0; if (cbTurnOutType==CT_THREE_LINE_TAKE_ONE) cbTurnLineCount=cbTurnCardCount/4; else if (cbTurnOutType==CT_THREE_LINE_TAKE_TWO) cbTurnLineCount=cbTurnCardCount/5; else cbTurnLineCount=cbTurnCardCount/3; //搜索连牌 for (BYTE i=cbTurnLineCount*3-1;i<cbCardCount;i++) { //获取数值 BYTE cbHandLogicValue=GetCardLogicValue(cbCardData[cbCardCount-i-1]); //构造判断 if (cbHandLogicValue<=cbLogicValue) continue; if ((cbTurnLineCount>1)&&(cbHandLogicValue>=15)) break; //搜索连牌 BYTE cbLineCount=0; for (BYTE j=(cbCardCount-i-1);j<(cbCardCount-2);j++) { //设置变量 OutCardResult.cbCardCount=0; //三牌判断 if ((GetCardLogicValue(cbCardData[j])+cbLineCount)!=cbHandLogicValue) continue; if ((GetCardLogicValue(cbCardData[j+1])+cbLineCount)!=cbHandLogicValue) continue; if ((GetCardLogicValue(cbCardData[j+2])+cbLineCount)!=cbHandLogicValue) continue; //增加连数 OutCardResult.cbResultCard[cbLineCount*3]=cbCardData[j]; OutCardResult.cbResultCard[cbLineCount*3+1]=cbCardData[j+1]; OutCardResult.cbResultCard[(cbLineCount++)*3+2]=cbCardData[j+2]; //完成判断 if (cbLineCount==cbTurnLineCount) { //连牌设置 OutCardResult.cbCardCount=cbLineCount*3; //构造扑克 BYTE cbLeftCardData[MAX_COUNT]; BYTE cbLeftCount=cbCardCount-OutCardResult.cbCardCount; CopyMemory(cbLeftCardData,cbCardData,sizeof(BYTE)*cbCardCount); RemoveCard(OutCardResult.cbResultCard,OutCardResult.cbCardCount,cbLeftCardData,cbCardCount); //分析扑克 tagAnalyseResult AnalyseResultLeft; AnalysebCardData(cbLeftCardData,cbLeftCount,AnalyseResultLeft); //单牌处理 if (cbTurnOutType==CT_THREE_LINE_TAKE_ONE) { //提取单牌 for (BYTE k=0;k<AnalyseResultLeft.cbSignedCount;k++) { //中止判断 if (OutCardResult.cbCardCount==cbTurnCardCount) break; //设置扑克 BYTE cbIndex=AnalyseResultLeft.cbSignedCount-k-1; BYTE cbSignedCard=AnalyseResultLeft.cbSignedCardData[cbIndex]; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbSignedCard; } //提取对牌 for (BYTE k=0;k<AnalyseResultLeft.cbDoubleCount*2;k++) { //中止判断 if (OutCardResult.cbCardCount==cbTurnCardCount) break; //设置扑克 BYTE cbIndex=(AnalyseResultLeft.cbDoubleCount*2-k-1); BYTE cbSignedCard=AnalyseResultLeft.cbDoubleCardData[cbIndex]; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbSignedCard; } //提取三牌 for (BYTE k=0;k<AnalyseResultLeft.cbThreeCount*3;k++) { //中止判断 if (OutCardResult.cbCardCount==cbTurnCardCount) break; //设置扑克 BYTE cbIndex=(AnalyseResultLeft.cbThreeCount*3-k-1); BYTE cbSignedCard=AnalyseResultLeft.cbThreeCardData[cbIndex]; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbSignedCard; } //提取四牌 for (BYTE k=0;k<AnalyseResultLeft.cbFourCount*4;k++) { //中止判断 if (OutCardResult.cbCardCount==cbTurnCardCount) break; //设置扑克 BYTE cbIndex=(AnalyseResultLeft.cbFourCount*4-k-1); BYTE cbSignedCard=AnalyseResultLeft.cbFourCardData[cbIndex]; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbSignedCard; } } //对牌处理 if (cbTurnOutType==CT_THREE_LINE_TAKE_TWO) { //提取对牌 for (BYTE k=0;k<AnalyseResultLeft.cbDoubleCount;k++) { //中止判断 if (OutCardResult.cbCardCount==cbTurnCardCount) break; //设置扑克 BYTE cbIndex=(AnalyseResultLeft.cbDoubleCount-k-1)*2; BYTE cbCardData1=AnalyseResultLeft.cbDoubleCardData[cbIndex]; BYTE cbCardData2=AnalyseResultLeft.cbDoubleCardData[cbIndex+1]; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbCardData1; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbCardData2; } //提取三牌 for (BYTE k=0;k<AnalyseResultLeft.cbThreeCount;k++) { //中止判断 if (OutCardResult.cbCardCount==cbTurnCardCount) break; //设置扑克 BYTE cbIndex=(AnalyseResultLeft.cbThreeCount-k-1)*3; BYTE cbCardData1=AnalyseResultLeft.cbThreeCardData[cbIndex]; BYTE cbCardData2=AnalyseResultLeft.cbThreeCardData[cbIndex+1]; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbCardData1; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbCardData2; } //提取四牌 for (BYTE k=0;k<AnalyseResultLeft.cbFourCount;k++) { //中止判断 if (OutCardResult.cbCardCount==cbTurnCardCount) break; //设置扑克 BYTE cbIndex=(AnalyseResultLeft.cbFourCount-k-1)*4; BYTE cbCardData1=AnalyseResultLeft.cbFourCardData[cbIndex]; BYTE cbCardData2=AnalyseResultLeft.cbFourCardData[cbIndex+1]; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbCardData1; OutCardResult.cbResultCard[OutCardResult.cbCardCount++]=cbCardData2; } } //完成判断 if (OutCardResult.cbCardCount==cbTurnCardCount) return true; } } } break; } } //搜索炸弹 if ((cbCardCount>=4)&&(cbTurnOutType!=CT_MISSILE_CARD)) { //变量定义 BYTE cbLogicValue=0; if (cbTurnOutType==CT_BOMB_CARD) cbLogicValue=GetCardLogicValue(cbTurnCardData[0]); //搜索炸弹 for (BYTE i=3;i<cbCardCount;i++) { //获取数值 BYTE cbHandLogicValue=GetCardLogicValue(cbCardData[cbCardCount-i-1]); //构造判断 if (cbHandLogicValue<=cbLogicValue) continue; //炸弹判断 BYTE cbTempLogicValue=GetCardLogicValue(cbCardData[cbCardCount-i-1]); BYTE j=1; for (;j<4;j++) { if (GetCardLogicValue(cbCardData[cbCardCount+j-i-1])!=cbTempLogicValue) break; } if (j!=4) continue; //设置结果 OutCardResult.cbCardCount=4; OutCardResult.cbResultCard[0]=cbCardData[cbCardCount-i-1]; OutCardResult.cbResultCard[1]=cbCardData[cbCardCount-i]; OutCardResult.cbResultCard[2]=cbCardData[cbCardCount-i+1]; OutCardResult.cbResultCard[3]=cbCardData[cbCardCount-i+2]; return true; } } //搜索火箭 if ((cbCardCount>=2)&&(cbCardData[0]==0x4F)&&(cbCardData[1]==0x4E)) { //设置结果 OutCardResult.cbCardCount=2; OutCardResult.cbResultCard[0]=cbCardData[0]; OutCardResult.cbResultCard[1]=cbCardData[1]; return true; } return false; }
//对比扑克 bool CGameLogic::CompareCard(const BYTE cbFirstCard[], const BYTE cbNextCard[], BYTE cbFirstCount, BYTE cbNextCount) { //获取类型 BYTE cbNextType=GetCardType(cbNextCard,cbNextCount); BYTE cbFirstType=GetCardType(cbFirstCard,cbFirstCount); //类型判断 if (cbNextType==CT_ERROR) return false; if (cbNextType==CT_MISSILE_CARD) return true; //炸弹判断 if ((cbFirstType!=CT_BOMB_CARD)&&(cbNextType==CT_BOMB_CARD)) return true; if ((cbFirstType==CT_BOMB_CARD)&&(cbNextType!=CT_BOMB_CARD)) return false; //规则判断 if ((cbFirstType!=cbNextType)||(cbFirstCount!=cbNextCount)) return false; //开始对比 switch (cbNextType) { case CT_SINGLE: case CT_DOUBLE: case CT_THREE: case CT_SINGLE_LINE: case CT_DOUBLE_LINE: case CT_THREE_LINE: case CT_BOMB_CARD: { //获取数值 BYTE cbNextLogicValue=GetCardLogicValue(cbNextCard[0]); BYTE cbFirstLogicValue=GetCardLogicValue(cbFirstCard[0]); //对比扑克 return cbNextLogicValue>cbFirstLogicValue; } case CT_THREE_LINE_TAKE_ONE: case CT_THREE_LINE_TAKE_TWO: { //分析扑克 tagAnalyseResult NextResult; tagAnalyseResult FirstResult; AnalysebCardData(cbNextCard,cbNextCount,NextResult); AnalysebCardData(cbFirstCard,cbFirstCount,FirstResult); //获取数值 BYTE cbNextLogicValue=GetCardLogicValue(NextResult.cbThreeCardData[0]); BYTE cbFirstLogicValue=GetCardLogicValue(FirstResult.cbThreeCardData[0]); //对比扑克 return cbNextLogicValue>cbFirstLogicValue; } case CT_FOUR_LINE_TAKE_ONE: case CT_FOUR_LINE_TAKE_TWO: { //分析扑克 tagAnalyseResult NextResult; tagAnalyseResult FirstResult; AnalysebCardData(cbNextCard,cbNextCount,NextResult); AnalysebCardData(cbFirstCard,cbFirstCount,FirstResult); //获取数值 BYTE cbNextLogicValue=GetCardLogicValue(NextResult.cbFourCardData[0]); BYTE cbFirstLogicValue=GetCardLogicValue(FirstResult.cbFourCardData[0]); //对比扑克 return cbNextLogicValue>cbFirstLogicValue; } } return false; }
//获取类型 BYTE CGameLogic::GetCardType(const BYTE cbCardData[], BYTE cbCardCount) { //简单牌型 switch (cbCardCount) { case 0: //空牌 { return CT_ERROR; } case 1: //单牌 { return CT_SINGLE; } case 2: //对牌火箭 { //牌型判断 if ((cbCardData[0]==0x4F)&&(cbCardData[1]==0x4E)) return CT_MISSILE_CARD; if (GetCardLogicValue(cbCardData[0])==GetCardLogicValue(cbCardData[1])) return CT_DOUBLE; return CT_ERROR; } } //分析扑克 tagAnalyseResult AnalyseResult; AnalysebCardData(cbCardData,cbCardCount,AnalyseResult); //四牌判断 if (AnalyseResult.cbFourCount>0) { //牌型判断 if ((AnalyseResult.cbFourCount==1)&&(cbCardCount==4)) return CT_BOMB_CARD; // if ((AnalyseResult.cbFourCount==1)&&(AnalyseResult.cbSignedCount==2)&&(cbCardCount==6)) return CT_FOUR_LINE_TAKE_ONE; if ((AnalyseResult.cbFourCount==1)&&(AnalyseResult.cbSignedCount==2)&&(cbCardCount==6)) return CT_FOUR_LINE_TAKE_ONE; if ((AnalyseResult.cbFourCount==1)&&(AnalyseResult.cbDoubleCount==2)&&(cbCardCount==8)) return CT_FOUR_LINE_TAKE_TWO; return CT_ERROR; } //三牌判断 if (AnalyseResult.cbThreeCount>0) { //三条类型 if(AnalyseResult.cbThreeCount==1 && cbCardCount==3) return CT_THREE ; //连牌判断 if (AnalyseResult.cbThreeCount>1) { //变量定义 BYTE cbCardData=AnalyseResult.cbThreeCardData[0]; BYTE cbFirstLogicValue=GetCardLogicValue(cbCardData); //错误过虑 if (cbFirstLogicValue>=15) return CT_ERROR; //连牌判断 for (BYTE i=1;i<AnalyseResult.cbThreeCount;i++) { BYTE cbCardData=AnalyseResult.cbThreeCardData[i*3]; if (cbFirstLogicValue!=(GetCardLogicValue(cbCardData)+i)) return CT_ERROR; } } //牌形判断 if (AnalyseResult.cbThreeCount*3==cbCardCount) return CT_THREE_LINE; if (AnalyseResult.cbThreeCount*4==cbCardCount) return CT_THREE_LINE_TAKE_ONE; if ((AnalyseResult.cbThreeCount*5==cbCardCount)&&(AnalyseResult.cbDoubleCount==AnalyseResult.cbThreeCount)) return CT_THREE_LINE_TAKE_TWO; return CT_ERROR; } //两张类型 if (AnalyseResult.cbDoubleCount>=3) { //变量定义 BYTE cbCardData=AnalyseResult.cbDoubleCardData[0]; BYTE cbFirstLogicValue=GetCardLogicValue(cbCardData); //错误过虑 if (cbFirstLogicValue>=15) return CT_ERROR; //连牌判断 for (BYTE i=1;i<AnalyseResult.cbDoubleCount;i++) { BYTE cbCardData=AnalyseResult.cbDoubleCardData[i*2]; if (cbFirstLogicValue!=(GetCardLogicValue(cbCardData)+i)) return CT_ERROR; } //二连判断 if ((AnalyseResult.cbDoubleCount*2)==cbCardCount) return CT_DOUBLE_LINE; return CT_ERROR; } //单张判断 if ((AnalyseResult.cbSignedCount>=5)&&(AnalyseResult.cbSignedCount==cbCardCount)) { //变量定义 BYTE cbCardData=AnalyseResult.cbSignedCardData[0]; BYTE cbFirstLogicValue=GetCardLogicValue(cbCardData); //错误过虑 if (cbFirstLogicValue>=15) return CT_ERROR; //连牌判断 for (BYTE i=1;i<AnalyseResult.cbSignedCount;i++) { BYTE cbCardData=AnalyseResult.cbSignedCardData[i]; if (cbFirstLogicValue!=(GetCardLogicValue(cbCardData)+i)) return CT_ERROR; } return CT_SINGLE_LINE; } return CT_ERROR; }
//获取类型 BYTE CGameLogic::GetCardType(const BYTE bCardData[], BYTE bCardCount) { //开始分析 switch (bCardCount) { case 1: //单牌 { return CT_SINGLE; } case 2: //对牌和火箭 { if ((bCardData[0]==0x42)&&(bCardData[1]==0x41)) return CT_MISSILE_CARD; return (GetCardLogicValue(bCardData[0])==GetCardLogicValue(bCardData[1]))?CT_DOUBLE:CT_INVALID; } case 3: case 4: //连牌和炸弹 { BYTE bLogicValue=GetCardLogicValue(bCardData[0]); for (BYTE i=1;i<bCardCount;i++) { if (bLogicValue!=GetCardLogicValue(bCardData[i])) break; } if (i==bCardCount) return (bCardCount==3)?CT_THREE:CT_BOMB_CARD; if (bCardCount==3) return CT_INVALID; break; } } //其他牌型 if (bCardCount>=4) { //分析扑克 tagAnalyseResult AnalyseResult; AnalysebCardData(bCardData,bCardCount,AnalyseResult); //四牌判断 if (AnalyseResult.bFourCount>0) { if ((AnalyseResult.bFourCount==1)&&(bCardCount==5)) return CT_FOUR_LINE_TAKE_ONE; if ((AnalyseResult.bFourCount==1)&&(AnalyseResult.bDoubleCount==1)&&(bCardCount==6)) return CT_FOUR_LINE_TAKE_ONE; if ((AnalyseResult.bFourCount==1)&&(AnalyseResult.bDoubleCount==2)&&(bCardCount==8)) return CT_FOUR_LINE_TAKE_DOUBLE; if ((AnalyseResult.bFourCount==1)&&(bCardCount==6)) return CT_FOUR_LINE_TAKE_DOUBLE; return CT_INVALID; } //三牌判断 if (AnalyseResult.bThreeCount>0) { //连牌判断 if (AnalyseResult.bThreeCount>1) { if (AnalyseResult.bThreeLogicVolue[0]==15) return CT_INVALID; for (BYTE i=1;i<AnalyseResult.bThreeCount;i++) { if (AnalyseResult.bThreeLogicVolue[i]!=(AnalyseResult.bThreeLogicVolue[0]-i)) return CT_INVALID; } } //牌形判断 if (AnalyseResult.bThreeCount*3==bCardCount) return CT_THREE_LINE; if (AnalyseResult.bThreeCount==(bCardCount-AnalyseResult.bThreeCount*3)) return CT_THREE_LINE_TAKE_ONE; if ((AnalyseResult.bDoubleCount==AnalyseResult.bThreeCount)&&(bCardCount==(AnalyseResult.bThreeCount*3+AnalyseResult.bDoubleCount*2))) return CT_THREE_LINE_TAKE_DOUBLE; return CT_INVALID; } //两张类型 if (AnalyseResult.bDoubleCount>=3) { //二连判断 if (AnalyseResult.bDoubleLogicVolue[0]!=15) { for (BYTE i=1;i<AnalyseResult.bDoubleCount;i++) { if (AnalyseResult.bDoubleLogicVolue[i]!=(AnalyseResult.bDoubleLogicVolue[0]-i)) return CT_INVALID; } if (AnalyseResult.bDoubleCount*2==bCardCount) return CT_DOUBLE_LINE; } return CT_INVALID; } //单张判断 if ((AnalyseResult.bSignedCount>=5)&&(AnalyseResult.bSignedCount==bCardCount)) { BYTE bLogicValue=GetCardLogicValue(bCardData[0]); if (bLogicValue>=15) return CT_INVALID; for (BYTE i=1;i<AnalyseResult.bSignedCount;i++) { if (GetCardLogicValue(bCardData[i])!=(bLogicValue-i)) return CT_INVALID; } return CT_ONE_LINE; } return CT_INVALID; } return CT_INVALID; }