挖坑机器人算法
#define ANDROID_USER_ITEM_SINK_HEAD_FILE
#pragma once
#include "Stdafx.h"
#include "GameLogic.h"
//
//機器人類
class CAndroidUserItemSink : public IAndroidUserItemSink
{
//游戲變量
protected:
WORD m_wBankerUser; //莊家用戶
BYTE m_cbCurrentLandScore; //已叫分數
WORD m_wOutCardUser; //出牌玩家
//撲克變量
protected:
BYTE m_cbTurnCardCount; //出牌數目
BYTE m_cbTurnCardData[MAX_COUNT]; //出牌列表
//手上撲克
protected:
BYTE m_cbHandCardData[MAX_COUNT]; //手上撲克
BYTE m_cbHandCardCount[GAME_PLAYER]; //撲克數目
//搜索結果
protected:
tagSearchCardResult m_OutCardResult; //搜索結果
//歷史撲克
protected:
//控件變量
protected:
CGameLogic m_GameLogic; //游戲邏輯
IAndroidUserItem * m_pIAndroidUserItem; //用戶接口
//函數定義
public:
//構造函數
CAndroidUserItemSink();
//析構函數
virtual ~CAndroidUserItemSink();
//基礎接口
public:
//釋放對象
virtual VOID Release() { delete this; }
//接口查詢
virtual VOID * QueryInterface(REFGUID Guid, DWORD dwQueryVer);
//控制接口
public:
//初始接口
virtual bool Initialization(IUnknownEx * pIUnknownEx);
//重置接口
virtual bool RepositionSink();
//游戲事件
public:
//時間消息
virtual bool OnEventTimer(UINT nTimerID);
//游戲消息
virtual bool OnEventGameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize);
//游戲消息
virtual bool OnEventFrameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize);
//場景消息
virtual bool OnEventSceneMessage(BYTE cbGameStatus, bool bLookonOther, VOID * pData, WORD wDataSize);
//用戶事件
public:
//用戶進入
virtual VOID OnEventUserEnter(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser);
//用戶離開
virtual VOID OnEventUserLeave(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser);
//用戶積分
virtual VOID OnEventUserScore(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser);
//用戶狀態
virtual VOID OnEventUserStatus(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser);
//用戶段位
virtual VOID OnEventUserSegment(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser);
//消息處理
protected:
//游戲開始
bool OnSubGameStart(VOID * pData, WORD wDataSize);
//用戶叫分
bool OnSubCallScore(VOID * pData, WORD wDataSize);
//莊家信息
bool OnSubBankerInfo(VOID * pData, WORD wDataSize);
//用戶出牌
bool OnSubOutCard(VOID * pData, WORD wDataSize);
//用戶放棄
bool OnSubPassCard(VOID * pData, WORD wDataSize);
//游戲結束
bool OnSubGameEnd(VOID * pData, WORD wDataSize);
public:
//思考出牌
bool AndroidThinkToOutCard(void);
};
//
#endif
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
#include "Stdafx.h"
#include "AndroidUserItemSink.h"
#include "ClogFile.h"
//
//輔助時間
#define TIME_LESS 2//最少時間
#define TIME_DISPATCH 5//發牌時間
//游戲時間
#define TIME_OUT_CARD 2//出牌時間
#define TIME_START_GAME 5//開始時間
#define TIME_CALL_SCORE 3//叫分時間
//游戲時間
#define IDI_OUT_CARD (0)//出牌定時器
#define IDI_START_GAME (1)//開始定時器
#define IDI_CALL_SCORE (2)//叫分定時器
#define IDI_AI_TALK (3)//說話定時器
//
//構造函數
CAndroidUserItemSink::CAndroidUserItemSink()
{
//游戲變量
m_wBankerUser=INVALID_CHAIR;
m_cbCurrentLandScore=0;
m_wOutCardUser=INVALID_CHAIR;
//撲克變量
m_cbTurnCardCount=0;
ZeroMemory(m_cbTurnCardData,sizeof(m_cbTurnCardData));
//手上撲克
ZeroMemory(m_cbHandCardData,sizeof(m_cbHandCardData));
ZeroMemory(m_cbHandCardCount,sizeof(m_cbHandCardCount));
ZeroMemory(&m_OutCardResult,sizeof(m_OutCardResult));
//接口變量
m_pIAndroidUserItem=NULL;;
//隨機時間
srand( (unsigned)time( NULL ) );
return;
}
//析構函數
CAndroidUserItemSink::~CAndroidUserItemSink()
{
}
//接口查詢
VOID * CAndroidUserItemSink::QueryInterface(REFGUID Guid, DWORD dwQueryVer)
{
QUERYINTERFACE(IAndroidUserItemSink,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IAndroidUserItemSink,Guid,dwQueryVer);
return NULL;
}
//初始接口
bool CAndroidUserItemSink::Initialization(IUnknownEx * pIUnknownEx)
{
//查詢接口
m_pIAndroidUserItem=QUERY_OBJECT_PTR_INTERFACE(pIUnknownEx,IAndroidUserItem);
if (m_pIAndroidUserItem==NULL) return false;
return true;
}
//重置接口
bool CAndroidUserItemSink::RepositionSink()
{
//游戲變量
m_wBankerUser=INVALID_CHAIR;
//撲克變量
m_cbTurnCardCount=0;
ZeroMemory(m_cbTurnCardData,sizeof(m_cbTurnCardData));
//手上撲克
ZeroMemory(m_cbHandCardData,sizeof(m_cbHandCardData));
ZeroMemory(m_cbHandCardCount,sizeof(m_cbHandCardCount));
return true;
}
//時間消息
bool CAndroidUserItemSink::OnEventTimer(UINT nTimerID)
{
switch (nTimerID)
{
case IDI_START_GAME://開始游戲
{
//開始判斷
m_pIAndroidUserItem->SendUserReady(NULL,0);
//將會說話
int nElapse = rand()%50 + 5;
int ifWillTalk = rand()%3;
if (ifWillTalk == 0)
{
m_pIAndroidUserItem->SetGameTimer(IDI_AI_TALK,nElapse);
}
return true;
}
case IDI_CALL_SCORE://用戶叫分
{
//構造變量
CMD_C_CallScore CallScore;
ZeroMemory(&CallScore,sizeof(CallScore));
//設置變量
CallScore.cbCallScore=m_GameLogic.LandScore(m_pIAndroidUserItem->GetChairID(), m_cbCurrentLandScore);
//發送數據
m_pIAndroidUserItem->SendSocketData(SUB_C_CALL_SCORE,&CallScore,sizeof(CallScore));
return true;
}
case IDI_OUT_CARD://用戶出牌
{
//結果判斷
if (m_OutCardResult.cbCardCount>0)
{
//構造變量
CMD_C_OutCard OutCard;
ZeroMemory(&OutCard, sizeof(OutCard));
//設置變量
OutCard.cbCardCount=m_OutCardResult.cbCardCount;
CopyMemory(OutCard.cbCardData, m_OutCardResult.cbResultCard, m_OutCardResult.cbCardCount*sizeof(BYTE));
//發送數據
WORD wHeadSize=sizeof(OutCard)-sizeof(OutCard.cbCardData);
m_pIAndroidUserItem->SendSocketData(SUB_C_OUT_CARD, &OutCard, wHeadSize+OutCard.cbCardCount*sizeof(BYTE));
}
else
{
//放棄出牌
m_pIAndroidUserItem->SendSocketData(SUB_C_PASS_CARD);
}
//重置結果
ZeroMemory(&m_OutCardResult,sizeof(m_OutCardResult));
return true;
}
case IDI_AI_TALK://機器人說話
{
WORD wChairId = m_pIAndroidUserItem->GetChairID();
if (wChairId != INVALID_CHAIR)
{
CMD_C_ReminderUserCard info;
info.nChairID = wChairId;
info.nExpressIndex = 3 + rand()%7;
m_pIAndroidUserItem->SendSocketData(SUB_C_REMINDER_USER_CARD,&info,sizeof(info));
}
return true;
}
}
return false;
}
//游戲消息
bool CAndroidUserItemSink::OnEventGameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)
{
switch (wSubCmdID)
{
case SUB_S_GAME_START://游戲開始
{
return OnSubGameStart(pData,wDataSize);
}
case SUB_S_CALL_SCORE://用戶叫分
{
return OnSubCallScore(pData,wDataSize);
}
case SUB_S_BANKER_INFO://莊家信息
{
return OnSubBankerInfo(pData,wDataSize);
}
case SUB_S_OUT_CARD://用戶出牌
{
return OnSubOutCard(pData,wDataSize);
}
case SUB_S_PASS_CARD://用戶放棄
{
return OnSubPassCard(pData,wDataSize);
}
case SUB_S_GAME_CONCLUDE://游戲結束
{
return OnSubGameEnd(pData,wDataSize);
}
}
return true;
}
//游戲消息
bool CAndroidUserItemSink::OnEventFrameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)
{
return true;
}
//場景消息
bool CAndroidUserItemSink::OnEventSceneMessage(BYTE cbGameStatus, bool bLookonOther, VOID * pData, WORD wDataSize)
{
switch (cbGameStatus)
{
case GAME_SCENE_FREE://空閑狀態
{
//效驗數據
ASSERT(wDataSize==sizeof(CMD_S_StatusFree));
if (wDataSize!=sizeof(CMD_S_StatusFree)) return false;
//變量定義
CMD_S_StatusFree * pStatusFree=(CMD_S_StatusFree *)pData;
IServerUserItem * pIServerUserItem=m_pIAndroidUserItem->GetMeUserItem();
//玩家設置
if (pIServerUserItem->GetUserStatus()!=US_READY)
{
UINT nElapse=rand()%TIME_START_GAME+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_START_GAME,nElapse);
}
return true;
}
case GAME_SCENE_CALL://叫分狀態
{
//效驗數據
if (wDataSize!=sizeof(CMD_S_StatusCall)) return false;
CMD_S_StatusCall * pStatusCall=(CMD_S_StatusCall *)pData;
//撲克數據
for (WORD i=0;i<GAME_PLAYER;i++) m_cbHandCardCount[i]=NORMAL_COUNT;
CopyMemory(m_cbHandCardData,pStatusCall->cbHandCardData,sizeof(BYTE)*NORMAL_COUNT);
//叫分設置
if (m_pIAndroidUserItem->GetChairID()==pStatusCall->wCurrentUser)
{
UINT nElapse=rand()%TIME_CALL_SCORE+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_CALL_SCORE,nElapse+TIME_DISPATCH);
}
return true;
}
case GAME_SCENE_PLAY://游戲狀態
{
//效驗數據
if (wDataSize!=sizeof(CMD_S_StatusPlay)) return false;
CMD_S_StatusPlay * pStatusPlay=(CMD_S_StatusPlay *)pData;
//出牌變量
m_cbTurnCardCount=pStatusPlay->cbTurnCardCount;
CopyMemory(m_cbTurnCardData,pStatusPlay->cbTurnCardData,m_cbTurnCardCount*sizeof(BYTE));
//撲克數據
WORD wMeChairID=m_pIAndroidUserItem->GetChairID();
CopyMemory(m_cbHandCardCount,pStatusPlay->cbHandCardCount,sizeof(m_cbHandCardCount));
CopyMemory(m_cbHandCardData,pStatusPlay->cbHandCardData,sizeof(BYTE)*m_cbHandCardCount[wMeChairID]);
//玩家設置
if (pStatusPlay->wCurrentUser==m_pIAndroidUserItem->GetChairID())
{
UINT nElapse=rand()%TIME_OUT_CARD+TIME_LESS+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_OUT_CARD,nElapse);
}
return true;
}
case SUB_GF_USER_CHAT://聊天消息
{
//跟著說話
int nElapse = rand()%3 + 1;
int ifWillTalk = rand()%7;
if (ifWillTalk == 0)
{
m_pIAndroidUserItem->SetGameTimer(IDI_AI_TALK, nElapse);
}
return true;
}
}
//錯誤斷言
ASSERT(FALSE);
return false;
}
//用戶進入
VOID CAndroidUserItemSink::OnEventUserEnter(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用戶離開
VOID CAndroidUserItemSink::OnEventUserLeave(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用戶積分
VOID CAndroidUserItemSink::OnEventUserScore(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用戶狀態
VOID CAndroidUserItemSink::OnEventUserStatus(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用戶段位
VOID CAndroidUserItemSink::OnEventUserSegment(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//游戲開始
bool CAndroidUserItemSink::OnSubGameStart(VOID * pData, WORD wDataSize)
{
//效驗參數
ASSERT(wDataSize==sizeof(CMD_S_AndroidCard));
if (wDataSize!=sizeof(CMD_S_AndroidCard)) return false;
//變量定義
CMD_S_AndroidCard * pAndroidCard=(CMD_S_AndroidCard *)pData;
//設置狀態
m_pIAndroidUserItem->SetGameStatus(GAME_SCENE_CALL);
m_cbCurrentLandScore = 0 ;
//撲克變量
m_cbTurnCardCount=0;
ZeroMemory(m_cbTurnCardData,sizeof(m_cbTurnCardData));
ZeroMemory(m_cbHandCardData,sizeof(m_cbHandCardData));
ZeroMemory(m_cbHandCardCount,sizeof(m_cbHandCardCount));
ZeroMemory(m_GameLogic.m_cbAllCardData,sizeof(m_GameLogic.m_cbAllCardData));
ZeroMemory(m_GameLogic.m_cbUserCardCount,sizeof(m_GameLogic.m_cbUserCardCount));
//手上撲克
WORD wMeChairID=m_pIAndroidUserItem->GetChairID();
for (WORD i=0;i<GAME_PLAYER;i++) m_cbHandCardCount[i]=NORMAL_COUNT;
for(WORD wChairID=0; wChairID<GAME_PLAYER; ++wChairID)
{
if(wChairID==wMeChairID)
{
CopyMemory(m_cbHandCardData,pAndroidCard->cbHandCard[wChairID],sizeof(BYTE)*NORMAL_COUNT);
}
m_GameLogic.SetUserCard(wChairID, pAndroidCard->cbHandCard[wChairID], NORMAL_COUNT) ;
}
//排列撲克
m_GameLogic.SortCardList(m_cbHandCardData,m_cbHandCardCount[wMeChairID],ST_ORDER);
//首出玩家
if (m_pIAndroidUserItem->GetChairID()==pAndroidCard->wCurrentUser)
{
UINT nElapse=rand()%TIME_CALL_SCORE+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_CALL_SCORE,nElapse+TIME_DISPATCH);
}
return true;
}
//用戶叫分
bool CAndroidUserItemSink::OnSubCallScore(VOID * pData, WORD wDataSize)
{
//效驗參數
ASSERT(wDataSize==sizeof(CMD_S_CallScore));
if (wDataSize!=sizeof(CMD_S_CallScore)) return false;
//變量定義
CMD_S_CallScore * pCallScore=(CMD_S_CallScore *)pData;
m_cbCurrentLandScore = pCallScore->cbCurrentScore ;
//用戶處理
if (m_pIAndroidUserItem->GetChairID()==pCallScore->wCurrentUser)
{
UINT nElapse=rand()%TIME_CALL_SCORE+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_CALL_SCORE,nElapse);
}
return true;
}
//莊家信息
bool CAndroidUserItemSink::OnSubBankerInfo(VOID * pData, WORD wDataSize)
{
//效驗參數
ASSERT(wDataSize==sizeof(CMD_S_BankerInfo));
if (wDataSize!=sizeof(CMD_S_BankerInfo)) return false;
//變量定義
CMD_S_BankerInfo * pBankerInfo=(CMD_S_BankerInfo *)pData;
//設置狀態
m_pIAndroidUserItem->SetGameStatus(GAME_SCENE_PLAY);
//設置變量
m_wBankerUser=pBankerInfo->wBankerUser;
m_cbHandCardCount[m_wBankerUser]+=CountArray(pBankerInfo->cbBankerCard);
//我是莊家
if (pBankerInfo->wBankerUser==m_pIAndroidUserItem->GetChairID())
{
//設置撲克
CopyMemory(&m_cbHandCardData[NORMAL_COUNT],pBankerInfo->cbBankerCard,sizeof(pBankerInfo->cbBankerCard));
//排列撲克
WORD wMeChairID=m_pIAndroidUserItem->GetChairID();
m_GameLogic.SortCardList(m_cbHandCardData,m_cbHandCardCount[wMeChairID],ST_ORDER);
}
//設置底牌
m_GameLogic.SetBackCard(pBankerInfo->wBankerUser, pBankerInfo->cbBankerCard, DIPAI_CARD_COUNT) ;
m_GameLogic.SetBanker(pBankerInfo->wBankerUser) ;
//玩家設置
if (pBankerInfo->wCurrentUser==m_pIAndroidUserItem->GetChairID())
{
AndroidThinkToOutCard();
}
return true;
}
//用戶出牌
bool CAndroidUserItemSink::OnSubOutCard(VOID * pData, WORD wDataSize)
{
//變量定義
CMD_S_OutCard * pOutCard=(CMD_S_OutCard *)pData;
WORD wHeadSize=sizeof(CMD_S_OutCard)-sizeof(pOutCard->cbCardData);
//效驗數據
ASSERT((wDataSize>=wHeadSize)&&(wDataSize==(wHeadSize+pOutCard->cbCardCount*sizeof(BYTE))));
if ((wDataSize<wHeadSize)||(wDataSize!=(wHeadSize+pOutCard->cbCardCount*sizeof(BYTE)))) return false;
//出牌變量
if (pOutCard->wCurrentUser==pOutCard->wOutCardUser)
{
m_cbTurnCardCount=0;
ZeroMemory(m_cbTurnCardData,sizeof(m_cbTurnCardData));
}
else
{
m_cbTurnCardCount=pOutCard->cbCardCount;
CopyMemory(m_cbTurnCardData,pOutCard->cbCardData,pOutCard->cbCardCount*sizeof(BYTE));
m_wOutCardUser = pOutCard->wOutCardUser ;
}
//Logic層變量
m_GameLogic.RemoveUserCardData(pOutCard->wOutCardUser, pOutCard->cbCardData, pOutCard->cbCardCount) ;
//Sink層變量
if (pOutCard->wOutCardUser == m_pIAndroidUserItem->GetChairID())
{
m_GameLogic.RemoveCard(pOutCard->cbCardData,pOutCard->cbCardCount,m_cbHandCardData,m_cbHandCardCount[m_pIAndroidUserItem->GetChairID()]);
}
m_cbHandCardCount[pOutCard->wOutCardUser] -= pOutCard->cbCardCount;
//輪到玩家
if (m_pIAndroidUserItem->GetChairID()==pOutCard->wCurrentUser)
{
AndroidThinkToOutCard();
}
return true;
}
//用戶放棄
bool CAndroidUserItemSink::OnSubPassCard(VOID * pData, WORD wDataSize)
{
//效驗數據
ASSERT(wDataSize==sizeof(CMD_S_PassCard));
if (wDataSize!=sizeof(CMD_S_PassCard)) return false;
//變量定義
CMD_S_PassCard * pPassCard=(CMD_S_PassCard *)pData;
//一輪判斷
if (pPassCard->cbTurnOver==TRUE)
{
m_cbTurnCardCount=0;
ZeroMemory(m_cbTurnCardData,sizeof(m_cbTurnCardData));
}
//玩家設置
if (m_pIAndroidUserItem->GetChairID()==pPassCard->wCurrentUser)
{
AndroidThinkToOutCard();
}
return true;
}
//游戲結束
bool CAndroidUserItemSink::OnSubGameEnd(VOID * pData, WORD wDataSize)
{
//效驗數據
ASSERT(wDataSize==sizeof(CMD_S_GameConclude));
if (wDataSize!=sizeof(CMD_S_GameConclude)) return false;
//變量定義
CMD_S_GameConclude * pGameEnd=(CMD_S_GameConclude *)pData;
//設置狀態
m_pIAndroidUserItem->SetGameStatus(GAME_SCENE_FREE);
//設置變量
m_cbTurnCardCount=0;
ZeroMemory(m_cbTurnCardData,sizeof(m_cbTurnCardData));
ZeroMemory(m_cbHandCardData,sizeof(m_cbHandCardData));
ZeroMemory(m_cbHandCardCount,sizeof(m_cbHandCardCount));
//刪除時間
m_pIAndroidUserItem->KillGameTimer(IDI_OUT_CARD);
m_pIAndroidUserItem->KillGameTimer(IDI_CALL_SCORE);
m_pIAndroidUserItem->KillGameTimer(IDI_AI_TALK);
//開始設置
UINT nElapse=rand()%TIME_START_GAME+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_START_GAME,nElapse);
return true;
}
//
//思考出牌
bool CAndroidUserItemSink::AndroidThinkToOutCard(void)
{
try
{
WORD wMeChairID=m_pIAndroidUserItem->GetChairID();
m_GameLogic.SearchOutCard(m_cbHandCardData,m_cbHandCardCount[wMeChairID],m_cbTurnCardData,m_cbTurnCardCount, m_wOutCardUser, m_pIAndroidUserItem->GetChairID(), m_OutCardResult);
m_GameLogic.SortCardList(m_OutCardResult.cbResultCard,m_OutCardResult.cbCardCount,ST_ORDER);
}
catch(...)
{
ZeroMemory(m_OutCardResult.cbResultCard, sizeof(m_OutCardResult.cbResultCard)) ;
m_OutCardResult.cbCardCount = 0 ;
}
//牌型合法
if(m_OutCardResult.cbCardCount>0 )
{
if (m_cbTurnCardCount == 0 && m_GameLogic.GetCardType(m_OutCardResult.cbResultCard, m_OutCardResult.cbCardCount) == CT_ERROR)
{
ASSERT(false) ;
ZeroMemory(&m_OutCardResult, sizeof(m_OutCardResult)) ;
}
}
//先出牌不能為空
if(m_cbTurnCardCount == 0)
{
if (m_OutCardResult.cbCardCount == 0)
{
WORD wMeChairID = m_pIAndroidUserItem->GetChairID();
//最小一張
m_OutCardResult.cbCardCount = 1 ;
m_OutCardResult.cbResultCard[0] = m_cbHandCardData[m_cbHandCardCount[wMeChairID]-1] ;
}
}
else
{
if(!m_GameLogic.CompareCard(m_cbTurnCardData, m_OutCardResult.cbResultCard, m_cbTurnCardCount, m_OutCardResult.cbCardCount))
{
ZeroMemory(&m_OutCardResult, sizeof(m_OutCardResult)) ;
}
}
//出牌事件
UINT nElapse=rand()%TIME_OUT_CARD + TIME_LESS;
//特殊情況
if (m_cbTurnCardCount==0 || m_cbHandCardCount[m_pIAndroidUserItem->GetChairID()]<=3) nElapse=2;
m_pIAndroidUserItem->SetGameTimer(IDI_OUT_CARD, nElapse);
return true;
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
#ifndef GAME_LOGIC_HEAD_FILE
#define GAME_LOGIC_HEAD_FILE
#pragma once
#include "Stdafx.h"
//
//排序類型
#define ST_ORDER 0//大小排序
#define ST_COUNT 1//數目排序
#define ST_CUSTOM 2//自定排序
//
//分析結構
struct tagAnalyseResult
{
BYTE cbBlockCount[4];//撲克數目
BYTE cbCardData[4][MAX_COUNT];//撲克數據
};
//分布信息
struct tagDistributing
{
BYTE cbCardCount;//撲克數目
BYTE cbDistributing[15][6];//分布信息
};
#define MAX_TYPE_COUNT 254
struct tagOutCardTypeResult?
{
BYTE cbCardType;//撲克類型
BYTE cbCardTypeCount;//牌型數目
BYTE cbEachHandCardCount[MAX_TYPE_COUNT];//每手個數
BYTE cbCardData[MAX_TYPE_COUNT][MAX_COUNT];//撲克數據
};
//搜索結果
struct tagSearchCardResult
{
BYTE cbCardCount;//撲克數目
BYTE cbResultCard[MAX_COUNT];//結果撲克
};
//牌型分布
struct CardsDistribution
{
//牌型數量
BYTE cbThreeLineCardsCount[4];//儲存三順
BYTE cbDoubleLineCardsCount[4];//儲存雙順
BYTE cbSingleLineCardsCount[7];//儲存單順
BYTE cbFourCardsCount;//儲存四牌
BYTE cbThreeCardsCount;//儲存三牌
BYTE cbDoubleCardsCount;//儲存對牌
BYTE cbSingleCardsCount;//儲存單牌
//牌的數值
BYTE cbThreeLineCards[4][10];//儲存三順
BYTE cbDoubleLineCards[4][10];//儲存雙順
BYTE cbSingleLineCards[7][10];//儲存單順
BYTE cbFourCards[5][4];//儲存四牌
BYTE cbThreeCards[7][3];//儲存三牌
BYTE cbDoubleCards[13][2];//儲存對牌
BYTE cbSingleCards[13];//儲存單牌
//四順暫不考慮
};
//
//游戲邏輯類
class CGameLogic
{
//變量定義
protected:
static const BYTEm_cbCardData[FULL_COUNT]; //撲克數據
//AI變量
public:
BYTE m_cbAllCardData[GAME_PLAYER][MAX_COUNT];//所有撲克
BYTE m_cbUserCardCount[GAME_PLAYER];//撲克數目
WORD m_wBankerUser;//地主玩家
//函數定義
public:
//構造函數
CGameLogic();
//析構函數
virtual ~CGameLogic();
//類型函數
public:
//獲取類型
BYTE GetCardType(const BYTE cbCardData[], BYTE cbCardCount);
//獲取數值
BYTE GetCardValue(BYTE cbCardData) { return cbCardData&MASK_VALUE; }
//獲取花色
BYTE GetCardColor(BYTE cbCardData) { return cbCardData&MASK_COLOR; }
//控制函數
public:
//排列撲克
VOID SortCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbSortType);
//刪除撲克
bool RemoveCard(const BYTE cbRemoveCard[], BYTE cbRemoveCount, BYTE cbCardData[], BYTE cbCardCount);
//邏輯函數
public:
//邏輯數值
BYTE GetCardLogicValue(BYTE cbCardData);
//對比撲克
bool CompareCard(const BYTE cbFirstCard[], const BYTE cbNextCard[], BYTE cbFirstCount, BYTE cbNextCount);
//內部函數
public:
//分析撲克
VOID AnalysebCardData(const BYTE cbCardData[], BYTE cbCardCount, tagAnalyseResult & AnalyseResult);
//設置函數
public:
//設置撲克
VOID SetUserCard(WORD wChairID, BYTE cbCardData[], BYTE cbCardCount) ;
//設置底牌
VOID SetBackCard(WORD wChairID, BYTE cbBackCardData[], BYTE cbCardCount) ;
//設置莊家
VOID SetBanker(WORD wBanker) ;
//刪除撲克
VOID RemoveUserCardData(WORD wChairID, BYTE cbRemoveCardData[], BYTE cbRemoveCardCount) ;
//出牌函數
public:
//出牌搜索
bool SearchOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, WORD wOutCardUser, WORD wMeChairID, tagSearchCardResult & m_OutCardResult);
//地主出牌(先出牌)
VOID BankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, tagSearchCardResult & m_OutCardResult) ;
//地主出牌(后出牌)
VOID BankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wOutCardUser, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult) ;
//地主上家(先出牌)
VOID UpsideOfBankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wMeChairID,tagSearchCardResult & m_OutCardResult) ;
//地主上家(后出牌)
VOID UpsideOfBankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wOutCardUser, ?const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult) ;
//地主下家(先出牌)
VOID UndersideOfBankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wMeChairID,tagSearchCardResult & m_OutCardResult) ;
//地主下家(后出牌)
VOID UndersideOfBankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wOutCardUser, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult) ;
//智能邏輯
public:
//分析拍的數據
//只分析對子
void AnalyseDoubleCardsOnly(const BYTE cbHandCardData[], BYTE cbHandCardCount, CardsDistribution& cbDoubleCards);
//只分析三牌
void AnalyseThreeCardsOnly(const BYTE cbHandCardData[], BYTE cbHandCardCount, CardsDistribution& cbThreeCards);
//只分析四牌
void AnalyseFourCardsOnly(const BYTE cbHandCardData[], BYTE cbHandCardCount, CardsDistribution& cbFourCards);
//分析我的牌
bool AnalyseMyCards(const BYTE cbCardData[], BYTE cbCardCount, CardsDistribution &myCardsDistribution);
//牌值評估
int EvaluateUserCards(const BYTE cbCardData[], BYTE cbCardCount);
//獲得最小牌
BYTE GetLestCard(const BYTE cbCardData[], BYTE cbCardCount);
//獲得最小雙牌
bool GetLestDoubleCards(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbLestDoubleCards[2]);
//最大牌值
BYTE GetAllUserLargestCardLogicValue(void);
//叫分判斷
BYTE LandScore(WORD wMeChairID, BYTE cbCurrentLandScore) ;
//連牌搜索
bool SearchLineCardType(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbLestCard, BYTE cbBlockCount, BYTE cbLineCount, tagSearchCardResult * pSearchCardResult);
//考慮自己
bool OutCardAccordingToMyCards(const BYTE cbHandCardData[], BYTE cbHandCardCount, tagSearchCardResult & m_OutCardResult);
//能壓就壓
bool OutCardForced(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult);
//強制拐牌
void OutBigCardsFirst(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, BYTE cbMeChairID, tagSearchCardResult & m_OutCardResult);
//莊家是否就剩一張牌了
bool IsBankerOnlyHaveOneCard(void);
//我已經能贏了
bool ICanWin(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult);
};
//
#endif
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
#include "StdAfx.h"
#include "GameLogic.h"
#include "ClogFile.h"
//撲克數據
const BYTE CGameLogic::m_cbCardData[FULL_COUNT]=
{
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D, //方塊 A - K
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D, //梅花 A - K
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D, //紅桃 A - K
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D, //黑桃 A - K
};
//構造函數
CGameLogic::CGameLogic()
{
}
//析構函數
CGameLogic::~CGameLogic()
{
}
//設置撲克
VOID CGameLogic::SetUserCard(WORD wChairID, BYTE cbCardData[], BYTE cbCardCount)
{
CopyMemory(m_cbAllCardData[wChairID], cbCardData, cbCardCount*sizeof(BYTE)) ;
m_cbUserCardCount[wChairID] = cbCardCount ;
//排列撲克
SortCardList(m_cbAllCardData[wChairID], cbCardCount, ST_ORDER) ;
}
//設置底牌
VOID CGameLogic::SetBackCard(WORD wChairID, BYTE cbBackCardData[], BYTE cbCardCount)
{
BYTE cbTmpCount = m_cbUserCardCount[wChairID] ;
CopyMemory(m_cbAllCardData[wChairID]+cbTmpCount, cbBackCardData, cbCardCount*sizeof(BYTE)) ;
m_cbUserCardCount[wChairID] += cbCardCount ;
//排列撲克
SortCardList(m_cbAllCardData[wChairID], m_cbUserCardCount[wChairID], ST_ORDER) ;
}
//設置莊家
VOID CGameLogic::SetBanker(WORD wBanker)?
{
m_wBankerUser = wBanker ;
}
//刪除撲克
VOID CGameLogic::RemoveUserCardData(WORD wChairID, BYTE cbRemoveCardData[], BYTE cbRemoveCardCount)?
{
bool bSuccess = RemoveCard(cbRemoveCardData, cbRemoveCardCount, m_cbAllCardData[wChairID], m_cbUserCardCount[wChairID]) ;
ASSERT(bSuccess) ;
m_cbUserCardCount[wChairID] -= cbRemoveCardCount ;
}
//獲取類型
BYTE CGameLogic::GetCardType(const BYTE cbCardData[], BYTE cbCardCount)
{
//簡單牌型
switch (cbCardCount)
{
case 0: //空牌
{
return CT_ERROR;
}
case 1: //單牌
{
return CT_SINGLE;
}
case 2: //對牌
{
if (GetCardLogicValue(cbCardData[0])==GetCardLogicValue(cbCardData[1])) return CT_DOUBLE;
return CT_ERROR;
}
}
//分析撲克
tagAnalyseResult AnalyseResult;
AnalysebCardData(cbCardData,cbCardCount,AnalyseResult);
//四牌判斷
if (AnalyseResult.cbBlockCount[3]>0)
{
//牌型判斷
if ((AnalyseResult.cbBlockCount[3]==1)&&(cbCardCount==4)) return CT_BOMB_CARD;
//連牌判斷
if (AnalyseResult.cbBlockCount[3]>2)
{
//變量定義
BYTE cbCardData=AnalyseResult.cbCardData[3][0];
BYTE cbFirstLogicValue=GetCardLogicValue(cbCardData);
//錯誤過慮
if (cbFirstLogicValue>=14) return CT_ERROR;
//連牌判斷
for (BYTE i=1;i<AnalyseResult.cbBlockCount[3];i++)
{
BYTE cbCardData=AnalyseResult.cbCardData[3][i*4];
if (cbFirstLogicValue!=(GetCardLogicValue(cbCardData)+i)) return CT_ERROR;
}
if (AnalyseResult.cbBlockCount[3]*4 == cbCardCount)
{
return CT_THREE_LINE;
}
}
return CT_ERROR;
}
//三牌判斷
if (AnalyseResult.cbBlockCount[2]>0)
{
//連牌判斷
if (AnalyseResult.cbBlockCount[2]>2)
{
//變量定義
BYTE cbCardData=AnalyseResult.cbCardData[2][0];
BYTE cbFirstLogicValue=GetCardLogicValue(cbCardData);
//錯誤過慮
if (cbFirstLogicValue>=14) return CT_ERROR;
//連牌判斷
for (BYTE i=1;i<AnalyseResult.cbBlockCount[2];i++)
{
BYTE cbCardData=AnalyseResult.cbCardData[2][i*3];
if (cbFirstLogicValue!=(GetCardLogicValue(cbCardData)+i)) return CT_ERROR;
}
if (AnalyseResult.cbBlockCount[2]*3 == cbCardCount)
{
return CT_THREE_LINE;
}
}
else if( cbCardCount == 3 )
{
return CT_THREE;
}
return CT_ERROR;
}
//兩張類型
if (AnalyseResult.cbBlockCount[1]>=3)
{
//變量定義
BYTE cbCardData=AnalyseResult.cbCardData[1][0];
BYTE cbFirstLogicValue=GetCardLogicValue(cbCardData);
//1,2,3不參與連牌
if (cbFirstLogicValue>=14) return CT_ERROR;
//連牌判斷
for (BYTE i=1;i<AnalyseResult.cbBlockCount[1];i++)
{
BYTE cbCardData=AnalyseResult.cbCardData[1][i*2];
if (cbFirstLogicValue!=(GetCardLogicValue(cbCardData)+i)) return CT_ERROR;
}
//二連判斷
if ((AnalyseResult.cbBlockCount[1]*2)==cbCardCount)
{
return CT_DOUBLE_LINE;
}
return CT_ERROR;
}
//單連判斷
if ((AnalyseResult.cbBlockCount[0]>=3)&&(AnalyseResult.cbBlockCount[0]==cbCardCount))
{
//變量定義
BYTE cbCardData=AnalyseResult.cbCardData[0][0];
BYTE cbFirstLogicValue=GetCardLogicValue(cbCardData);
//1,2,3不參與連牌
if (cbFirstLogicValue>=14) return CT_ERROR;
//連牌判斷
for (BYTE i=1; i<AnalyseResult.cbBlockCount[0]; i++)
{
BYTE cbCardData=AnalyseResult.cbCardData[0][i];
if (cbFirstLogicValue!=(GetCardLogicValue(cbCardData)+i)) return CT_ERROR;
}
return CT_SINGLE_LINE;
}
return CT_ERROR;
}
//排列撲克
VOID CGameLogic::SortCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbSortType)
{
//數目過慮
if (cbCardCount==0) return;
if (cbSortType==ST_CUSTOM) return;
//轉換數值
BYTE cbSortValue[MAX_COUNT];
for (BYTE i=0;i<cbCardCount;i++) cbSortValue[i]=GetCardLogicValue(cbCardData[i]);
//排序操作
bool bSorted=true;
BYTE cbSwitchData=0,cbLast=cbCardCount-1;
do
{
bSorted=true;
for (BYTE i=0;i<cbLast;i++)
{
if ((cbSortValue[i]<cbSortValue[i+1])||
((cbSortValue[i]==cbSortValue[i+1])&&(cbCardData[i]<cbCardData[i+1])))
{
//設置標志
bSorted=false;
//撲克數據
cbSwitchData=cbCardData[i];
cbCardData[i]=cbCardData[i+1];
cbCardData[i+1]=cbSwitchData;
//排序權位
cbSwitchData=cbSortValue[i];
cbSortValue[i]=cbSortValue[i+1];
cbSortValue[i+1]=cbSwitchData;
}
}
cbLast--;
} while(bSorted==false);
//數目排序
if (cbSortType==ST_COUNT)
{
//變量定義
BYTE cbCardIndex=0;
//分析撲克
tagAnalyseResult AnalyseResult;
AnalysebCardData(&cbCardData[cbCardIndex],cbCardCount-cbCardIndex,AnalyseResult);
//提取撲克
for (BYTE i=0;i<CountArray(AnalyseResult.cbBlockCount);i++)
{
//拷貝撲克
BYTE cbIndex=CountArray(AnalyseResult.cbBlockCount)-i-1;
CopyMemory(&cbCardData[cbCardIndex],AnalyseResult.cbCardData[cbIndex],AnalyseResult.cbBlockCount[cbIndex]*(cbIndex+1)*sizeof(BYTE));
//設置索引
cbCardIndex+=AnalyseResult.cbBlockCount[cbIndex]*(cbIndex+1)*sizeof(BYTE);
}
}
return;
}
//刪除撲克
bool CGameLogic::RemoveCard(const BYTE cbRemoveCard[], BYTE cbRemoveCount, BYTE cbCardData[], BYTE cbCardCount)
{
//檢驗數據
ASSERT(cbRemoveCount<=cbCardCount);
//定義變量
BYTE cbDeleteCount=0,cbTempCardData[MAX_COUNT];
if (cbCardCount>CountArray(cbTempCardData)) return false;
CopyMemory(cbTempCardData,cbCardData,cbCardCount*sizeof(cbCardData[0]));
//置零撲克
for (BYTE i=0;i<cbRemoveCount;i++)
{
for (BYTE j=0;j<cbCardCount;j++)
{
if (cbRemoveCard[i]==cbTempCardData[j])
{
cbDeleteCount++;
cbTempCardData[j]=0x00;
break;
}
}
}
if (cbDeleteCount!=cbRemoveCount) return false;
//清理撲克
BYTE cbCardPos=0;
ZeroMemory(cbCardData,cbCardCount);
for (BYTE i=0;i<cbCardCount;i++)
{
if (cbTempCardData[i]!=0x00) cbCardData[cbCardPos++]=cbTempCardData[i];
}
return true;
}
//邏輯數值
BYTE CGameLogic::GetCardLogicValue(BYTE cbCardData)
{
//撲克屬性
BYTE cbCardColor=GetCardColor(cbCardData);
BYTE cbCardValue=GetCardValue(cbCardData);
//轉換數值
return (cbCardValue<=3 && cbCardValue>=1)?(cbCardValue+13):cbCardValue;
}
//對比撲克
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 || cbFirstType==CT_ERROR) return false;
//規則判斷
if ((cbFirstType!=cbNextType)||(cbFirstCount!=cbNextCount)) return false;
//只比第一張
return GetCardLogicValue(cbNextCard[0])>GetCardLogicValue(cbFirstCard[0]);
}
//分析撲克
VOID CGameLogic::AnalysebCardData(const BYTE cbCardData[], BYTE cbCardCount, tagAnalyseResult & AnalyseResult)
{
//設置結果
ZeroMemory(&AnalyseResult,sizeof(AnalyseResult));
//撲克分析
for (BYTE i=0;i<cbCardCount;i++)
{
//變量定義
BYTE cbSameCount=1,cbCardValueTemp=0;
BYTE cbLogicValue=GetCardLogicValue(cbCardData[i]);
//搜索同牌
for (BYTE j=i+1;j<cbCardCount;j++)
{
//獲取撲克
if (GetCardLogicValue(cbCardData[j])!=cbLogicValue) break;
//設置變量
cbSameCount++;
}
//設置結果
BYTE cbIndex=AnalyseResult.cbBlockCount[cbSameCount-1]++;
for (BYTE j=0;j<cbSameCount;j++) AnalyseResult.cbCardData[cbSameCount-1][cbIndex*cbSameCount+j]=cbCardData[i+j];
//設置索引
i+=cbSameCount-1;
}
return;
}
//最大牌值
BYTE CGameLogic::GetAllUserLargestCardLogicValue(void)
{
BYTE LargestCardLogicValue = 0x00;
for (int playerID=0; playerID<3; playerID++)
{
for (int i=0;i<m_cbUserCardCount[playerID];i++)
{
if (GetCardLogicValue(m_cbAllCardData[playerID][i]) > LargestCardLogicValue)
{
LargestCardLogicValue = GetCardLogicValue(m_cbAllCardData[playerID][i]);
}
}
}
return LargestCardLogicValue;
}
//獲得最小牌
BYTE CGameLogic::GetLestCard(const BYTE cbCardData[], BYTE cbCardCount)
{
if(cbCardCount == 0) return 0;?
BYTE cbTmpCardData[MAX_COUNT] = {0};
CopyMemory(cbTmpCardData,cbCardData,cbCardCount);
SortCardList(cbTmpCardData,cbCardCount,ST_ORDER);
return cbTmpCardData[cbCardCount-1];
}
//莊家是否就剩一張牌了
bool CGameLogic::IsBankerOnlyHaveOneCard(void)
{
return m_cbUserCardCount[m_wBankerUser] == 1 ? true : false;
}
//獲得最小雙牌
bool CGameLogic::GetLestDoubleCards(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbLestDoubleCards[2])
{
//存在雙牌
bool bExistDoubleCards = false;
for (int i=cbHandCardCount-1; i>=0; i--)
{
BYTE cbCardCount = 1;
cbLestDoubleCards[0]=cbHandCardData[i];
if (cbLestDoubleCards[0] == 0x00) continue;
for (int j=0; j<cbHandCardCount; j++)
{
if (GetCardLogicValue(cbHandCardData[i])==GetCardLogicValue(cbHandCardData[j]) && i!=j)
{
cbCardCount = 2;
cbLestDoubleCards[1]=cbHandCardData[j];
return true;
}
}
}
ZeroMemory(cbLestDoubleCards,sizeof(BYTE)*2);
return false;
}
//只分析對子
void CGameLogic::AnalyseDoubleCardsOnly(const BYTE cbHandCardData[], BYTE cbHandCardCount, CardsDistribution& cbDoubleCards)
{
//三牌,四牌也算對子
ZeroMemory(&cbDoubleCards,sizeof(CardsDistribution));
for (BYTE cbCardID=GetCardLogicValue(GetLestCard(cbHandCardData,cbHandCardCount)); cbCardID<=GetAllUserLargestCardLogicValue(); cbCardID++)
{
int iHaveThisCardCount = 0;
BYTE cbCardBuffer[2];
for (int i=0; i<cbHandCardCount; i++)
{
if (GetCardLogicValue(cbHandCardData[i]) == cbCardID)
{
cbCardBuffer[iHaveThisCardCount ++] = cbHandCardData[i];
if (iHaveThisCardCount == 2)
{
CopyMemory(cbDoubleCards.cbDoubleCards[cbDoubleCards.cbDoubleCardsCount], cbCardBuffer, 2);
cbDoubleCards.cbDoubleCardsCount ++;
break;
}
}
}
}
}
//只分析三牌
void CGameLogic::AnalyseThreeCardsOnly(const BYTE cbHandCardData[], BYTE cbHandCardCount, CardsDistribution& cbThreeCards)
{
//四牌也算三牌
ZeroMemory(&cbThreeCards,sizeof(CardsDistribution));
for (BYTE cbCardID=GetCardLogicValue(GetLestCard(cbHandCardData,cbHandCardCount)); cbCardID<=GetAllUserLargestCardLogicValue(); cbCardID++)
{
int iHaveThisCardCount = 0;
BYTE cbCardBuffer[3];
for (int i=0; i<cbHandCardCount; i++)
{
if (GetCardLogicValue(cbHandCardData[i]) == cbCardID)
{
cbCardBuffer[iHaveThisCardCount ++] = cbHandCardData[i];
if (iHaveThisCardCount == 3)
{
CopyMemory(cbThreeCards.cbThreeCards[cbThreeCards.cbThreeCardsCount], cbCardBuffer, 3);
cbThreeCards.cbThreeCardsCount ++;
break;
}
}
}
}
}
//只分析四牌
void CGameLogic::AnalyseFourCardsOnly(const BYTE cbHandCardData[], BYTE cbHandCardCount, CardsDistribution& cbFourCards)
{
ZeroMemory(&cbFourCards,sizeof(CardsDistribution));
for (BYTE cbCardID=GetCardLogicValue(GetLestCard(cbHandCardData,cbHandCardCount)); cbCardID<=GetAllUserLargestCardLogicValue(); cbCardID++)
{
int iHaveThisCardCount = 0;
BYTE cbCardBuffer[4];
for (int i=0; i<cbHandCardCount; i++)
{
if (GetCardLogicValue(cbHandCardData[i]) == cbCardID)
{
cbCardBuffer[iHaveThisCardCount ++] = cbHandCardData[i];
if (iHaveThisCardCount == 4)
{
CopyMemory(cbFourCards.cbFourCards[cbFourCards.cbFourCardsCount], cbCardBuffer, 4);
cbFourCards.cbFourCardsCount ++;
break;
}
}
}
}
}
//牌值評估
int CGameLogic::EvaluateUserCards(const BYTE cbCardData[], BYTE cbCardCount)
{
/*
1.擁有一張最大牌 評估值+2
2.擁有一張二大牌 評估值+1
3.擁有一張單牌(小于10) 評估值-1
4.所有牌的平均值a 評估值+(a-7)* 2
5.牌的手數 ? ? ? ? ? ? ? ? ? ? ?評估值+(4-a)*4
*/
//大牌評估
int iEvaluateValue = 0;
BYTE LargestCardLogicValue = GetAllUserLargestCardLogicValue();
for (int i=0; i<cbCardCount; i++)
{
if (GetCardLogicValue(cbCardData[i]) == LargestCardLogicValue)
{
iEvaluateValue += 2;
}
}
for (int i=0; i<cbCardCount; i++)
{
if (GetCardLogicValue(cbCardData[i]) == LargestCardLogicValue-1)
{
iEvaluateValue += 1;
}
}
//單牌評估
CardsDistribution myCardsDistribution;
AnalyseMyCards(cbCardData,cbCardCount,myCardsDistribution);
BYTE Card10LogicValue = GetCardLogicValue(0x0A);
for (int i=0; i<myCardsDistribution.cbSingleCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbSingleCards[i]) < Card10LogicValue)
{
iEvaluateValue -= 1;
}
}
//平均值評估
int AllCardsSum = 0;
for (int i=0; i<cbCardCount; i++)
{
AllCardsSum += GetCardLogicValue(cbCardData[i]);
}
iEvaluateValue += ((AllCardsSum/cbCardCount)-7) * 2;
//牌的手數
CardsDistribution tCardsDistribution;
AnalyseMyCards(cbCardData,cbCardCount,tCardsDistribution);
int cardsOutCount = tCardsDistribution.cbSingleCardsCount + tCardsDistribution.cbDoubleCardsCount + tCardsDistribution.cbThreeCardsCount + tCardsDistribution.cbFourCardsCount
? ? ? ? ? ? ? ?+ tCardsDistribution.cbSingleLineCardsCount[0]+ tCardsDistribution.cbSingleLineCardsCount[1] + tCardsDistribution.cbDoubleLineCardsCount[0] + tCardsDistribution.cbThreeLineCardsCount[0] ;
iEvaluateValue += (4 - cardsOutCount)*4;
return iEvaluateValue;
}
//
//連牌搜索
//參數三:連牌中最小值 ? 參數四:單連、雙連、三連、四連 ? 參數五:連子的長度
bool CGameLogic::SearchLineCardType(const BYTE cbHandCardData[], BYTE cbHandCardCount, BYTE cbLestCard, BYTE cbBlockCount, BYTE cbLineCount, tagSearchCardResult * pSearchCardResult)
{
ZeroMemory(pSearchCardResult, sizeof(tagSearchCardResult));
//確定起始值
BYTE cbReferIndex = GetCardLogicValue(cbLestCard);
//長度判斷
if(cbHandCardCount < cbLineCount*cbBlockCount) return false;
if (cbReferIndex+cbLineCount-1>GetCardLogicValue(0x0D)) return false;
//拷貝數據
BYTE tmpHandCard[MAX_COUNT] = {0};
CopyMemory(tmpHandCard,cbHandCardData,cbHandCardCount);
//查詢連牌
for (int cardNum=0; cardNum<cbLineCount; cardNum++)
{
//確定牌值
BYTE cbCardLogicValue = GetCardLogicValue(cbLestCard) + cardNum;
//存在該牌
bool bExistThisCard = false;
//單順查詢
for (int i=0;i<cbHandCardCount;i++)
{
if (GetCardLogicValue(tmpHandCard[i]) == cbCardLogicValue)
{
pSearchCardResult->cbResultCard[pSearchCardResult->cbCardCount++] = tmpHandCard[i];
tmpHandCard[i] = 0x00;
if (cbBlockCount==1) bExistThisCard = true;
break;
}
}
//雙連查詢
if (cbBlockCount >= 2)
{
for (int i=0;i<cbHandCardCount;i++)
{
if (GetCardLogicValue(tmpHandCard[i]) == cbCardLogicValue)
{
pSearchCardResult->cbResultCard[pSearchCardResult->cbCardCount++] = tmpHandCard[i];
tmpHandCard[i] = 0x00;
if (cbBlockCount==2) bExistThisCard = true;
break;
}
}
}
//三順查詢
if (cbBlockCount >= 3)
{
for (int i=0;i<cbHandCardCount;i++)
{
if (GetCardLogicValue(tmpHandCard[i]) == cbCardLogicValue)
{
pSearchCardResult->cbResultCard[pSearchCardResult->cbCardCount++] = tmpHandCard[i];
tmpHandCard[i] = 0x00;
if (cbBlockCount==3) bExistThisCard = true;
break;
}
}
}
if (!bExistThisCard)
{
ZeroMemory(pSearchCardResult, sizeof(tagSearchCardResult));
return false;
}
}
//搜到了結果
return true;
}
//分析我的牌
bool CGameLogic::AnalyseMyCards(const BYTE cbCardData[], BYTE cbCardCount, CardsDistribution &myCardsDistribution)
{
//數據校驗
if(cbCardCount <= 0) return false;
//臨時變量
BYTE cbTmpCardData[MAX_COUNT] = {0};
BYTE cbTmpCardCount = cbCardCount;
CopyMemory(cbTmpCardData,cbCardData, cbCardCount);
SortCardList(cbTmpCardData, cbCardCount, ST_ORDER);
//變量初始化
ZeroMemory(&myCardsDistribution, sizeof(myCardsDistribution));
//分析三順
{
//雙連個數
int iThreeLineCount = 0;
//最小的牌
BYTE cbLestCard = GetLestCard(cbTmpCardData, cbTmpCardCount);
for (BYTE cbStartCard=GetCardLogicValue(cbLestCard); cbStartCard<=GetCardLogicValue(0x0B); cbStartCard++)
{
for (int iLineLength=10; iLineLength>=3; iLineLength--)
{
//搜到的結果
tagSearchCardResult tmpResult = {0};
bool bFindResult = SearchLineCardType(cbTmpCardData, cbTmpCardCount, cbStartCard, 3, iLineLength, &tmpResult);
if (bFindResult)
{
//記錄數據
CopyMemory(myCardsDistribution.cbThreeLineCards[iThreeLineCount], tmpResult.cbResultCard, tmpResult.cbCardCount);
myCardsDistribution.cbThreeLineCardsCount[iThreeLineCount]=iLineLength;
//移除數據
RemoveCard(tmpResult.cbResultCard, tmpResult.cbCardCount, cbTmpCardData, cbTmpCardCount);
cbTmpCardCount -= tmpResult.cbCardCount;
iThreeLineCount ++;
break;
}
}
}
}
//分析雙順
{
//雙連個數
int iDoubleLineCount = 0;
//最小的牌
BYTE cbLestCard = GetLestCard(cbTmpCardData, cbTmpCardCount);
for (BYTE cbStartCard=GetCardLogicValue(cbLestCard); cbStartCard<=GetCardLogicValue(0x0B); cbStartCard++)
{
for (int iLineLength=10; iLineLength>=3; iLineLength--)
{
//搜到的結果
tagSearchCardResult tmpResult = {0};
bool bFindResult = SearchLineCardType(cbTmpCardData, cbTmpCardCount, cbStartCard, 2, iLineLength, &tmpResult);
if (bFindResult)
{
//記錄數據
CopyMemory(myCardsDistribution.cbDoubleLineCards[iDoubleLineCount], tmpResult.cbResultCard, tmpResult.cbCardCount);
myCardsDistribution.cbDoubleLineCardsCount[iDoubleLineCount]=iLineLength;
//移除數據
RemoveCard(tmpResult.cbResultCard, tmpResult.cbCardCount, cbTmpCardData, cbTmpCardCount);
cbTmpCardCount -= tmpResult.cbCardCount;
iDoubleLineCount ++;
break;
}
}
}
}
//分析單順
{
//單順個數
int iSingleLineCount = 0;
//最小的牌
BYTE cbLestCard = GetLestCard(cbTmpCardData, cbTmpCardCount);
for (BYTE cbStartCard=GetCardLogicValue(cbLestCard); cbStartCard<=GetCardLogicValue(0x0B); cbStartCard++)
{
for (int iLineLength=10; iLineLength>=3; iLineLength--)
{
//搜到的結果
tagSearchCardResult tmpResult = {0};
bool bFindResult = SearchLineCardType(cbTmpCardData, cbTmpCardCount, cbStartCard, 1, iLineLength, &tmpResult);
if (bFindResult)
{
//記錄數據
CopyMemory(myCardsDistribution.cbSingleLineCards[iSingleLineCount], tmpResult.cbResultCard, tmpResult.cbCardCount );
myCardsDistribution.cbSingleLineCardsCount[iSingleLineCount] = iLineLength;
//移除數據
RemoveCard(tmpResult.cbResultCard, tmpResult.cbCardCount, cbTmpCardData, cbTmpCardCount);
cbTmpCardCount -= tmpResult.cbCardCount;
iSingleLineCount++;
break;
}
}
}
}
//分析四牌
{
//四牌個數
int iFourCardsCount = 0;
for (BYTE cardID=GetCardLogicValue(GetLestCard(cbTmpCardData,cbTmpCardCount)); cardID<=GetCardLogicValue(0x03); cardID++)
{
int iHaveCount = 0;
BYTE cbFourCard[4]={0};
for (int i=0;i<cbTmpCardCount;i++)
{
if (GetCardLogicValue(cbTmpCardData[i]) == cardID)
{
cbFourCard[iHaveCount++]=cbTmpCardData[i];
}
}
if (iHaveCount == 4)
{
//記錄數據
CopyMemory(myCardsDistribution.cbFourCards[iFourCardsCount++], cbFourCard, 4);
myCardsDistribution.cbFourCardsCount ++;
//移除數據
RemoveCard(cbFourCard, 4, cbTmpCardData, cbTmpCardCount);
cbTmpCardCount -= 4;
}
}
}
//分析三牌
{
//三牌個數
int iThreeCardsCount = 0;
for (BYTE cardID=GetCardLogicValue(GetLestCard(cbTmpCardData,cbTmpCardCount)); cardID<=GetCardLogicValue(0x03); cardID++)
{
int iHaveCount = 0;
BYTE cbThreeCard[3]={0};
for (int i=0;i<cbTmpCardCount;i++)
{
if (GetCardLogicValue(cbTmpCardData[i]) == cardID)
{
cbThreeCard[iHaveCount++]=cbTmpCardData[i];
}
}
if (iHaveCount == 3)
{
//記錄數據
CopyMemory(myCardsDistribution.cbThreeCards[iThreeCardsCount++], cbThreeCard, 3);
myCardsDistribution.cbThreeCardsCount ++;
//移除數據
RemoveCard(cbThreeCard, 3, cbTmpCardData, cbTmpCardCount);
cbTmpCardCount -= 3;
}
}
}
//分析對子
{
//對子個數
int iDoubleCardsCount = 0;
for (BYTE cardID=GetCardLogicValue(GetLestCard(cbTmpCardData,cbTmpCardCount)); cardID<=GetCardLogicValue(0x03); cardID++)
{
int iHaveCount = 0;
BYTE cbDoubleCard[2]={0};
for (int i=0;i<cbTmpCardCount;i++)
{
if (GetCardLogicValue(cbTmpCardData[i]) == cardID)
{
cbDoubleCard[iHaveCount++]=cbTmpCardData[i];
}
}
if (iHaveCount == 2)
{
//記錄數據
CopyMemory(myCardsDistribution.cbDoubleCards[iDoubleCardsCount++], cbDoubleCard, 2);
myCardsDistribution.cbDoubleCardsCount ++;
//移除數據
RemoveCard(cbDoubleCard, 2, cbTmpCardData, cbTmpCardCount);
cbTmpCardCount -= 2;
}
}
}
//分析單牌
{
//記錄數據
CopyMemory(myCardsDistribution.cbSingleCards, cbTmpCardData, cbTmpCardCount);
myCardsDistribution.cbSingleCardsCount = cbTmpCardCount;
}
return true;
}
//
// 上面:只是分析 ? ? ? ? 下面:動作邏輯
//
//叫分邏輯
BYTE CGameLogic::LandScore(WORD wMeChairID, BYTE cbCurrentLandScore)
{
//
//四個3或者三個3+兩個2或者兩個3+三個2以上 ? 叫3分
//兩個3+兩個2或者三個3+一個2 ? ? ? ? ? ? ? ?叫2分
//無3 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 不叫牌 ?
//其他 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?叫1分
//將會叫分
BYTE AndriodWillCall = 0;
//有幾張3
int iHave3Count = 0;
BYTE cbCard3LogicValue = GetCardLogicValue(0x03);
for (int i=0; i<NORMAL_COUNT; i++)
{
if (GetCardLogicValue(m_cbAllCardData[wMeChairID][i]) == cbCard3LogicValue) iHave3Count++;
}
//有幾張2
int iHave2Count = 0;
BYTE cbCard2LogicValue = GetCardLogicValue(0x02);
for (int i=0; i<NORMAL_COUNT; i++)
{
if (GetCardLogicValue(m_cbAllCardData[wMeChairID][i]) == cbCard2LogicValue) iHave2Count++;
}
if (iHave3Count==4 || (iHave3Count==3 && iHave2Count>=2) || (iHave3Count==2 && iHave2Count>=3))
{
AndriodWillCall = 3;
}
else if ((iHave3Count==2 && iHave2Count==2) || (iHave3Count==3))
{
AndriodWillCall = 2;
}
else if (iHave3Count == 0)
{
AndriodWillCall = 0;
}
else
{
AndriodWillCall = 1;
}
return AndriodWillCall > cbCurrentLandScore ? AndriodWillCall : 0;
}
//只考慮自己
bool CGameLogic::OutCardAccordingToMyCards(const BYTE cbHandCardData[], BYTE cbHandCardCount, tagSearchCardResult & m_OutCardResult)
{
//我已能贏
if (ICanWin(cbHandCardData,cbHandCardCount,NULL,0,m_OutCardResult)) return true;
//分析數據
CardsDistribution myCardsDistribution;
AnalyseMyCards(cbHandCardData, cbHandCardCount, myCardsDistribution);
//出單張牌
if (myCardsDistribution.cbSingleCardsCount >= 1)
{
//防止白扔最大大牌
if (!(myCardsDistribution.cbSingleCardsCount==1 && GetCardLogicValue(myCardsDistribution.cbSingleCards[0])==GetAllUserLargestCardLogicValue()))
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleCards[myCardsDistribution.cbSingleCardsCount-1], 1);
return true;
}
}
//出對子牌
if (myCardsDistribution.cbDoubleCardsCount >= 1)
{
if (
//一個小對子
(myCardsDistribution.cbDoubleCardsCount==1 && GetCardLogicValue(myCardsDistribution.cbDoubleCards[0][0])<GetCardLogicValue(0x0A))
//三對以上
||(myCardsDistribution.cbDoubleCardsCount>=3)
//手中的牌已經不多了
||(myCardsDistribution.cbDoubleCardsCount>=1 && cbHandCardCount<=5)
)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleCards[0], 2);
return true;
}
}
//出單順牌
if (myCardsDistribution.cbSingleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbSingleLineCardsCount[0];
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[0], myCardsDistribution.cbSingleLineCardsCount[0]);
return true;
}
//出三張牌
if (myCardsDistribution.cbThreeCardsCount >= 1)
{
//防止白扔大牌
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[0][0]) < GetAllUserLargestCardLogicValue()-1)
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbThreeCards[0], 3);
return true;
}
}
//出四張牌
if (myCardsDistribution.cbFourCardsCount >= 1)
{
//防止白扔大牌
if (GetCardLogicValue(myCardsDistribution.cbFourCards[0][0]) < GetAllUserLargestCardLogicValue()-1)
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbFourCards[0], 3);
return true;
}
}
//出雙順
if (myCardsDistribution.cbDoubleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbDoubleLineCardsCount[0] * 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleLineCards[0], myCardsDistribution.cbDoubleLineCardsCount[0]*2);
return true;
}
return true;
}
//能壓就壓
bool CGameLogic::OutCardForced(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult)
{
//變量初始化
ZeroMemory(&m_OutCardResult,sizeof(tagSearchCardResult));
//牌的類型
BYTE userCardType = GetCardType(cbTurnCardData,cbTurnCardCount);
//自己的牌
CardsDistribution myCardsDistribution;
AnalyseMyCards(cbHandCardData,cbHandCardCount,myCardsDistribution);
switch (userCardType)
{
case CT_SINGLE:
{
if (myCardsDistribution.cbSingleCardsCount > 0)//有單牌
{
for (int i=myCardsDistribution.cbSingleCardsCount-1; i>=0; i--)
{
//尋找單排中打得過的
if (GetCardLogicValue(myCardsDistribution.cbSingleCards[i]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleCards[i], 1);
return true;
}
}
//沒有找到
if (GetCardLogicValue(cbHandCardData[0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, cbHandCardData, 1);
return true;
}
}
else//無單牌
{
//最大牌打死
if (GetCardLogicValue(cbHandCardData[0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, cbHandCardData, 1);
return true;
}
}
}
break;
case CT_DOUBLE:
{
if (myCardsDistribution.cbDoubleCardsCount > 0)//有對子
{
for (int i=0; i<myCardsDistribution.cbDoubleCardsCount; i++)
{
//尋找對子中打得過的
if (GetCardLogicValue(myCardsDistribution.cbDoubleCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbDoubleCards[i][0])==GetAllUserLargestCardLogicValue()&& cbHandCardCount>7 && GetCardType(m_cbAllCardData[m_wBankerUser],m_cbUserCardCount[m_wBankerUser]) == CT_ERROR))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbDoubleCards[i], 2);
return true;
}
}
}
}
else//無對子
{
//用三牌拆
if (myCardsDistribution.cbThreeCardsCount > 0)//有三牌
{
for (int i=0; i<myCardsDistribution.cbThreeCardsCount; i++)
{
//尋找三牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbThreeCards[i], 2);
return true;
}
}
}
//用四牌拆
if (myCardsDistribution.cbFourCardsCount > 0)//有四牌
{
for (int i=0; i<myCardsDistribution.cbFourCardsCount; i++)
{
//尋找三牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 2);
return true;
}
}
}
//只要能打死肯定得打死
for (int iCardID=GetCardLogicValue(cbTurnCardData[0])+1; iCardID<=GetCardLogicValue(0x03); iCardID++)
{
int iHaveThisCardCount = 0;
BYTE cbCardBuffer[4] = {0};
for (int i=0; i<cbHandCardCount; i++)
{
if (GetCardLogicValue(cbHandCardData[i]) == iCardID)
{
cbCardBuffer[iHaveThisCardCount++] = cbHandCardData[i];
}
}
if (iHaveThisCardCount>=2)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, cbCardBuffer, 2);
return true;
}
}
}
}
break;
case CT_THREE:
{
if (myCardsDistribution.cbThreeCardsCount > 0)//有三牌
{
for (int i=0; i<myCardsDistribution.cbThreeCardsCount; i++)
{
//尋找三牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0])==GetAllUserLargestCardLogicValue()&& cbHandCardCount>7 && GetCardType(m_cbAllCardData[m_wBankerUser],m_cbUserCardCount[m_wBankerUser]) == CT_ERROR))
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbThreeCards[i], 3);
return true;
}
}
}
}
//用四牌拆
if (myCardsDistribution.cbFourCardsCount > 0)//有四牌
{
for (int i=0; i<myCardsDistribution.cbFourCardsCount; i++)
{
//尋找三牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbFourCards[i][0])==GetAllUserLargestCardLogicValue()&& cbHandCardCount>7 && GetCardType(m_cbAllCardData[m_wBankerUser],m_cbUserCardCount[m_wBankerUser]) == CT_ERROR))
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 3);
return true;
}
}
}
}
//只要能打死肯定得打死
for (int iCardID=GetCardLogicValue(cbTurnCardData[0])+1; iCardID<=GetCardLogicValue(0x03); iCardID++)
{
int iHaveThisCardCount = 0;
BYTE cbCardBuffer[4] = {0};
for (int i=0; i<cbHandCardCount; i++)
{
if (GetCardLogicValue(cbHandCardData[i]) == iCardID)
{
cbCardBuffer[iHaveThisCardCount++] = cbHandCardData[i];
}
}
if (iHaveThisCardCount>=3)
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, cbCardBuffer, 3);
return true;
}
}
}
break;
case CT_BOMB_CARD:
{
if (myCardsDistribution.cbFourCardsCount > 0)//有四牌
{
for (int i=myCardsDistribution.cbFourCardsCount-1; i>=0; i--)
{
//尋找四牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbFourCards[i][0])==GetAllUserLargestCardLogicValue()&& cbHandCardCount>7 && GetCardType(m_cbAllCardData[m_wBankerUser],m_cbUserCardCount[m_wBankerUser]) == CT_ERROR))
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 4);
return true;
}
}
}
}
//只要能打死肯定得打死
for (int iCardID=GetCardLogicValue(cbTurnCardData[0])+1; iCardID<=GetCardLogicValue(0x03); iCardID++)
{
int iHaveThisCardCount = 0;
BYTE cbCardBuffer[4] = {0};
for (int i=0; i<cbHandCardCount; i++)
{
if (GetCardLogicValue(cbHandCardData[i]) == iCardID)
{
cbCardBuffer[iHaveThisCardCount++] = cbHandCardData[i];
}
}
if (iHaveThisCardCount>=4)
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, cbCardBuffer, 4);
return true;
}
}
}
break;
case CT_SINGLE_LINE:
{
//遍歷所有鏈子
for (int i=0; i<7; i++)
{
//鏈子數目正好
if (myCardsDistribution.cbSingleLineCardsCount[i] == cbTurnCardCount)
{
//且能大過
if (GetCardLogicValue(cbTurnCardData[0]) < GetCardLogicValue(myCardsDistribution.cbSingleLineCards[i][cbTurnCardCount-1]))
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbSingleLineCards[i], cbTurnCardCount);
return true;
}
}
}
//不行就拆
for (int i=0; i<7; i++)
{
//可以拆成兩聯鏈子
if (myCardsDistribution.cbSingleLineCardsCount[i] >= cbTurnCardCount + 3)
{
//且能大過
if (GetCardLogicValue(cbTurnCardData[0]) < GetCardLogicValue(myCardsDistribution.cbSingleLineCards[i][myCardsDistribution.cbSingleLineCardsCount[i]-1]))
{
//挑大的出
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[i][0] + myCardsDistribution.cbSingleLineCardsCount[i] - cbTurnCardCount, cbTurnCardCount);
return true;
}
}
}
//不能拆成兩聯也得打死
for (int i=0; i<7; i++)
{
if (myCardsDistribution.cbSingleLineCardsCount[i] > cbTurnCardCount)
{
//且能大過
if (GetCardLogicValue(cbTurnCardData[0]) < GetCardLogicValue(myCardsDistribution.cbSingleLineCards[i][myCardsDistribution.cbSingleLineCardsCount[i]-1]))
{
//挑大的出
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[i][0] + myCardsDistribution.cbSingleLineCardsCount[i] - cbTurnCardCount, cbTurnCardCount);
return true;
}
}
}
//只要能打死肯定得打死
for (int iCardID=GetCardLogicValue(cbTurnCardData[0])+1; iCardID<=GetCardLogicValue(0x0B); iCardID++)
{
tagSearchCardResult SearchLineCardResult;
bool bFindLine = SearchLineCardType(cbHandCardData,cbHandCardCount,iCardID,1,cbTurnCardCount,&SearchLineCardResult);
if (bFindLine)
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, SearchLineCardResult.cbResultCard, cbTurnCardCount);
return true;
}
}
}
break;
case CT_DOUBLE_LINE:
{
//只要能打死肯定得打死
for (int iCardID=GetCardLogicValue(cbTurnCardData[0])+1; iCardID<=GetCardLogicValue(0x0B); iCardID++)
{
tagSearchCardResult SearchLineCardResult;
bool bFindLine = SearchLineCardType(cbHandCardData,cbHandCardCount,iCardID,2,cbTurnCardCount/2,&SearchLineCardResult);
if (bFindLine)
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, SearchLineCardResult.cbResultCard, cbTurnCardCount);
return true;
}
}
}
break;
case CT_THREE_LINE:
{
//只要能打死肯定得打死
for (int iCardID=GetCardLogicValue(cbTurnCardData[0])+1; iCardID<=GetCardLogicValue(0x0B); iCardID++)
{
tagSearchCardResult SearchLineCardResult;
bool bFindLine = SearchLineCardType(cbHandCardData,cbHandCardCount,iCardID,3,cbTurnCardCount/3,&SearchLineCardResult);
if (bFindLine)
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, SearchLineCardResult.cbResultCard, cbTurnCardCount);
return true;
}
}
}
break;
case CT_FOUR_LINE:
{//概率太小,先不考慮
}
break;
default:
break;
}
return true;
}
//
//出牌搜索
bool CGameLogic::SearchOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, WORD wOutCardUser, WORD wMeChairID, tagSearchCardResult & m_OutCardResult)
{
//玩家判斷
WORD wUndersideOfBanker = (m_wBankerUser+1)%GAME_PLAYER ; //地主下家
WORD wUpsideOfBanker = (wUndersideOfBanker+1)%GAME_PLAYER ; //地主上家
//初始變量
ZeroMemory(&m_OutCardResult, sizeof(m_OutCardResult)) ;
//強制拐牌
OutBigCardsFirst(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,wMeChairID,m_OutCardResult);
if (m_OutCardResult.cbCardCount != 0) return true;
//先出牌
if(cbTurnCardCount==0)
{
//地主出牌
if(wMeChairID==m_wBankerUser) BankerOutCard(cbHandCardData, cbHandCardCount, m_OutCardResult) ;
//地主下家
else if(wMeChairID==wUndersideOfBanker) UndersideOfBankerOutCard(cbHandCardData, cbHandCardCount,wMeChairID, ?m_OutCardResult) ;
//地主上家
else if(wMeChairID==wUpsideOfBanker) UpsideOfBankerOutCard(cbHandCardData, cbHandCardCount, wMeChairID, m_OutCardResult) ;
//錯誤 ID
else ASSERT(false) ;
}
//壓牌
else
{
//地主出牌
if(wMeChairID==m_wBankerUser) BankerOutCard(cbHandCardData, cbHandCardCount, wOutCardUser, cbTurnCardData, cbTurnCardCount, m_OutCardResult) ;
//地主下家
else if(wMeChairID==wUndersideOfBanker) UndersideOfBankerOutCard(cbHandCardData, cbHandCardCount, wOutCardUser, cbTurnCardData, cbTurnCardCount, m_OutCardResult) ;
//地主上家
else if(wMeChairID==wUpsideOfBanker) UpsideOfBankerOutCard(cbHandCardData, cbHandCardCount, wOutCardUser, cbTurnCardData, cbTurnCardCount, m_OutCardResult) ;
//錯誤 ID
else ASSERT(false) ;
}
return true ;
}
//莊家出牌(已令牌)
VOID CGameLogic::BankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, tagSearchCardResult & m_OutCardResult)?
{
//考慮自己
OutCardAccordingToMyCards(cbHandCardData,cbHandCardCount,m_OutCardResult);
return ;
}
//莊家出牌(跟牌)
VOID CGameLogic::BankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wOutCardUser, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult)?
{
//牌的類型
BYTE userCardType = GetCardType(cbTurnCardData,cbTurnCardCount);
CardsDistribution myCardsDistribution;
AnalyseMyCards(cbHandCardData,cbHandCardCount,myCardsDistribution);
//我已能贏
if (ICanWin(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult)) return ;
switch (userCardType)
{
case CT_SINGLE:
{
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
break;
case CT_DOUBLE:
{
//盡量打死
if (myCardsDistribution.cbDoubleCardsCount > 0)//有對子
{
for (int i=0; i<myCardsDistribution.cbDoubleCardsCount; i++)
{
//尋找對子中打得過的
if (GetCardLogicValue(myCardsDistribution.cbDoubleCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbDoubleCards[i][0])==GetAllUserLargestCardLogicValue()&& cbHandCardCount>5 && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser]) == CT_ERROR))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbDoubleCards[i], 2);
return;
}
}
}
}
else//無對子
{
//用三牌拆
if (myCardsDistribution.cbThreeCardsCount > 0)//有三牌
{
for (int i=0; i<myCardsDistribution.cbThreeCardsCount; i++)
{
//尋找三牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbThreeCards[i], 2);
return;
}
}
}
//用四牌拆
if (myCardsDistribution.cbFourCardsCount > 0)//有四牌
{
for (int i=0; i<myCardsDistribution.cbFourCardsCount; i++)
{
//尋找四牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 2);
return;
}
}
}
//死活打死
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
//強制打死
if (GetCardType(m_cbAllCardData[wOutCardUser] ,m_cbUserCardCount[wOutCardUser]) != CT_ERROR)
{
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
break;
case CT_THREE:
{
//有三牌
if (myCardsDistribution.cbThreeCardsCount > 0)//有三牌
{
for (int i=0; i<myCardsDistribution.cbThreeCardsCount; i++)
{
//尋找三牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0])==GetAllUserLargestCardLogicValue()&& cbHandCardCount>6 && GetCardType(m_cbAllCardData[m_wBankerUser],m_cbUserCardCount[m_wBankerUser]) == CT_ERROR))
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbThreeCards[i], 3);
return;
}
}
}
}
//用四牌拆
if (myCardsDistribution.cbFourCardsCount > 0)//有四牌
{
for (int i=0; i<myCardsDistribution.cbFourCardsCount; i++)
{
//尋找三牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbFourCards[i][0])==GetAllUserLargestCardLogicValue()&& cbHandCardCount>7 && GetCardType(m_cbAllCardData[m_wBankerUser],m_cbUserCardCount[m_wBankerUser]) == CT_ERROR))
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 3);
return;
}
}
}
}
//強制打死
if (GetCardType(m_cbAllCardData[wOutCardUser] ,m_cbUserCardCount[wOutCardUser]) != CT_ERROR)
{
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
break;
case CT_BOMB_CARD:
{
//有四牌
if (myCardsDistribution.cbFourCardsCount > 0)
{
for (int i=myCardsDistribution.cbFourCardsCount-1; i>=0; i--)
{
//尋找三牌中打得過的
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbFourCards[i][0])==GetAllUserLargestCardLogicValue()&& cbHandCardCount>7 && GetCardType(m_cbAllCardData[m_wBankerUser],m_cbUserCardCount[m_wBankerUser]) == CT_ERROR))
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 4);
return;
}
}
}
}
//強制打死
if (GetCardType(m_cbAllCardData[wOutCardUser] ,m_cbUserCardCount[wOutCardUser]) != CT_ERROR)
{
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
break;
case CT_SINGLE_LINE:
{
//鏈子到頂
if (GetCardLogicValue(cbTurnCardData[0]) == GetCardLogicValue(0x0D)) return;
//遍歷所有鏈子
for (int i=0; i<7; i++)
{
//鏈子數目正好
if (myCardsDistribution.cbSingleLineCardsCount[i] == cbTurnCardCount)
{
//且能大過
if (GetCardLogicValue(cbTurnCardData[0]) < GetCardLogicValue(myCardsDistribution.cbSingleLineCards[i][cbTurnCardCount-1]))
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbSingleLineCards[i], cbTurnCardCount);
return;
}
}
}
//不行就拆
for (int i=0; i<7; i++)
{
//可以拆成兩聯鏈子
if (myCardsDistribution.cbSingleLineCardsCount[i] >= cbTurnCardCount + 3)
{
//且能大過
if (GetCardLogicValue(cbTurnCardData[0]) < GetCardLogicValue(myCardsDistribution.cbSingleLineCards[i][myCardsDistribution.cbSingleLineCardsCount[i]-1]))
{
//挑大的出
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[i][0] + myCardsDistribution.cbSingleLineCardsCount[i] - cbTurnCardCount, cbTurnCardCount);
return;
}
}
}
//不能拆成兩聯也得打死
for (int i=0; i<7; i++)
{
if (myCardsDistribution.cbSingleLineCardsCount[i] > cbTurnCardCount)
{
//且能大過
if (GetCardLogicValue(cbTurnCardData[0]) < GetCardLogicValue(myCardsDistribution.cbSingleLineCards[i][myCardsDistribution.cbSingleLineCardsCount[i]-1]))
{
//挑大的出
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[i][0] + myCardsDistribution.cbSingleLineCardsCount[i] - cbTurnCardCount, cbTurnCardCount);
return;
}
}
}
//強制打死
if (GetCardType(m_cbAllCardData[wOutCardUser] ,m_cbUserCardCount[wOutCardUser]) != CT_ERROR)
{
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
break;
case CT_DOUBLE_LINE:
{
//只要能打死肯定得打死
for (int iCardID=GetCardLogicValue(cbTurnCardData[0])+1; iCardID<=GetCardLogicValue(0x0B); iCardID++)
{
tagSearchCardResult SearchLineCardResult;
bool bFindLine = SearchLineCardType(cbHandCardData,cbHandCardCount,iCardID,2,cbTurnCardCount/2,&SearchLineCardResult);
if (bFindLine)
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, SearchLineCardResult.cbResultCard, cbTurnCardCount);
return ;
}
}
//強制打死
if (GetCardType(m_cbAllCardData[wOutCardUser] ,m_cbUserCardCount[wOutCardUser]) != CT_ERROR)
{
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
break;
case CT_THREE_LINE:
{
//只要能打死肯定得打死
for (int iCardID=GetCardLogicValue(cbTurnCardData[0])+1; iCardID<=GetCardLogicValue(0x0B); iCardID++)
{
tagSearchCardResult SearchLineCardResult;
bool bFindLine = SearchLineCardType(cbHandCardData,cbHandCardCount,iCardID,3,cbTurnCardCount/3,&SearchLineCardResult);
if (bFindLine)
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, SearchLineCardResult.cbResultCard, cbTurnCardCount);
return ;
}
}
//強制打死
if (GetCardType(m_cbAllCardData[wOutCardUser] ,m_cbUserCardCount[wOutCardUser]) != CT_ERROR)
{
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
case CT_FOUR_LINE:
{//暫不考慮
}
break;
}
}
//莊家上家(已令牌)
VOID CGameLogic::UpsideOfBankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wMeChairID, tagSearchCardResult & m_OutCardResult)
{
//分析自己能走的可能性
BYTE cbFriendChairID = (wMeChairID+2) % GAME_PLAYER;
bool cbThinkMyself = false;
if (EvaluateUserCards(cbHandCardData,cbHandCardCount) > EvaluateUserCards(m_cbAllCardData[cbFriendChairID],m_cbUserCardCount[cbFriendChairID])+1)
{
cbThinkMyself = true;
}
CardsDistribution myCardsDistribution;
AnalyseMyCards(cbHandCardData,cbHandCardCount,myCardsDistribution);
//我已能贏
if (ICanWin(cbHandCardData,cbHandCardCount,NULL,0,m_OutCardResult)) return ;
if (cbThinkMyself)//考慮自己
{
OutCardAccordingToMyCards(cbHandCardData,cbHandCardCount,m_OutCardResult);
if (IsBankerOnlyHaveOneCard() && m_OutCardResult.cbCardCount==1)
{
//出對子牌
if (myCardsDistribution.cbDoubleCardsCount >= 1)
{
if (
//一個小對子
(myCardsDistribution.cbDoubleCardsCount==1 && GetCardLogicValue(myCardsDistribution.cbDoubleCards[0][0])<GetCardLogicValue(0x0A))
//三對以上
||(myCardsDistribution.cbDoubleCardsCount>=3)
//手中的牌已經不多了
||(myCardsDistribution.cbDoubleCardsCount>=1 && cbHandCardCount<5)
)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleCards[0], 2);
return ;
}
}
//出單順牌
if (myCardsDistribution.cbSingleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbSingleLineCardsCount[0];
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[0], myCardsDistribution.cbSingleLineCardsCount[0]);
return ;
}
//出三張牌
if (myCardsDistribution.cbThreeCardsCount >= 1)
{
//防止白扔大牌
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[0][0]) < GetAllUserLargestCardLogicValue()-1)
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbThreeCards[0], 3);
return ;
}
}
//出四張牌
if (myCardsDistribution.cbFourCardsCount >= 1)
{
//防止白扔大牌
if (GetCardLogicValue(myCardsDistribution.cbFourCards[0][0]) < GetAllUserLargestCardLogicValue()-1)
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbFourCards[0], 3);
return ;
}
}
//出雙順
if (myCardsDistribution.cbDoubleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbDoubleLineCardsCount[0] * 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleLineCards[0], myCardsDistribution.cbDoubleLineCardsCount[0]*2);
return ;
}
}
return;
}
else//給隊友送牌
{
//分析隊友的牌
CardsDistribution friendCardsDistribution;
AnalyseMyCards(m_cbAllCardData[cbFriendChairID],m_cbUserCardCount[cbFriendChairID],friendCardsDistribution);
//分析我自己的牌
CardsDistribution myCardsDistribution;
AnalyseMyCards(m_cbAllCardData[wMeChairID],m_cbUserCardCount[wMeChairID],myCardsDistribution);
//能跑就跑---出雙順
if (myCardsDistribution.cbDoubleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbDoubleLineCardsCount[0] * 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleLineCards[0], myCardsDistribution.cbDoubleLineCardsCount[0]*2);
return ;
}
//能跑就跑---出單順牌
if (myCardsDistribution.cbSingleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbSingleLineCardsCount[0];
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[0], myCardsDistribution.cbSingleLineCardsCount[0]);
return ;
}
//試著送隊友
if (friendCardsDistribution.cbSingleLineCardsCount[0] > 0)//隊友要鏈子
{
for (int i=0; i<7; i++)
{
if (friendCardsDistribution.cbSingleLineCardsCount[i] == 0) break;
int iLineCardsLength = friendCardsDistribution.cbSingleLineCardsCount[i];
//媽的,拆機器買零件的送
for (BYTE cbCardID=GetCardLogicValue(GetLestCard(cbHandCardData,cbHandCardCount)); cbCardID<GetCardLogicValue(friendCardsDistribution.cbSingleLineCards[i][0]); cbCardID++)
{
tagSearchCardResult SearchLineCardResult;
bool bFindIt = SearchLineCardType(cbHandCardData,cbHandCardCount,cbCardID,1,iLineCardsLength,&SearchLineCardResult);
if (bFindIt)
{
m_OutCardResult.cbCardCount = iLineCardsLength;
CopyMemory(m_OutCardResult.cbResultCard, SearchLineCardResult.cbResultCard, iLineCardsLength);
return ;
}
}
}
}
if(friendCardsDistribution.cbDoubleCardsCount > 0)//隊友要對子
{
//能送小雙
BYTE cbMyLestDoubleCards[2] = {0};
if (GetLestDoubleCards(cbHandCardData,cbHandCardCount,cbMyLestDoubleCards))
{
if (GetCardLogicValue(cbMyLestDoubleCards[0]) < GetCardLogicValue(friendCardsDistribution.cbDoubleCards[0][0]))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, cbMyLestDoubleCards, 2);
return ;
}
}
}
//出一張大牌死頂
for (int i=cbHandCardCount-1; i>=0; i--)
{
if (GetCardLogicValue(cbHandCardData[i]) < GetCardLogicValue(m_cbAllCardData[cbFriendChairID][0]))
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &cbHandCardData[i], 1);
return ;
}
}
}
}
//莊家上家(跟牌)
VOID CGameLogic::UpsideOfBankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wOutCardUser, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult)?
{
//出牌類型
BYTE cbOutCardType = GetCardType(cbTurnCardData, cbTurnCardCount);
//分析自己能走的可能性
BYTE cbFriendChairID = (m_wBankerUser+1) % GAME_PLAYER;
BYTE cbMeChairID = (m_wBankerUser+2) % GAME_PLAYER;
bool cbThinkMyself = false;
if (EvaluateUserCards(cbHandCardData,cbHandCardCount) > EvaluateUserCards(m_cbAllCardData[cbFriendChairID],m_cbUserCardCount[cbFriendChairID])+1)
{
cbThinkMyself = true;
}
//分析隊友的牌
CardsDistribution friendCardsDistribution;
AnalyseMyCards(m_cbAllCardData[cbFriendChairID],m_cbUserCardCount[cbFriendChairID],friendCardsDistribution);
//分析自己的牌
CardsDistribution myCardsDistribution;
AnalyseMyCards(m_cbAllCardData[cbMeChairID],m_cbUserCardCount[cbMeChairID],myCardsDistribution);
//我已能贏
if (ICanWin(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult)) return ;
switch (cbOutCardType)
{
case CT_SINGLE:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
if (cbThinkMyself)//考慮自己
{
//隊友沒出,強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
if (IsBankerOnlyHaveOneCard())
{
m_OutCardResult.cbCardCount = 1;
m_OutCardResult.cbResultCard[0] = cbHandCardData[0];
}
return ;
}
else//考慮隊友
{
//隊友沒出,強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
if (IsBankerOnlyHaveOneCard())
{
m_OutCardResult.cbCardCount = 1;
m_OutCardResult.cbResultCard[0] = cbHandCardData[0];
}
return ;
}
}
else//出牌人是隊友
{
//莊家只剩一張牌了
if (IsBankerOnlyHaveOneCard())
{
m_OutCardResult.cbCardCount = 1;
m_OutCardResult.cbResultCard[0] = cbHandCardData[0];
return ;
}
if (cbThinkMyself)//考慮自己
{
if (myCardsDistribution.cbSingleCardsCount > 0)//沒有單牌就不接了
{
for (int i=myCardsDistribution.cbSingleCardsCount-1; i>=0; i--)
{
//尋找單排中打得過的
if (GetCardLogicValue(myCardsDistribution.cbSingleCards[i]) > GetCardLogicValue(cbTurnCardData[0]) && GetCardLogicValue(myCardsDistribution.cbSingleCards[i])!=GetAllUserLargestCardLogicValue())
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleCards[i], 1);
return ;
}
}
}
else
{
return ;
}
}
else//考慮隊友
{
if (GetCardLogicValue(cbTurnCardData[0]) > GetAllUserLargestCardLogicValue() -4)//牌已經夠大了
{//不做處理
}
else //牌太小了,頂一下
{
for (int i=myCardsDistribution.cbSingleCardsCount-1; i>=0; i--)
{
//尋找單排中打得過的
if (GetCardLogicValue(myCardsDistribution.cbSingleCards[i]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (GetCardLogicValue(myCardsDistribution.cbSingleCards[i]) > GetAllUserLargestCardLogicValue()-4)
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleCards[i], 1);
return ;
}
}
}
for (BYTE cbCardId=GetAllUserLargestCardLogicValue()-3; cbCardId>=4; cbCardId--)
{
for (int i=0; i<cbHandCardCount; i++)
{
if (GetCardLogicValue(cbHandCardData[i]) == cbCardId)
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &cbHandCardData[i], 1);
return ;
}
}
}
}
}
}
}
break;
case CT_DOUBLE:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
if (cbThinkMyself)//考慮自己
{
//隊友沒出,強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
else//考慮隊友
{
//隊友沒出,強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
else//出牌人是隊友
{
if (cbThinkMyself)//考慮自己
{
if (myCardsDistribution.cbDoubleCardsCount > 0)//沒有雙牌就不接了
{
for (int i=0; i<myCardsDistribution.cbDoubleCardsCount; i++)
{
//尋找對子中打得過的
if (GetCardLogicValue(myCardsDistribution.cbDoubleCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (GetCardLogicValue(myCardsDistribution.cbDoubleCards[i][0]) < GetAllUserLargestCardLogicValue() -2)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleCards[i], 2);
return ;
}
else
{
return ;
}
}
}
}
else
{
return ;
}
}
else//考慮隊友
{
if (GetCardLogicValue(cbTurnCardData[0]) >GetAllUserLargestCardLogicValue() -5)//牌已經夠大了
{//不做處理
}
else //牌太小了,頂一下
{
CardsDistribution cbSeachDoubleCards;
AnalyseDoubleCardsOnly(cbHandCardData,cbHandCardCount,cbSeachDoubleCards);
for (BYTE cbCardId=GetAllUserLargestCardLogicValue()-3; cbCardId>=4; cbCardId--)
{
for (int i=0; i<cbSeachDoubleCards.cbDoubleCardsCount; i++)
{
if (GetCardLogicValue(cbSeachDoubleCards.cbDoubleCards[i][0]) == GetCardLogicValue(cbCardId))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, &cbSeachDoubleCards.cbDoubleCards[i], 2);
return ;
}
}
}
}
}
}
}
break;
case CT_THREE:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
if (cbThinkMyself)//考慮自己
{
if (myCardsDistribution.cbThreeCardsCount > 0)//有就打死
{
for (int i=0; i<myCardsDistribution.cbThreeCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0])==GetCardLogicValue(0x03) && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser])==CT_ERROR))
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbThreeCards[i], 3);
return ;
}
}
}
}
else//沒有也不會拆牌
{
return ;
}
}
else//考慮隊友
{
//強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
if (!(GetCardLogicValue(m_OutCardResult.cbResultCard[0])==GetCardLogicValue(0x03) && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser])==CT_ERROR))
{
return ;
}
}
}
else//出牌人是隊友
{
if (cbThinkMyself)
{
if (GetCardLogicValue(cbTurnCardData[0]) < GetAllUserLargestCardLogicValue() - 5)//出牌較小
{
if (myCardsDistribution.cbThreeCardsCount > 0)//有就打死
{
for (int i=0; i<myCardsDistribution.cbThreeCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbThreeCards[i], 3);
return ;
}
}
}
else//沒有也不會拆牌
{
return ;
}
}
else
{
//不管不問
return ;
}
}
else
{
//不管不問
return ;
}
return ;
}
}
break;
case CT_BOMB_CARD:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
if (cbThinkMyself)//考慮自己
{
if (myCardsDistribution.cbFourCardsCount > 0)//有就打死
{
for (int i=0; i<myCardsDistribution.cbFourCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbFourCards[i][0])==GetCardLogicValue(0x03) && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser])==CT_ERROR))
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 4);
return ;
}
}
}
}
else//沒有也不會拆牌
{
return ;
}
}
else//考慮隊友
{
//強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
if (!(GetCardLogicValue(m_OutCardResult.cbResultCard[0])==GetCardLogicValue(0x03) && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser])==CT_ERROR))
{
return ;
}
}
}
else//出牌人是隊友
{
if (cbThinkMyself)
{
if (GetCardLogicValue(cbTurnCardData[0]) < GetAllUserLargestCardLogicValue() - 5)//出牌較小
{
if (myCardsDistribution.cbFourCardsCount > 0)//有就打死
{
for (int i=0; i<myCardsDistribution.cbFourCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 4);
return ;
}
}
}
else//沒有也不會拆牌
{
return ;
}
}
else
{
//不管不問
return ;
}
}
else
{
//不管不問
return ;
}
return ;
}
}
break;
case CT_SINGLE_LINE:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
//強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
else
{
if (cbThinkMyself)
{
//遍歷所有鏈子
for (int i=0; i<7; i++)
{
//鏈子數目正好
if (myCardsDistribution.cbSingleLineCardsCount[i] == cbTurnCardCount)
{
//且能大過
if (GetCardLogicValue(cbTurnCardData[0]) < GetCardLogicValue(myCardsDistribution.cbSingleLineCards[i][cbTurnCardCount-1]))
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbSingleLineCards[i], cbTurnCardCount);
return;
}
}
}
}
else
{
//不管不問
return ;
}
}
}
break;
default:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
//強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
else
{
return ;
}
}
break;
}
}
//莊家下家(已令牌)
VOID CGameLogic::UndersideOfBankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wMeChairID,tagSearchCardResult & m_OutCardResult)?
{
BYTE cbFriendChairID = (wMeChairID+1) % GAME_PLAYER;
bool cbThinkMyself = false;
//分析隊友的牌
CardsDistribution friendCardsDistribution;
AnalyseMyCards(m_cbAllCardData[cbFriendChairID],m_cbUserCardCount[cbFriendChairID],friendCardsDistribution);
//分析我自己的牌
CardsDistribution myCardsDistribution;
AnalyseMyCards(m_cbAllCardData[wMeChairID],m_cbUserCardCount[wMeChairID],myCardsDistribution);
//我已能贏
if (ICanWin(cbHandCardData,cbHandCardCount,NULL,0,m_OutCardResult)) return ;
//分析自己能走的可能性
if (EvaluateUserCards(cbHandCardData,cbHandCardCount) > EvaluateUserCards(m_cbAllCardData[cbFriendChairID],m_cbUserCardCount[cbFriendChairID])+1)
{
cbThinkMyself = true;
}
//下家剩一張
if (m_cbUserCardCount[cbFriendChairID] == 1)
{
if (GetCardLogicValue(cbHandCardData[cbHandCardCount-1]) < GetCardLogicValue(m_cbAllCardData[cbFriendChairID][0]))
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &cbHandCardData[cbHandCardCount-1], 1);
return;
}
}
if (cbThinkMyself)//考慮自己
{
OutCardAccordingToMyCards(cbHandCardData,cbHandCardCount,m_OutCardResult);
if (IsBankerOnlyHaveOneCard() && m_OutCardResult.cbCardCount==1)
{
//出對子牌
if (myCardsDistribution.cbDoubleCardsCount >= 1)
{
if (
//一個小對子
(myCardsDistribution.cbDoubleCardsCount==1 && GetCardLogicValue(myCardsDistribution.cbDoubleCards[0][0])<GetCardLogicValue(0x0A))
//三對以上
||(myCardsDistribution.cbDoubleCardsCount>=3)
//手中的牌已經不多了
||(myCardsDistribution.cbDoubleCardsCount>=1 && cbHandCardCount<5)
)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleCards[0], 2);
return ;
}
}
//出單順牌
if (myCardsDistribution.cbSingleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbSingleLineCardsCount[0];
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[0], myCardsDistribution.cbSingleLineCardsCount[0]);
return ;
}
//出三張牌
if (myCardsDistribution.cbThreeCardsCount >= 1)
{
//防止白扔大牌
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[0][0]) < GetAllUserLargestCardLogicValue()-1)
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbThreeCards[0], 3);
return ;
}
}
//出四張牌
if (myCardsDistribution.cbFourCardsCount >= 1)
{
//防止白扔大牌
if (GetCardLogicValue(myCardsDistribution.cbFourCards[0][0]) < GetAllUserLargestCardLogicValue()-1)
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbFourCards[0], 3);
return ;
}
}
//出雙順
if (myCardsDistribution.cbDoubleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbDoubleLineCardsCount[0] * 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleLineCards[0], myCardsDistribution.cbDoubleLineCardsCount[0]*2);
return ;
}
}
return;
}
else//給隊友送牌
{
if (m_cbUserCardCount[cbFriendChairID] == 1)//隊友要單
{
if (myCardsDistribution.cbSingleCardsCount > 0)//自己有單牌
{
//能送走
if (GetCardLogicValue(myCardsDistribution.cbSingleCards[0]) < GetCardLogicValue(friendCardsDistribution.cbSingleCards[friendCardsDistribution.cbSingleCardsCount-1]))
{
m_OutCardResult.cbCardCount = 1;
m_OutCardResult.cbResultCard[0] = myCardsDistribution.cbSingleCards[0];
return ;
}
else
{
//不好送就自己出
OutCardAccordingToMyCards(cbHandCardData,cbHandCardCount,m_OutCardResult);
return ;
}
}
}
else if (m_cbUserCardCount[cbFriendChairID] == 2 && friendCardsDistribution.cbDoubleCardsCount == 1)//隊友要雙
{
if (myCardsDistribution.cbDoubleCardsCount > 0)//自己有對子
{
//能送走
if (GetCardLogicValue(myCardsDistribution.cbDoubleCards[0][0]) < GetCardLogicValue(friendCardsDistribution.cbDoubleCards[friendCardsDistribution.cbDoubleCardsCount-1][0]))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard,myCardsDistribution.cbDoubleCards,2);
return ;
}
else
{
//不好送就自己出
OutCardAccordingToMyCards(cbHandCardData,cbHandCardCount,m_OutCardResult);
return ;
}
}
}
//不好送就自己出
OutCardAccordingToMyCards(cbHandCardData,cbHandCardCount,m_OutCardResult);
if (IsBankerOnlyHaveOneCard() && m_OutCardResult.cbCardCount==1)
{
//出對子牌
if (myCardsDistribution.cbDoubleCardsCount >= 1)
{
if (
//一個小對子
(myCardsDistribution.cbDoubleCardsCount==1 && GetCardLogicValue(myCardsDistribution.cbDoubleCards[0][0])<GetCardLogicValue(0x0A))
//三對以上
||(myCardsDistribution.cbDoubleCardsCount>=3)
//手中的牌已經不多了
||(myCardsDistribution.cbDoubleCardsCount>=1 && cbHandCardCount<5)
)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleCards[0], 2);
return ;
}
}
//出單順牌
if (myCardsDistribution.cbSingleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbSingleLineCardsCount[0];
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleLineCards[0], myCardsDistribution.cbSingleLineCardsCount[0]);
return ;
}
//出三張牌
if (myCardsDistribution.cbThreeCardsCount >= 1)
{
//防止白扔大牌
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[0][0]) < GetAllUserLargestCardLogicValue()-1)
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbThreeCards[0], 3);
return ;
}
}
//出四張牌
if (myCardsDistribution.cbFourCardsCount >= 1)
{
//防止白扔大牌
if (GetCardLogicValue(myCardsDistribution.cbFourCards[0][0]) < GetAllUserLargestCardLogicValue()-1)
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbFourCards[0], 3);
return ;
}
}
//出雙順
if (myCardsDistribution.cbDoubleLineCardsCount[0] != 0)
{
m_OutCardResult.cbCardCount = myCardsDistribution.cbDoubleLineCardsCount[0] * 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleLineCards[0], myCardsDistribution.cbDoubleLineCardsCount[0]*2);
return ;
}
}
return ;
}
}
//莊家下家(跟牌)
VOID CGameLogic::UndersideOfBankerOutCard(const BYTE cbHandCardData[], BYTE cbHandCardCount, WORD wOutCardUser, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult)
{
//出牌類型
BYTE cbOutCardType = GetCardType(cbTurnCardData, cbTurnCardCount);
//分析自己能走的可能性
BYTE cbFriendChairID = (m_wBankerUser+2) % GAME_PLAYER;
BYTE cbMeChairID = (m_wBankerUser+1) % GAME_PLAYER;
bool cbThinkMyself = false;
if (EvaluateUserCards(cbHandCardData,cbHandCardCount) > EvaluateUserCards(m_cbAllCardData[cbFriendChairID],m_cbUserCardCount[cbFriendChairID])+1)
{
cbThinkMyself = true;
}
//分析隊友的牌
CardsDistribution friendCardsDistribution;
AnalyseMyCards(m_cbAllCardData[cbFriendChairID],m_cbUserCardCount[cbFriendChairID],friendCardsDistribution);
//分析自己的牌
CardsDistribution myCardsDistribution;
AnalyseMyCards(m_cbAllCardData[cbMeChairID],m_cbUserCardCount[cbMeChairID],myCardsDistribution);
//我已能贏
if (ICanWin(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult)) return ;
switch (cbOutCardType)
{
case CT_SINGLE:
{
//下家剩一張
if (m_cbUserCardCount[cbFriendChairID] == 1 && wOutCardUser!=cbFriendChairID)
{
if (GetCardLogicValue(cbHandCardData[0]) == GetAllUserLargestCardLogicValue())
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &cbHandCardData[cbHandCardCount-1], 1);
return;
}
}
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
if (cbThinkMyself)//考慮自己
{
//隊友沒出,強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
else//考慮隊友
{
//隊友沒出,強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
else//出牌人是隊友
{
if (cbThinkMyself)//考慮自己
{
if (myCardsDistribution.cbSingleCardsCount > 0)//沒有單牌就不接了
{
for (int i=myCardsDistribution.cbSingleCardsCount-1; i>=0; i--)
{
//尋找單排中打得過的
if (GetCardLogicValue(myCardsDistribution.cbSingleCards[i]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbSingleCards[i], 1);
return ;
}
}
}
else
{
return ;
}
}
else//考慮隊友
{
if (GetCardLogicValue(cbTurnCardData[0]) > GetAllUserLargestCardLogicValue() -4)//牌已經夠大了
{//不做處理
}
else //牌太小了,頂一下
{
for (BYTE cbCardId=GetAllUserLargestCardLogicValue()-3; cbCardId>=4; cbCardId--)
{
for (int i=0; i<cbHandCardCount; i++)
{
if (GetCardLogicValue(cbHandCardData[i]) == cbCardId)
{
m_OutCardResult.cbCardCount = 1;
CopyMemory(m_OutCardResult.cbResultCard, &cbHandCardData[i], 1);
return ;
}
}
}
}
}
}
}
break;
case CT_DOUBLE:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
if (cbThinkMyself)//考慮自己
{
//隊友沒出,強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
else//考慮隊友
{
//隊友沒出,強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
}
else//出牌人是隊友
{
if (cbThinkMyself)//考慮自己
{
if (myCardsDistribution.cbDoubleCardsCount > 0)//沒有對子就不接了
{
for (int i=0; i<myCardsDistribution.cbDoubleCardsCount; i++)
{
//尋找對子中打得過的
if (GetCardLogicValue(myCardsDistribution.cbDoubleCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (GetCardLogicValue(myCardsDistribution.cbDoubleCards[i][0]) < GetAllUserLargestCardLogicValue() -2)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, &myCardsDistribution.cbDoubleCards[i], 2);
return ;
}
else
{
return ;
}
}
}
}
else
{
return ;
}
}
else//考慮隊友
{
if (GetCardLogicValue(cbTurnCardData[0]) > GetAllUserLargestCardLogicValue() -5)//牌已經夠大了
{//不做處理
}
else //牌太小了,頂一下
{
CardsDistribution cbSeachDoubleCards;
AnalyseDoubleCardsOnly(cbHandCardData,cbHandCardCount,cbSeachDoubleCards);
for (BYTE cbCardId=GetAllUserLargestCardLogicValue()-3; cbCardId>=4; cbCardId--)
{
for (int i=0; i<cbSeachDoubleCards.cbDoubleCardsCount; i++)
{
if (GetCardLogicValue(cbSeachDoubleCards.cbDoubleCards[i][0]) == GetCardLogicValue(cbCardId))
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbDoubleCards[i], 2);
return ;
}
}
}
}
}
}
}
break;
case CT_THREE:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
if (cbThinkMyself)//考慮自己
{
if (myCardsDistribution.cbThreeCardsCount > 0)//有就打死
{
for (int i=0; i<myCardsDistribution.cbThreeCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0])==GetCardLogicValue(0x03) && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser])==CT_ERROR))
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbThreeCards[i], 3);
return ;
}
}
}
}
else//沒有也不會拆牌
{
return ;
}
}
else//考慮隊友
{
//強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
if (!(GetCardLogicValue(m_OutCardResult.cbResultCard[0])==GetCardLogicValue(0x03) && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser])==CT_ERROR))
{
return ;
}
}
}
else//出牌人是隊友
{
if (cbThinkMyself)
{
if (GetCardLogicValue(cbTurnCardData[0]) < GetAllUserLargestCardLogicValue() - 5)//出牌較小
{
if (myCardsDistribution.cbThreeCardsCount > 0)//有就打死
{
for (int i=0; i<myCardsDistribution.cbThreeCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbThreeCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbThreeCards[i], 3);
return ;
}
}
}
else//沒有也不會拆牌
{
return ;
}
}
else
{
//不管不問
return ;
}
}
else
{
//不管不問
return ;
}
return ;
}
}
break;
case CT_BOMB_CARD:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
if (cbThinkMyself)//考慮自己
{
if (myCardsDistribution.cbFourCardsCount > 0)//有就打死
{
for (int i=0; i<myCardsDistribution.cbFourCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
if (!(GetCardLogicValue(myCardsDistribution.cbFourCards[i][0])==GetCardLogicValue(0x03) && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser])==CT_ERROR))
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 4);
return ;
}
}
}
}
else//沒有也不會拆牌
{
return ;
}
}
else//考慮隊友
{
//強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
if (!(GetCardLogicValue(m_OutCardResult.cbResultCard[0])==GetCardLogicValue(0x03) && GetCardType(m_cbAllCardData[wOutCardUser],m_cbUserCardCount[wOutCardUser])==CT_ERROR))
{
return ;
}
}
}
else//出牌人是隊友
{
if (cbThinkMyself)
{
if (GetCardLogicValue(cbTurnCardData[0]) < GetAllUserLargestCardLogicValue() - 5)//出牌較小
{
if (myCardsDistribution.cbFourCardsCount > 0)//有就打死
{
for (int i=0; i<myCardsDistribution.cbFourCardsCount; i++)
{
if (GetCardLogicValue(myCardsDistribution.cbFourCards[i][0]) > GetCardLogicValue(cbTurnCardData[0]))
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbFourCards[i], 4);
return ;
}
}
}
else//沒有也不會拆牌
{
return ;
}
}
else
{
//不管不問
return ;
}
}
else
{
//不管不問
return ;
}
return ;
}
}
break;
case CT_SINGLE_LINE:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
//強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
else
{
if (cbThinkMyself)
{
//遍歷所有鏈子
for (int i=0; i<7; i++)
{
//鏈子數目正好
if (myCardsDistribution.cbSingleLineCardsCount[i] == cbTurnCardCount)
{
//且能大過
if (GetCardLogicValue(cbTurnCardData[0]) < GetCardLogicValue(myCardsDistribution.cbSingleLineCards[i][cbTurnCardCount-1]))
{
m_OutCardResult.cbCardCount = cbTurnCardCount;
CopyMemory(m_OutCardResult.cbResultCard, myCardsDistribution.cbSingleLineCards[i], cbTurnCardCount);
return;
}
}
}
}
else
{
//不管不問
return ;
}
}
}
break;
default:
{
if (wOutCardUser == m_wBankerUser)//出牌人是莊家
{
//強制打死莊家
OutCardForced(cbHandCardData,cbHandCardCount,cbTurnCardData,cbTurnCardCount,m_OutCardResult);
return ;
}
else
{
return ;
}
}
break;
}
}
//強制拐牌
void CGameLogic::OutBigCardsFirst(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, BYTE cbMeChairID, tagSearchCardResult & m_OutCardResult)
{
//一手出完
if (GetCardType(cbHandCardData,cbHandCardCount)!=CT_ERROR && cbTurnCardCount==0)
{
m_OutCardResult.cbCardCount = cbHandCardCount;
CopyMemory(m_OutCardResult.cbResultCard, cbHandCardData, cbHandCardCount);
return ;
}
//對方封頂
if (GetCardLogicValue(cbTurnCardData[0]) == GetAllUserLargestCardLogicValue()) return;
if (cbTurnCardCount == 0)//已經令牌
{
//單牌+一手牌
if (GetCardLogicValue(cbHandCardData[0]) == GetAllUserLargestCardLogicValue())
{
BYTE cbTmpMyCardData[20] = {0};
CopyMemory(cbTmpMyCardData,cbHandCardData,cbHandCardCount);
RemoveCard(cbTmpMyCardData,1,cbTmpMyCardData,cbHandCardCount);
//剩下的一手出完
if (GetCardType(cbTmpMyCardData,cbHandCardCount-1) != CT_ERROR)
{
m_OutCardResult.cbCardCount = 1;
m_OutCardResult.cbResultCard[0] = cbHandCardData[0];
return;
}
}
//對子+一手牌
CardsDistribution cbMyCardsDistribution2;
ZeroMemory(&cbMyCardsDistribution2,sizeof(CardsDistribution));
AnalyseDoubleCardsOnly(cbHandCardData,cbHandCardCount,cbMyCardsDistribution2);
if (cbMyCardsDistribution2.cbDoubleCardsCount > 0)
{
BYTE cbTmpMyCardData[20] = {0};
CopyMemory(cbTmpMyCardData,cbHandCardData,cbHandCardCount);
RemoveCard(cbMyCardsDistribution2.cbDoubleCards[cbMyCardsDistribution2.cbDoubleCardsCount-1],2,cbTmpMyCardData,cbHandCardCount);
//剩下的一手出完
if (GetCardType(cbTmpMyCardData,cbHandCardCount-2) != CT_ERROR)
{
//我的對子最大
bool bMyDoubleCardsIsBigest = true;
CardsDistribution cbOtherUser1AllDoubleCards;
ZeroMemory(&cbOtherUser1AllDoubleCards,sizeof(CardsDistribution));
AnalyseDoubleCardsOnly(m_cbAllCardData[(cbMeChairID+1)%GAME_PLAYER],m_cbUserCardCount[(cbMeChairID+1)%GAME_PLAYER],cbOtherUser1AllDoubleCards);
if (GetCardLogicValue(cbMyCardsDistribution2.cbDoubleCards[cbMyCardsDistribution2.cbDoubleCardsCount-1][0]) < GetCardLogicValue(cbOtherUser1AllDoubleCards.cbDoubleCards[cbOtherUser1AllDoubleCards.cbDoubleCardsCount-1][0]))
{
bMyDoubleCardsIsBigest = false;
}
CardsDistribution cbOtherUser2AllDoubleCards;
ZeroMemory(&cbOtherUser2AllDoubleCards,sizeof(CardsDistribution));
AnalyseDoubleCardsOnly(m_cbAllCardData[(cbMeChairID+2)%GAME_PLAYER],m_cbUserCardCount[(cbMeChairID+2)%GAME_PLAYER],cbOtherUser2AllDoubleCards);
if (GetCardLogicValue(cbMyCardsDistribution2.cbDoubleCards[cbMyCardsDistribution2.cbDoubleCardsCount-1][0]) < GetCardLogicValue(cbOtherUser2AllDoubleCards.cbDoubleCards[cbOtherUser2AllDoubleCards.cbDoubleCardsCount-1][0]))
{
bMyDoubleCardsIsBigest = false;
}
//且我這個對子是最大的對子
if (bMyDoubleCardsIsBigest)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, cbMyCardsDistribution2.cbDoubleCards[cbMyCardsDistribution2.cbDoubleCardsCount-1], 2);
return;
}
}
}
//三張+一手牌
CardsDistribution cbMyCardsDistribution3;
ZeroMemory(&cbMyCardsDistribution3,sizeof(CardsDistribution));
AnalyseThreeCardsOnly(cbHandCardData,cbHandCardCount,cbMyCardsDistribution3);
if (cbMyCardsDistribution3.cbThreeCardsCount > 0)
{
BYTE cbTmpMyCardData[20] = {0};
CopyMemory(cbTmpMyCardData,cbHandCardData,cbHandCardCount);
RemoveCard(cbMyCardsDistribution3.cbThreeCards[cbMyCardsDistribution3.cbThreeCardsCount-1],3,cbTmpMyCardData,cbHandCardCount);
//剩下的一手出完
if (GetCardType(cbTmpMyCardData,cbHandCardCount-3) != CT_ERROR)
{
//我的三牌最大
bool bMyThreeCardsIsBigest = true;
CardsDistribution cbOtherUser1AllThreeCards;
ZeroMemory(&cbOtherUser1AllThreeCards,sizeof(CardsDistribution));
AnalyseThreeCardsOnly(m_cbAllCardData[(cbMeChairID+1)%GAME_PLAYER],m_cbUserCardCount[(cbMeChairID+1)%GAME_PLAYER],cbOtherUser1AllThreeCards);
if (GetCardLogicValue(cbMyCardsDistribution3.cbThreeCards[cbMyCardsDistribution3.cbThreeCardsCount-1][0]) < GetCardLogicValue(cbOtherUser1AllThreeCards.cbThreeCards[cbOtherUser1AllThreeCards.cbThreeCardsCount-1][0]))
{
bMyThreeCardsIsBigest = false;
}
CardsDistribution cbOtherUser2AllThreeCards;
ZeroMemory(&cbOtherUser2AllThreeCards,sizeof(CardsDistribution));
AnalyseThreeCardsOnly(m_cbAllCardData[(cbMeChairID+2)%GAME_PLAYER],m_cbUserCardCount[(cbMeChairID+2)%GAME_PLAYER],cbOtherUser2AllThreeCards);
if (GetCardLogicValue(cbMyCardsDistribution3.cbThreeCards[cbMyCardsDistribution3.cbThreeCardsCount-1][0]) < GetCardLogicValue(cbOtherUser2AllThreeCards.cbThreeCards[cbOtherUser2AllThreeCards.cbThreeCardsCount-1][0]))
{
bMyThreeCardsIsBigest = false;
}
//且我這個三牌是最大的三牌
if (bMyThreeCardsIsBigest)
{
m_OutCardResult.cbCardCount = 3;
CopyMemory(m_OutCardResult.cbResultCard, cbMyCardsDistribution3.cbThreeCards[cbMyCardsDistribution3.cbThreeCardsCount-1], 3);
return;
}
}
}
//四牌+一手牌
CardsDistribution cbMyCardsDistribution4;
ZeroMemory(&cbMyCardsDistribution4,sizeof(CardsDistribution));
AnalyseFourCardsOnly(cbHandCardData,cbHandCardCount,cbMyCardsDistribution4);
if (cbMyCardsDistribution4.cbFourCardsCount > 0)
{
BYTE cbTmpMyCardData[20] = {0};
CopyMemory(cbTmpMyCardData,cbHandCardData,cbHandCardCount);
RemoveCard(cbMyCardsDistribution4.cbFourCards[cbMyCardsDistribution4.cbFourCardsCount-1],4,cbTmpMyCardData,cbHandCardCount);
//剩下的一手出完
if (GetCardType(cbTmpMyCardData,cbHandCardCount-4) != CT_ERROR)
{
//我的三牌最大
bool bMyFourCardsIsBigest = true;
CardsDistribution cbOtherUser1AllFourCards;
ZeroMemory(&cbOtherUser1AllFourCards,sizeof(CardsDistribution));
AnalyseFourCardsOnly(m_cbAllCardData[(cbMeChairID+1)%GAME_PLAYER],m_cbUserCardCount[(cbMeChairID+1)%GAME_PLAYER],cbOtherUser1AllFourCards);
if (GetCardLogicValue(cbMyCardsDistribution4.cbFourCards[cbMyCardsDistribution4.cbFourCardsCount-1][0]) < GetCardLogicValue(cbOtherUser1AllFourCards.cbFourCards[cbOtherUser1AllFourCards.cbFourCardsCount-1][0]))
{
bMyFourCardsIsBigest = false;
}
CardsDistribution cbOtherUser2AllFourCards;
ZeroMemory(&cbOtherUser2AllFourCards,sizeof(CardsDistribution));
AnalyseFourCardsOnly(m_cbAllCardData[(cbMeChairID+2)%GAME_PLAYER],m_cbUserCardCount[(cbMeChairID+2)%GAME_PLAYER],cbOtherUser2AllFourCards);
if (GetCardLogicValue(cbMyCardsDistribution4.cbFourCards[cbMyCardsDistribution4.cbFourCardsCount-1][0]) < GetCardLogicValue(cbOtherUser2AllFourCards.cbFourCards[cbOtherUser2AllFourCards.cbFourCardsCount-1][0]))
{
bMyFourCardsIsBigest = false;
}
//且我這個四牌是最大的四牌
if (bMyFourCardsIsBigest)
{
m_OutCardResult.cbCardCount = 4;
CopyMemory(m_OutCardResult.cbResultCard, cbMyCardsDistribution4.cbFourCards[cbMyCardsDistribution4.cbFourCardsCount-1], 4);
return;
}
}
}
//單順+一手牌
CardsDistribution cbMyCardsDistributionSingleLine;
ZeroMemory(&cbMyCardsDistributionSingleLine,sizeof(CardsDistribution));
AnalyseMyCards(cbHandCardData,cbHandCardCount,cbMyCardsDistributionSingleLine);
if (cbMyCardsDistributionSingleLine.cbSingleLineCardsCount[0] > 0)
{
BYTE cbTmpMyCardData[20] = {0};
CopyMemory(cbTmpMyCardData,cbHandCardData,cbHandCardCount);
RemoveCard(cbMyCardsDistributionSingleLine.cbSingleLineCards[0],cbMyCardsDistributionSingleLine.cbSingleLineCardsCount[0],cbTmpMyCardData,cbHandCardCount);
//剩下的一手出完
if (GetCardType(cbTmpMyCardData,cbHandCardCount-cbMyCardsDistributionSingleLine.cbSingleLineCardsCount[0]) != CT_ERROR)
{
m_OutCardResult.cbCardCount = cbMyCardsDistributionSingleLine.cbSingleLineCardsCount[0];
CopyMemory(m_OutCardResult.cbResultCard, cbMyCardsDistributionSingleLine.cbSingleLineCards[0], cbMyCardsDistributionSingleLine.cbSingleLineCardsCount[0]);
return;
}
}
//雙順+一手牌
CardsDistribution cbMyCardsDistributionDoubleleLine;
ZeroMemory(&cbMyCardsDistributionDoubleleLine,sizeof(CardsDistribution));
AnalyseMyCards(cbHandCardData,cbHandCardCount,cbMyCardsDistributionDoubleleLine);
if (cbMyCardsDistributionDoubleleLine.cbDoubleLineCardsCount[0] > 0)
{
BYTE cbTmpMyCardData[20] = {0};
CopyMemory(cbTmpMyCardData,cbHandCardData,cbHandCardCount);
RemoveCard(cbMyCardsDistributionDoubleleLine.cbDoubleLineCards[0],cbMyCardsDistributionDoubleleLine.cbDoubleLineCardsCount[0]*2,cbTmpMyCardData,cbHandCardCount);
//剩下的一手出完
if (GetCardType(cbTmpMyCardData,cbHandCardCount-cbMyCardsDistributionDoubleleLine.cbDoubleLineCardsCount[0]*2) != CT_ERROR)
{
m_OutCardResult.cbCardCount = cbMyCardsDistributionDoubleleLine.cbDoubleLineCardsCount[0]*2;
CopyMemory(m_OutCardResult.cbResultCard, cbMyCardsDistributionDoubleleLine.cbDoubleLineCards[0], cbMyCardsDistributionDoubleleLine.cbDoubleLineCardsCount[0]*2);
return;
}
}
}
else//跟牌情況
{
BYTE cbTurnCardType = GetCardType(cbTurnCardData,cbTurnCardCount);
switch (cbTurnCardType)
{
case CT_SINGLE:
{
//單牌+一手牌
if (GetCardLogicValue(cbHandCardData[0]) == GetAllUserLargestCardLogicValue())
{
BYTE cbTmpMyCardData[20] = {0};
CopyMemory(cbTmpMyCardData,cbHandCardData,cbHandCardCount);
RemoveCard(cbTmpMyCardData,1,cbTmpMyCardData,cbHandCardCount);
//剩下的一手出完
if (GetCardType(cbTmpMyCardData,cbHandCardCount-1) != CT_ERROR)
{
m_OutCardResult.cbCardCount = 1;
m_OutCardResult.cbResultCard[0] = cbHandCardData[0];
return;
}
}
}
break;
case CT_DOUBLE:
{
//對子+一手牌
CardsDistribution cbMyCardsDistribution2;
ZeroMemory(&cbMyCardsDistribution2,sizeof(CardsDistribution));
AnalyseDoubleCardsOnly(cbHandCardData,cbHandCardCount,cbMyCardsDistribution2);
if (cbMyCardsDistribution2.cbDoubleCardsCount > 0)
{
BYTE cbTmpMyCardData[20] = {0};
CopyMemory(cbTmpMyCardData,cbHandCardData,cbHandCardCount);
RemoveCard(cbMyCardsDistribution2.cbDoubleCards[cbMyCardsDistribution2.cbDoubleCardsCount-1],2,cbTmpMyCardData,cbHandCardCount);
//剩下的一手出完
if (GetCardType(cbTmpMyCardData,cbHandCardCount-2) != CT_ERROR)
{
//我的對子最大
bool bMyDoubleCardsIsBigest = true;
CardsDistribution cbOtherUser1AllDoubleCards;
ZeroMemory(&cbOtherUser1AllDoubleCards,sizeof(CardsDistribution));
AnalyseDoubleCardsOnly(m_cbAllCardData[(cbMeChairID+1)%GAME_PLAYER],m_cbUserCardCount[(cbMeChairID+1)%GAME_PLAYER],cbOtherUser1AllDoubleCards);
if (GetCardLogicValue(cbMyCardsDistribution2.cbDoubleCards[cbMyCardsDistribution2.cbDoubleCardsCount-1][0]) < GetCardLogicValue(cbOtherUser1AllDoubleCards.cbDoubleCards[cbOtherUser1AllDoubleCards.cbDoubleCardsCount][0]))
{
bMyDoubleCardsIsBigest = false;
}
CardsDistribution cbOtherUser2AllDoubleCards;
ZeroMemory(&cbOtherUser2AllDoubleCards,sizeof(CardsDistribution));
AnalyseDoubleCardsOnly(m_cbAllCardData[(cbMeChairID+2)%GAME_PLAYER],m_cbUserCardCount[(cbMeChairID+2)%GAME_PLAYER],cbOtherUser2AllDoubleCards);
if (GetCardLogicValue(cbMyCardsDistribution2.cbDoubleCards[cbMyCardsDistribution2.cbDoubleCardsCount-1][0]) < GetCardLogicValue(cbOtherUser2AllDoubleCards.cbDoubleCards[cbOtherUser2AllDoubleCards.cbDoubleCardsCount][0]))
{
bMyDoubleCardsIsBigest = false;
}
//且我這個對子是最大的對子
if (bMyDoubleCardsIsBigest)
{
m_OutCardResult.cbCardCount = 2;
CopyMemory(m_OutCardResult.cbResultCard, cbMyCardsDistribution2.cbDoubleCards[cbMyCardsDistribution2.cbDoubleCardsCount-1], 2);
return;
}
}
}
}
break;
default:
break;
}
}
}
//我已經能贏
bool CGameLogic::ICanWin(const BYTE cbHandCardData[], BYTE cbHandCardCount, const BYTE cbTurnCardData[], BYTE cbTurnCardCount, tagSearchCardResult & m_OutCardResult)
{
if (GetCardType(cbHandCardData,cbHandCardCount) == CT_ERROR) return false;
if (cbTurnCardCount == 0)
{
m_OutCardResult.cbCardCount = cbHandCardCount;
CopyMemory(m_OutCardResult.cbResultCard, cbHandCardData, cbHandCardCount);
}
else
{
if (CompareCard(cbTurnCardData, cbHandCardData, cbTurnCardCount, cbHandCardCount))
{
m_OutCardResult.cbCardCount = cbHandCardCount;
CopyMemory(m_OutCardResult.cbResultCard, cbHandCardData, cbHandCardCount);
return true;
}
else
{
return false;
}
}
return false;
}
/
總結
- 上一篇: dnf辅助外挂C++源代码
- 下一篇: STL算法学习-- 算法分类