想要查看内容赶紧注册登陆吧!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
#include "StdAfx.h"
#include "GameLogic.h"
//////////////////////////////////////////////////////////////////////////
//扑克数据
BYTE CGameLogic::m_cbCardListData[GAME_CARD]=
{
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
0x41 //大小鬼
};
//////////////////////////////////////////////////////////////////////////
//构造函数
CGameLogic::CGameLogic()
{
}
//析构函数
CGameLogic::~CGameLogic()
{
}
//获取类型
BYTE CGameLogic::GetCardType(BYTE cbCardData[], BYTE cbCardCount)
{
//简单牌形
switch (cbCardCount)
{
case 1: //单牌
{
return CT_SINGLE;
}
case 2: //对牌
{
return (GetCardLogicValue(cbCardData[0])==GetCardLogicValue(cbCardData[1]))?CT_PAIR:CT_SINGLE;
}
}
//五条类型
if (cbCardCount==5)
{
bool bgui=false;
//变量定义
bool cbSameColor=true,bLineCard=true;
BYTE cbFirstColor=GetCardColor(cbCardData[0]);
BYTE cbFirstValue=GetCardLogicValue(cbCardData[0]);
if (cbCardData[0]==0x41)
{
bgui=true;
cbFirstColor=GetCardColor(cbCardData[1]);
cbFirstValue=GetCardLogicValue(cbCardData[1]);
}
int t=0;
int t2=0;
int ivalue=0;
int icount=1;
if (bgui)
{
t=1;
t2=1;
icount=2;
}
//牌形分析
for (BYTE i=icount;i<5;i++)
{
//数据分析
if (GetCardColor(cbCardData)!=cbFirstColor) cbSameColor=false;
if (cbFirstValue!=(GetCardLogicValue(cbCardData)+i-icount+1)+ivalue)
{
bLineCard=false;
if (bgui)
{
ivalue++;
if (cbFirstValue==(GetCardLogicValue(cbCardData)+i-icount+1)+ivalue)
{
bgui=false;
bLineCard=true;
}
}
}
if (cbSameColor==false)
{
t++;
cbSameColor=true;
}
if (bLineCard==false)
{
t2++;
bLineCard=true;
}
}
bool b=false;
if (cbCardData[0]==0x41)
{
b= true;
}
if (b)
{
//顺子类型
if (t2==1&&t!=1) return CT_STRAIGHT;
//同花类型
if (t2!=1&&t==1) return CT_FLUSH;
//同花顺类型
if (t2==1&&t==1)
{
if (GetCardValue(cbCardData[1])==13||GetCardValue(cbCardData[1])==1)
{
return CT_DASHUN;
}
return CT_SEQUENCE;
}
}
//顺子类型
if (t2==0&&t!=0) return CT_STRAIGHT;
//同花类型
if (t2!=0&&t==0) return CT_FLUSH;
//同花顺类型
if (t2==0&&t==0)
{
if (GetCardValue(cbCardData[1])==13||GetCardValue(cbCardData[1])==1)
{
return CT_DASHUN;
}
return CT_SEQUENCE;
}
}
//扑克分析
tagAnalyseResult AnalyseResult;
AnalysebCardData(cbCardData,cbCardCount,AnalyseResult);
//类型判断
if (AnalyseResult.cbFourCount==1) return CT_IRON_BRANCH;
if (AnalyseResult.cbDoubleCount==2) return CT_DOUBLE_PAIR;
if ((AnalyseResult.cbDoubleCount==1)&&(AnalyseResult.cbThreeCount==1)) return CT_GOURD;
if ((AnalyseResult.cbThreeCount==1)&&(AnalyseResult.cbDoubleCount==0)) return CT_TRIPLE;
if ((AnalyseResult.cbDoubleCount==1)&&(AnalyseResult.cbSignedCount==3)) return CT_PAIR;
return CT_SINGLE;
}
//排列扑克
void CGameLogic::SortCardList(BYTE cbCardData[], BYTE cbCardCount)
{
//转换数值
BYTE cbLogicValue[MAX_COUNT];
for (BYTE i=0;i<cbCardCount;i++) cbLogicValue=GetCardLogicValue(cbCardData);
//排序操作
bool bSorted=true;
BYTE cbTempData,bLast=cbCardCount-1;
do
{
bSorted=true;
for (BYTE i=0;i<bLast;i++)
{
if ((cbLogicValue<cbLogicValue[i+1])||
((cbLogicValue==cbLogicValue[i+1])&&(cbCardData<cbCardData[i+1])))
{
//交换位置
cbTempData=cbCardData;
cbCardData=cbCardData[i+1];
cbCardData[i+1]=cbTempData;
cbTempData=cbLogicValue;
cbLogicValue=cbLogicValue[i+1];
cbLogicValue[i+1]=cbTempData;
bSorted=false;
}
}
bLast--;
} while(bSorted==false);
return;
}
//混乱扑克
void CGameLogic::RandCardList(BYTE cbCardBuffer[], BYTE cbBufferCount)
{
//混乱准备
BYTE cbCardData[CountArray(m_cbCardListData)];
CopyMemory(cbCardData,m_cbCardListData,sizeof(m_cbCardListData));
//混乱扑克
BYTE bRandCount=0,bPosition=0;
do
{
bPosition=rand()%(CountArray(m_cbCardListData)-bRandCount);
cbCardBuffer[bRandCount++]=cbCardData[bPosition];
cbCardData[bPosition]=cbCardData[CountArray(m_cbCardListData)-bRandCount];
} while (bRandCount<cbBufferCount);
cbCardBuffer[0]=0x21;cbCardBuffer[1]=0x2D;cbCardBuffer[2]=0x2C;cbCardBuffer[3]=0x2B;cbCardBuffer[4]=0x27;
//cbCardBuffer[6]=0x11;cbCardBuffer[7]=0x29;cbCardBuffer[8]=0x39;cbCardBuffer[9]=0x18;
//cbCardBuffer[10]=0x01;cbCardBuffer[11]=0x11;cbCardBuffer[12]=0x29;cbCardBuffer[13]=0x39;cbCardBuffer[14]=0x1C;
//cbCardBuffer[15]=0x01;cbCardBuffer[16]=0x11;cbCardBuffer[17]=0x29;cbCardBuffer[18]=0x39;cbCardBuffer[19]=0x29;
//cbCardBuffer[20]=0x01;cbCardBuffer[21]=0x11;cbCardBuffer[22]=0x29;cbCardBuffer[23]=0x39;cbCardBuffer[24]=0x2D;
return;
}
//逻辑数值
BYTE CGameLogic::GetCardLogicValue(BYTE cbCardData)
{
//扑克属性
BYTE bCardColor=GetCardColor(cbCardData);
BYTE bCardValue=GetCardValue(cbCardData);
//if (cbCardData==0x41)
//{
// return 15;
//}
//转换数值
return (bCardValue<=1)?(bCardValue+13):bCardValue;
}
//分析扑克
void CGameLogic::AnalysebCardData(const BYTE cbCardData[], BYTE cbCardCount, tagAnalyseResult & AnalyseResult)
{
//设置结果
ZeroMemory(&AnalyseResult,sizeof(AnalyseResult));
int time=0;
BYTE card=0;
//扑克分析
for (BYTE i=0;i<cbCardCount;i++)
{
//变量定义
BYTE cbSameCount=1;
BYTE cbSameCardData[4]={cbCardData,0,0,0};
BYTE cbLogicValue=GetCardLogicValue(cbCardData);
if (cbCardData==0x41)
{
AnalyseResult.cbSignedCount++;
continue;
}
//获取同牌
for (int j=i+1;j<cbCardCount;j++)
{
//逻辑对比
if (GetCardLogicValue(cbCardData[j])!=cbLogicValue) break;
//设置扑克
cbSameCardData[cbSameCount++]=cbCardData[j];
}
//保存结果
switch (cbSameCount)
{
case 1: //单张
{
AnalyseResult.cbSignedLogicValue[AnalyseResult.cbSignedCount]=cbLogicValue;
CopyMemory(&AnalyseResult.cbSignedCardData[(AnalyseResult.cbSignedCount++)*cbSameCount],cbSameCardData,cbSameCount);
break;
}
case 2: //两张
{
time++;
card=cbLogicValue;
AnalyseResult.cbDoubleLogicValue[AnalyseResult.cbDoubleCount]=cbLogicValue;
CopyMemory(&AnalyseResult.cbDoubleCardData[(AnalyseResult.cbDoubleCount++)*cbSameCount],cbSameCardData,cbSameCount);
break;
}
case 3: //三张
{
time+=2;
AnalyseResult.cbThreeLogicValue[AnalyseResult.cbThreeCount]=cbLogicValue;
CopyMemory(&AnalyseResult.cbThreeCardData[(AnalyseResult.cbThreeCount++)*cbSameCount],cbSameCardData,cbSameCount);
break;
}
case 4: //四张
{
AnalyseResult.cbFourLogicValue[AnalyseResult.cbFourCount]=cbLogicValue;
CopyMemory(&AnalyseResult.cbFourCardData[(AnalyseResult.cbFourCount++)*cbSameCount],cbSameCardData,cbSameCount);
break;
}
}
//设置递增
i+=cbSameCount-1;
}
bool b=true;
for (int i=0;i<cbCardCount;i++)
{
if (cbCardData==0x41)
{
b=false;
}
}
if (time==1&&b)
{
if (card<=7)
{
AnalyseResult.cbDoubleCount=0;
}
}
return;
}
//分析保留扑克
void CGameLogic::AnalyseKeepCardData(const BYTE cbCardData[], BYTE cbShowCard[])
{
//变量定义
//变量定义
bool bgui=false;
bool cbSameColor=true,bLineCard=true;
BYTE cbFirstColor=GetCardColor(cbCardData[0]);
BYTE cbFirstValue=GetCardLogicValue(cbCardData[0]);
if (cbCardData[0]==0x41)
{
cbFirstColor=GetCardColor(cbCardData[1]);
cbFirstValue=GetCardLogicValue(cbCardData[1]);
bgui=true;
}
int t=0;
int pos=0;
int t2=0;
int pos2=0;
int ivalue=0;
int icount=1;
if (bgui)
{
t2=1;
t=1;
icount=2;
}
//牌形分析
for (BYTE i=icount;i<5;i++)
{
//数据分析
if (GetCardColor(cbCardData)!=cbFirstColor) cbSameColor=false;
BYTE cbvalue2=GetCardLogicValue(cbCardData);
if (cbFirstValue!=(cbvalue2+i-icount+1)+ivalue)
{
bLineCard=false;
if (bgui)
{
ivalue++;
cbvalue2=GetCardLogicValue(cbCardData);
if (cbFirstValue==(cbvalue2+i-icount+1)+ivalue)
{
bgui=false;
bLineCard=true;
}
}
}
if (cbSameColor==false)
{
t++;
pos=i;
cbSameColor=true;
}
if (bLineCard==false)
{
t2++;
pos2=i;
bLineCard=true;
}
}
if (cbCardData[0]==0x41)
{
t--;
t2--;
}
if (t==0||t2==0)
{
//顺子,同花,同花顺类型
if ((cbSameColor==true)||(bLineCard==true))
{
for (int i=0;i<5;i++)
{
cbShowCard=true;
}
return;
}
}
int time=0;
BYTE card=0;
bool b=true;
//扑克分析
for (BYTE i=0;i<5;i++)
{
//变量定义
BYTE cbSameCount=1;
BYTE cbSameCardData[4]={cbCardData,0,0,0};
BYTE cbLogicValue=GetCardValue(cbCardData);
//获取同牌
for (int j=i+1;j<5;j++)
{
//逻辑对比
if (GetCardLogicValue(cbCardData[j])!=cbLogicValue) break;
cbShowCard=true;
cbShowCard[j]=true;
//设置扑克
cbSameCardData[cbSameCount++]=cbCardData[j];
}
if (cbSameCount==2)
{
time++;
card=cbCardData;
}
if (cbSameCount==3)
{
time+=2;
}
//设置递增
i+=cbSameCount-1;
}
if (time==1)
{
if (GetCardLogicValue(card)<8&&b)
{
for (int i=0;i<5;i++)
{
if (GetCardLogicValue(cbCardData)==GetCardLogicValue(card))
{
cbShowCard=false;
}
}
}
}
if (time==0&&!b)
{
if (GetCardLogicValue(cbCardData[1])>=8)
{
cbShowCard[1]=true;
}
}
return;
}
//////////////////////////////////////////////////////////////////////////
|