166 lines
5.4 KiB
C++
166 lines
5.4 KiB
C++
#ifndef GAME_PDK_LOGIC_HEAD_FILE
|
|
#define GAME_PDK_LOGIC_HEAD_FILE
|
|
|
|
#pragma once
|
|
#include "Types.h"
|
|
#include "Macro.h"
|
|
#include "CardDefine.h"
|
|
#include "PDK_CMD.h"
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//排序类型
|
|
#define PDK_ST_ORDER 1 //大小排序
|
|
#define PDK_ST_COUNT 2 //数目排序
|
|
#define PDK_ST_CUSTOM 3 //自定排序
|
|
|
|
//数值掩码
|
|
#define PDK_MASK_COLOR 0xF0 //花色掩码
|
|
#define PDK_MASK_VALUE 0x0F //数值掩码
|
|
|
|
//逻辑类型
|
|
#define PDK_CT_ERROR 0 //错误类型
|
|
#define PDK_CT_SINGLE 1 //单牌类型
|
|
#define PDK_CT_DOUBLE 2 //对牌类型
|
|
#define PDK_CT_SINGLE_LINE 4 //单连类型
|
|
#define PDK_CT_DOUBLE_LINE 5 //对连类型
|
|
#define PDK_CT_THREE_LINE 6 //三连类型(飞机);
|
|
#define PDK_CT_THREE_TAKE_TWO 7 //三带一对
|
|
#define PDK_CT_FOUR_TAKE_THREE 8 //四带两单
|
|
#define PDK_CT_BOMB_CARD 9 //炸弹类型
|
|
#define PDK_CT_3A_BOMB_CARD 10 //炸弹类型
|
|
|
|
#define PDK_ST_HIDE 100
|
|
#define PDK_ST_DEAL_CARD 101
|
|
#define PDK_ST_PASS 102
|
|
#define PDK_ST_CALL 103
|
|
#define PDK_ST_CLICK_CARD 104
|
|
#define PDK_ST_OUT_CARD 105
|
|
#define PDK_ST_LEFT_ONE_CARD 106
|
|
#define PDK_ST_WIN 107
|
|
#define PDK_ST_LOSE 108
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//分析结构
|
|
struct tagPDKAnalyseResult
|
|
{
|
|
uint8 cbBlockCount[4]; //扑克数目
|
|
uint8 cbCardData[4][PDK_MAX_COUNT]; //扑克数据
|
|
};
|
|
|
|
//出牌结果
|
|
struct tagPDKOutCardResult
|
|
{
|
|
uint8 cbCardCount; //扑克数目
|
|
uint8 cbResultCard[PDK_MAX_COUNT]; //结果扑克
|
|
};
|
|
|
|
//分布信息
|
|
struct tagPDKDistributing
|
|
{
|
|
uint8 cbCardCount; //扑克数目
|
|
uint8 cbDistributing[18][6]; //分布信息(按照逻辑值)
|
|
};
|
|
|
|
//搜索结果
|
|
struct tagPDKSearchCardResult
|
|
{
|
|
uint8 cbSearchCount; //结果数目
|
|
uint8 cbCardCount[PDK_MAX_COUNT]; //扑克数目
|
|
uint8 cbResultCard[PDK_MAX_COUNT][PDK_MAX_COUNT]; //结果扑克
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//游戏逻辑类
|
|
class CPDKGameLogic
|
|
{
|
|
//变量定义
|
|
protected:
|
|
static const BYTE m_cbCardData16[PDK_FULL_COUNT]; //扑克数据
|
|
static const BYTE m_cbCardData15[PDK_FULL_COUNT_15]; //扑克数据
|
|
|
|
uint32 m_dwGameRule; //牌型规则;
|
|
|
|
//函数定义
|
|
public:
|
|
//构造函数
|
|
CPDKGameLogic();
|
|
//析构函数
|
|
virtual ~CPDKGameLogic();
|
|
|
|
void SetCardRule(DWORD dwGameRule) { m_dwGameRule = dwGameRule; }
|
|
bool IsHasGameRule(ePDKRuleEnum eType)
|
|
{
|
|
return (m_dwGameRule & eType) > 0;
|
|
}
|
|
|
|
//类型函数
|
|
public:
|
|
//获取类型
|
|
uint8 GetCardType(const uint8 cbCardData[], uint8 cbCardCount, bool isLastCard);
|
|
//获取数值
|
|
uint8 GetCardValue(uint8 cbCardData) { return cbCardData&PDK_MASK_VALUE; }
|
|
//获取花色
|
|
uint8 GetCardColor(uint8 cbCardData) { return cbCardData&PDK_MASK_COLOR; }
|
|
|
|
//控制函数
|
|
public:
|
|
//排列扑克
|
|
void SortCardList(uint8 cbCardData[], uint8 cbCardCount, uint8 cbSortType);
|
|
//删除扑克
|
|
bool RemoveCardList(const uint8 cbRemoveCard[], uint8 cbRemoveCount, uint8 cbCardData[], uint8 cbCardCount);
|
|
//删除扑克
|
|
bool RemoveCard(const uint8 cbRemoveCard[], uint8 cbRemoveCount, uint8 cbCardData[], uint8 cbCardCount);
|
|
//排列扑克
|
|
void SortOutCardList(uint8 cbCardData[], uint8 cbCardCount, bool isLastCard);
|
|
//排列扑克
|
|
BYTE SortOutCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbCardType, BYTE cbBlockCount);
|
|
|
|
//逻辑函数
|
|
public:
|
|
//有效判断
|
|
bool IsValidCard(BYTE cbCardData);
|
|
//逻辑数值
|
|
uint8 GetCardLogicValue(uint8 cbCardData);
|
|
//获取最大牌;
|
|
uint8 GetMaxLogicValue(const BYTE cbHandCardData[], BYTE cbHandCardCount);
|
|
//获取最大牌;
|
|
uint8 GetMaxCardData(const BYTE cbHandCardData[], BYTE cbHandCardCount);
|
|
//对比扑克
|
|
bool CompareCard(const uint8 cbFirstCard[], const uint8 cbNextCard[], uint8 cbFirstCount, uint8 cbNextCount, bool isLastCard);
|
|
//出牌搜索
|
|
uint8 SearchOutCard( const uint8 cbHandCardData[], uint8 cbHandCardCount, const uint8 cbTurnCardData[], uint8 cbTurnCardCount, tagPDKSearchCardResult *pSearchCardResult );
|
|
//同牌搜索
|
|
uint8 SearchSameCard( const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbSameCardCount, tagPDKSearchCardResult *pSearchCardResult );
|
|
|
|
//搜索比出牌;
|
|
bool SearchMustOutCard(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbMustOutCard);
|
|
|
|
//搜索单顺;
|
|
uint8 SearchSingleLine(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbLineCount, tagPDKSearchCardResult *pSearchCardResult);
|
|
//搜索双顺;
|
|
uint8 SearchDoubleLine(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbLineCount, tagPDKSearchCardResult *pSearchCardResult);
|
|
//搜索三带二;
|
|
uint8 SearchThreeTakeTwo(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, tagPDKSearchCardResult *pSearchCardResult);
|
|
//搜索四带三;
|
|
uint8 SearchFourTakeThree(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, tagPDKSearchCardResult *pSearchCardResult);
|
|
//搜索飞机;
|
|
uint8 SearchThreeLineTakeTwo(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbBlockCount, tagPDKSearchCardResult *pSearchCardResult);
|
|
|
|
//内部函数
|
|
public:
|
|
|
|
//构造扑克
|
|
uint8 MakeCardData(uint8 cbValueIndex, uint8 cbColorIndex);
|
|
//分析扑克
|
|
void AnalysebCardData(const uint8 cbCardData[], uint8 cbCardCount, tagPDKAnalyseResult & AnalyseResult);
|
|
//分析分布
|
|
void AnalysebDistributing(const uint8 cbCardData[], uint8 cbCardCount, tagPDKDistributing & Distributing);
|
|
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#endif |