204 lines
6.3 KiB
C++
204 lines
6.3 KiB
C++
#ifndef DZ_GAME_LOGIC_HEAD_FILE
|
|
#define DZ_GAME_LOGIC_HEAD_FILE
|
|
|
|
#pragma once
|
|
#include "Types.h"
|
|
#include "Macro.h"
|
|
#include "CardDefine.h"
|
|
#include "DZ_CMD.h"
|
|
|
|
//排序类型
|
|
#define DZ_ST_ORDER 0 //大小排序
|
|
#define DZ_ST_COUNT 1 //数目排序
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//数目定义;
|
|
#define DZ_MAX_COUNT 27 //最大数目;
|
|
#define DZ_FULL_COUNT 108 //全牌数目;
|
|
|
|
#define DZ_MAX_NO_JOKER_COUNT 26 //最大数目
|
|
#define NO_JOKER_COUNT 104 //全牌数目
|
|
|
|
//逻辑数目;
|
|
#define DZ_NORMAL_COUNT 27 //常规数目;
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//数值掩码
|
|
#define DZ_MASK_COLOR 0xF0 //花色掩码
|
|
#define DZ_MASK_VALUE 0x0F //数值掩码
|
|
|
|
//扑克类型
|
|
enum CART_TYPE
|
|
{
|
|
DZ_CT_ERROR = 0, //错误类型
|
|
|
|
DZ_CT_SINGLE, //单牌类型
|
|
DZ_CT_DOUBLE, //对牌类型
|
|
DZ_CT_THREE_TAKE_TWO, //三条类型
|
|
DZ_CT_SINGLE_LINE, //单连类型
|
|
DZ_CT_DOUBLE_LINE, //对连类型
|
|
DZ_CT_THREE_LINE, //三连类型
|
|
DZ_CT_BOMB_4, //炸弹类型
|
|
DZ_CT_BOMB_5, //炸弹类型
|
|
DZ_CT_BOMB_6, //炸弹类型
|
|
DZ_CT_BOMB_7, //炸弹类型
|
|
DZ_CT_BOMB_8, //炸弹类型
|
|
DZ_CT_BOMB_9, //炸弹类型
|
|
DZ_CT_BOMB_10, //炸弹类型
|
|
|
|
DZ_CT_COUNT, //牌型数量
|
|
};
|
|
|
|
#define DZ_ST_HIDE 100
|
|
#define DZ_ST_DEAL_CARD 101
|
|
#define DZ_ST_PASS 102
|
|
#define DZ_ST_CALL 103
|
|
#define DZ_ST_CLICK_CARD 104
|
|
#define DZ_ST_OUT_CARD 105
|
|
#define DZ_ST_LEFT_ONE_CARD 106
|
|
#define DZ_ST_WIN 107
|
|
#define DZ_ST_LOSE 108
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
#define DZ_MAX_BLOCK_COUNT 12 //一手牌最大张数
|
|
|
|
enum CARD_BLOCK_INDEX
|
|
{
|
|
BLOCK_ONE = 0,
|
|
BLOCK_TWO,
|
|
BLOCK_THREE,
|
|
BLOCK_FOUR,
|
|
BLOCK_FIVE,
|
|
BLOCK_SIX,
|
|
BLOCK_SEVEN,
|
|
BLOCK_EIGHT,
|
|
BLOCK_NINE,
|
|
BLOCK_TEN,
|
|
BLOCK_ELEVEN,
|
|
BLOCK_TWELVE
|
|
};
|
|
|
|
struct tagDZAnalyseResult
|
|
{
|
|
uint8 cbBlockCount[DZ_MAX_BLOCK_COUNT]; //扑克数目
|
|
uint8 cbCardData[DZ_MAX_BLOCK_COUNT][DZ_MAX_COUNT]; //扑克数据
|
|
bool cbLaiZi;
|
|
};
|
|
|
|
//出牌结果
|
|
struct tagDZOutCardResult
|
|
{
|
|
uint8 cbCardCount; //扑克数目
|
|
uint8 cbResultCard[DZ_MAX_COUNT]; //结果扑克
|
|
};
|
|
|
|
//分布信息
|
|
struct tagDZDistributing
|
|
{
|
|
uint8 cbCardCount; //扑克数目
|
|
uint8 cbDistributing[18][6]; //分布信息(按照逻辑值)
|
|
};
|
|
|
|
//搜索结果
|
|
struct tagDZSearchCardResult
|
|
{
|
|
uint8 cbSearchCount; //结果数目
|
|
uint8 cbCardCount[DZ_MAX_COUNT]; //扑克数目
|
|
uint8 cbResultCard[DZ_MAX_COUNT][DZ_MAX_COUNT]; //结果扑克
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//游戏逻辑类
|
|
class DZ_CGameLogic
|
|
{
|
|
//变量定义
|
|
protected:
|
|
static const uint8 m_cbCardData[DZ_FULL_COUNT]; //扑克数据
|
|
static const uint8 m_cbNoJokerCardData[DZ_NO_JOKER_COUNT];
|
|
|
|
//函数定义
|
|
public:
|
|
//构造函数
|
|
DZ_CGameLogic();
|
|
//析构函数
|
|
virtual ~DZ_CGameLogic();
|
|
|
|
//类型函数
|
|
public:
|
|
//获取类型
|
|
int GetCardType(const uint8 cbCardData[], uint8 cbCardCount, bool isLastCard);
|
|
//获取数值
|
|
uint8 GetCardValue(uint8 cbCardData) { return cbCardData&DZ_MASK_VALUE; }
|
|
//获取花色
|
|
uint8 GetCardColor(uint8 cbCardData) { return cbCardData&DZ_MASK_COLOR; }
|
|
|
|
//控制函数
|
|
public:
|
|
//混乱扑克
|
|
void RandCardList(uint8 cbCardBuffer[], uint8 cbBufferCount);
|
|
//混乱扑克
|
|
void RandNoJokerCardList(uint8 cbCardBuffer[], uint8 cbBufferCount);
|
|
//排列扑克
|
|
void SortCardList(uint8 cbCardData[], uint8 cbCardCount, uint8 cbSortType);
|
|
//删除扑克
|
|
bool RemoveCard(const uint8 cbRemoveCard[], uint8 cbRemoveCount, uint8 cbCardData[], uint8 cbCardCount);
|
|
//随机扑克
|
|
uint8 GetRandomCard(void) ;
|
|
//排列扑克
|
|
void SortOutCardList(uint8 cbCardData[], uint8 cbCardCount, int nCardType, bool isLastCard);
|
|
|
|
//逻辑函数
|
|
public:
|
|
//有效判断
|
|
bool IsValidCard(uint8 cbCardData);
|
|
//逻辑数值
|
|
uint8 GetCardLogicValue(uint8 cbCardData);
|
|
//对比扑克(比较前需确认牌型合法);
|
|
bool CompareCard(const DZ_CMD_C_OutCard* pFirstOutCard, const DZ_CMD_C_OutCard* pNextOutCard);
|
|
//赖子数目
|
|
uint8 GetLaiZiCount(const uint8 cbHandCardData[], uint8 cbHandCardCount);
|
|
//是否癞子牌
|
|
bool IsLaiZiCard(uint8 cbCard);
|
|
//出牌搜索
|
|
uint8 SearchOutCard(const uint8 cbHandCardData[], uint8 cbHandCardCount, const DZ_CMD_C_OutCard* pFirstOutCard, tagDZSearchCardResult *pSearchCardResult);
|
|
//搜索单牌;
|
|
uint8 SearchSingle(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, tagDZSearchCardResult *pSearchCardResult);
|
|
//搜索对子;
|
|
uint8 SearchDouble(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, tagDZSearchCardResult *pSearchCardResult);
|
|
//搜索单顺;
|
|
uint8 SearchSingleLine(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbLineCount, tagDZSearchCardResult *pSearchCardResult);
|
|
//搜索双顺;
|
|
uint8 SearchDoubleLine(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbLineCount, tagDZSearchCardResult *pSearchCardResult);
|
|
//搜索三带二;
|
|
uint8 SearchThreeTakeTwo(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, tagDZSearchCardResult *pSearchCardResult);
|
|
//搜索飞机;
|
|
uint8 SearchThreeLineTakeTwo(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbBlockCount, tagDZSearchCardResult *pSearchCardResult);
|
|
//搜索炸弹;
|
|
uint8 SearchBomb(const uint8 cbHandCardData[], uint8 cbHandCardCount, uint8 cbReferCard, uint8 cbReferCount, int iReferCardType, tagDZSearchCardResult *pSearchCardResult, uint8 &cbResultCount);
|
|
|
|
//内部函数
|
|
public:
|
|
//分析扑克
|
|
void AnalysebCardData(const uint8 cbCardData[], uint8 cbCardCount, tagDZAnalyseResult & AnalyseResult);
|
|
//分析比较
|
|
bool AnalysebCompare(const uint8 cbCardData[], uint8 cbCardCount, uint8 cbMaxCardData[DZ_CT_COUNT], uint8 &cbBlockCount, int dCardType, bool isLastCard);
|
|
//牌组转换(将32张牌的使用情况转化为一个32位整型)
|
|
int TransListToInt(int iOldType,int iNewType);
|
|
//是否包含牌型
|
|
bool IsHasCardType(int iCardType, CART_TYPE ct_value);
|
|
//是不是炸弹;
|
|
bool IsBombType(int iCardType);
|
|
//分析分布
|
|
void AnalysebDistributing(const uint8 cbCardData[], uint8 cbCardCount, tagDZDistributing & Distributing);
|
|
|
|
private:
|
|
//获取类型结果
|
|
int GetType(tagDZAnalyseResult& AnalyseResult, const uint8 cbCardData[], uint8 cbCardCount, uint8& cbMaxCardData, uint8 &cbBlockCount, bool isLastCard);
|
|
//构造扑克
|
|
uint8 MakeCardData(uint8 cbLogicValue, uint8 cbColorIndex);
|
|
};
|
|
|
|
#endif
|