百人红九(温州两张)机器人+控制+真人下注显示【源码】
http://img.woaidaima.com//upload/image/20170511/1494466205934073345.jpghttp://img.woaidaima.com//upload/image/20170511/1494466207768081575.jpg#include "StdAfx.h"#include "GameLogic.h"
//////////////////////////////////////////////////////////////////////////
//扑克数据
const BYTE CGameLogic::m_cbCardListData=
{
0x0C,0x2C,
0x1B,0x3B,
0x0A,0x1A,0x2A,0x3A,
0x09,0x29,
0x07,0x17,0x27,0x37,
0x08,0x18,0x28,0x38,
0x06,0x16,0x26,0x36,
0x05,0x25,
0x04,0x14,0x24,0x34,
0x02,0x22,
0x31,
0x33
};
//////////////////////////////////////////////////////////////////////////
//构造函数
CGameLogic::CGameLogic()
{
}
//析构函数
CGameLogic::~CGameLogic()
{
}
//混乱扑克
void CGameLogic::RandCardList(BYTE cbCardBuffer[], BYTE cbBufferCount)
{
//混乱准备
BYTE cbCardData;
CopyMemory(cbCardData,m_cbCardListData,sizeof(m_cbCardListData));
//混乱扑克
BYTE cbRandCount=0,cbPosition=0;
do
{
cbPosition=rand()%(CountArray(cbCardData)-cbRandCount);
cbCardBuffer=cbCardData;
cbCardData=cbCardData;
} while (cbRandCount<cbBufferCount);
return;
}
//获取牌型
BYTE CGameLogic::GetCardType(const BYTE cbCardData[], BYTE cbCardCount)
{
//合法判断
ASSERT(2==cbCardCount);
if (2!=cbCardCount) return CT_ERROR;
//排序扑克
BYTE cbCardDataSort;
CopyMemory(cbCardDataSort,cbCardData,sizeof(BYTE)*cbCardCount);
SortCardList(cbCardDataSort,cbCardCount,ST_LOGIC);
//获取点数
BYTE cbFirstCardValue=GetCardValue(cbCardDataSort);
BYTE cbSecondCardValue=GetCardValue(cbCardDataSort);
//获取花色
BYTE cbFistCardColor=GetCardColor(cbCardDataSort);
BYTE cbSecondCardColor=GetCardColor(cbCardDataSort);
//特殊牌型
if (12==cbFirstCardValue && cbFirstCardValue==cbSecondCardValue) return CT_SPECIAL_1;
if ((0+2)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 2==cbFirstCardValue) return CT_SPECIAL_2;
if ((3+3)==(cbFistCardColor+cbSecondCardColor) && (1==cbFirstCardValue && 3==cbSecondCardValue || 3==cbFirstCardValue && 1==cbSecondCardValue)) return CT_SPECIAL_3;
if ((0+2)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 8==cbFirstCardValue) return CT_SPECIAL_4;
if ((0+2)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 4==cbFirstCardValue) return CT_SPECIAL_5;
if ((1+3)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 10==cbFirstCardValue) return CT_SPECIAL_6;
if ((1+3)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 6==cbFirstCardValue) return CT_SPECIAL_6;
if ((1+3)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 4==cbFirstCardValue) return CT_SPECIAL_6;
if ((0+2)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 6==cbFirstCardValue) return CT_SPECIAL_7;
if ((0+2)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 7==cbFirstCardValue) return CT_SPECIAL_7;
if ((0+2)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 10==cbFirstCardValue) return CT_SPECIAL_7;
if ((1+3)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 11==cbFirstCardValue) return CT_SPECIAL_7;
if ((1+3)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 7==cbFirstCardValue) return CT_SPECIAL_8;
if ((1+3)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 8==cbFirstCardValue) return CT_SPECIAL_8;
if ((0+2)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 9==cbFirstCardValue) return CT_SPECIAL_8;
if ((0+2)==(cbFistCardColor+cbSecondCardColor) && cbFirstCardValue==cbSecondCardValue && 5==cbFirstCardValue) return CT_SPECIAL_8;
if (12==cbFirstCardValue && 9==cbSecondCardValue) return CT_SPECIAL_9;
if (12==cbFirstCardValue && 8==cbSecondCardValue) return CT_SPECIAL_10;
if (2==cbFirstCardValue && 8==cbSecondCardValue) return CT_SPECIAL_11;
//点数牌型
return CT_POINT;
}
//大小比较
/*
cbNextCardData>cbFirstCardData返回1
cbNextCardData<cbFirstCardData返回-1
cbNextCardData==cbFirstCardData 返回0
*/
int CGameLogic::CompareCard(const BYTE cbFirstCardData[], BYTE cbFirstCardCount,const BYTE cbNextCardData[], BYTE cbNextCardCount)
{
//合法判断
ASSERT(2==cbFirstCardCount && 2==cbNextCardCount);
if (!(2==cbFirstCardCount && 2==cbNextCardCount)) return 0;
//获取牌型
BYTE cbFirstCardType=GetCardType(cbFirstCardData, cbFirstCardCount);
BYTE cbNextCardType=GetCardType(cbNextCardData, cbNextCardCount);
//牌型比较
if (cbFirstCardType != cbNextCardType)
{
if (cbNextCardType > cbFirstCardType) return 1;
else return -1;
}
//特殊牌型判断
if (CT_POINT!=cbFirstCardType && cbFirstCardType==cbNextCardType)
{
return 0;
}
//获取点数
BYTE cbFirstPip=GetCardListPip(cbFirstCardData, cbFirstCardCount);
BYTE cbNextPip=GetCardListPip(cbNextCardData, cbNextCardCount);
//点数比较
if (cbFirstPip != cbNextPip)
{
if (cbNextPip > cbFirstPip) return 1;
else return -1;
}
//零点判断
if (0==cbFirstPip && 0==cbNextPip) return 0;
//排序扑克
BYTE cbFirstCardDataTmp, cbNextCardDataTmp;
CopyMemory(cbFirstCardDataTmp,cbFirstCardData,sizeof(BYTE)*cbFirstCardCount);
CopyMemory(cbNextCardDataTmp,cbNextCardData,sizeof(BYTE)*cbNextCardCount);
SortCardList(cbFirstCardDataTmp,cbFirstCardCount,ST_LOGIC);
SortCardList(cbNextCardDataTmp,cbNextCardCount,ST_LOGIC);
//相等判断
if (GetCardLogicValue(cbFirstCardDataTmp)==GetCardLogicValue(cbNextCardDataTmp)) return 0;
else if (GetCardLogicValue(cbNextCardDataTmp) > GetCardLogicValue(cbFirstCardDataTmp)) return 1;
else -1;
return 0;
}
//获取牌点
BYTE CGameLogic::GetCardListPip(const BYTE cbCardData[], BYTE cbCardCount)
{
//变量定义
BYTE cbPipCount=0;
//获取牌点
BYTE cbCardValue=0;
for (BYTE i=0;i<cbCardCount;i++)
{
cbCardValue=GetCardValue(cbCardData);
cbPipCount+=(1==cbCardValue ? 6 : cbCardValue);
}
return (cbPipCount%10);
}
//逻辑大小
BYTE CGameLogic::GetCardLogicValue(BYTE cbCardData)
{
//获取花色
BYTE cbColor=GetCardColor(cbCardData);
//获取数值
BYTE cbValue=GetCardValue(cbCardData);
//返回逻辑值
if (12==cbValue && (0==cbColor || 2==cbColor)) return 8;
if (2==cbValue && (0==cbColor || 2==cbColor)) return 7;
if (8==cbValue && (0==cbColor || 2==cbColor)) return 6;
if (4==cbValue && (0==cbColor || 2==cbColor)) return 5;
if ((1==cbColor || 3==cbColor) && (10==cbValue || 6==cbValue || 4==cbValue)) return 4;
if ((0==cbColor || 2==cbColor) && (10==cbValue || 6==cbValue || 7==cbValue)) return 3;
if ((1==cbColor || 3==cbColor) && 11==cbValue) return 3;
if ((1==cbColor || 3==cbColor) && (7==cbValue || 8==cbValue)) return 2;
if ((0==cbColor || 2==cbColor) && (5==cbValue || 9==cbValue)) return 2;
if (3==cbColor && (1==cbValue || 3==cbValue)) return 1;
return 0;
}
//排列扑克
void CGameLogic::SortCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbSortType)
{
//数目过虑
if (cbCardCount==0) return;
//转换数值
BYTE cbSortValue;
if (ST_VALUE==cbSortType)
{
for (BYTE i=0;i<cbCardCount;i++) cbSortValue=GetCardValue(cbCardData);
}
else
{
for (BYTE i=0;i<cbCardCount;i++) cbSortValue=GetCardLogicValue(cbCardData);
}
//排序操作
bool bSorted=true;
BYTE cbThreeCount,cbLast=cbCardCount-1;
do
{
bSorted=true;
for (BYTE i=0;i<cbLast;i++)
{
if ((cbSortValue<cbSortValue)||
((cbSortValue==cbSortValue)&&(cbCardData<cbCardData)))
{
//交换位置
cbThreeCount=cbCardData;
cbCardData=cbCardData;
cbCardData=cbThreeCount;
cbThreeCount=cbSortValue;
cbSortValue=cbSortValue;
cbSortValue=cbThreeCount;
bSorted=false;
}
}
cbLast--;
} while(bSorted==false);
return;
}
//////////////////////////////////////////////////////////////////////////
页:
[1]