金皇冠改版2【源码】
http://img.woaidaima.com//upload/image/20170523/1495499914182041146.pnghttp://img.woaidaima.com//upload/image/20170523/1495499915978092266.png#include "StdAfx.h"#include "GameLogic.h"
//////////////////////////////////////////////////////////////////////////
//扑克数据
BYTE CGameLogic::m_cbCardListData=
{
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)==GetCardLogicValue(cbCardData))?CT_PAIR:CT_SINGLE;
}
}
//五条类型
if (cbCardCount==5)
{
bool bgui=false;
//变量定义
bool cbSameColor=true,bLineCard=true;
BYTE cbFirstColor=GetCardColor(cbCardData);
BYTE cbFirstValue=GetCardLogicValue(cbCardData);
if (cbCardData==0x41)
{
bgui=true;
cbFirstColor=GetCardColor(cbCardData);
cbFirstValue=GetCardLogicValue(cbCardData);
}
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==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)==13||GetCardValue(cbCardData)==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)==13||GetCardValue(cbCardData)==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;
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)||
((cbLogicValue==cbLogicValue)&&(cbCardData<cbCardData)))
{
//交换位置
cbTempData=cbCardData;
cbCardData=cbCardData;
cbCardData=cbTempData;
cbTempData=cbLogicValue;
cbLogicValue=cbLogicValue;
cbLogicValue=cbTempData;
bSorted=false;
}
}
bLast--;
} while(bSorted==false);
return;
}
//混乱扑克
void CGameLogic::RandCardList(BYTE cbCardBuffer[], BYTE cbBufferCount)
{
//混乱准备
BYTE cbCardData;
CopyMemory(cbCardData,m_cbCardListData,sizeof(m_cbCardListData));
//混乱扑克
BYTE bRandCount=0,bPosition=0;
do
{
bPosition=rand()%(CountArray(m_cbCardListData)-bRandCount);
cbCardBuffer=cbCardData;
cbCardData=cbCardData;
} while (bRandCount<cbBufferCount);
cbCardBuffer=0x21;cbCardBuffer=0x2D;cbCardBuffer=0x2C;cbCardBuffer=0x2B;cbCardBuffer=0x27;
//cbCardBuffer=0x11;cbCardBuffer=0x29;cbCardBuffer=0x39;cbCardBuffer=0x18;
//cbCardBuffer=0x01;cbCardBuffer=0x11;cbCardBuffer=0x29;cbCardBuffer=0x39;cbCardBuffer=0x1C;
//cbCardBuffer=0x01;cbCardBuffer=0x11;cbCardBuffer=0x29;cbCardBuffer=0x39;cbCardBuffer=0x29;
//cbCardBuffer=0x01;cbCardBuffer=0x11;cbCardBuffer=0x29;cbCardBuffer=0x39;cbCardBuffer=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={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)!=cbLogicValue) break;
//设置扑克
cbSameCardData=cbCardData;
}
//保存结果
switch (cbSameCount)
{
case 1: //单张
{
AnalyseResult.cbSignedLogicValue=cbLogicValue;
CopyMemory(&AnalyseResult.cbSignedCardData[(AnalyseResult.cbSignedCount++)*cbSameCount],cbSameCardData,cbSameCount);
break;
}
case 2: //两张
{
time++;
card=cbLogicValue;
AnalyseResult.cbDoubleLogicValue=cbLogicValue;
CopyMemory(&AnalyseResult.cbDoubleCardData[(AnalyseResult.cbDoubleCount++)*cbSameCount],cbSameCardData,cbSameCount);
break;
}
case 3: //三张
{
time+=2;
AnalyseResult.cbThreeLogicValue=cbLogicValue;
CopyMemory(&AnalyseResult.cbThreeCardData[(AnalyseResult.cbThreeCount++)*cbSameCount],cbSameCardData,cbSameCount);
break;
}
case 4: //四张
{
AnalyseResult.cbFourLogicValue=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);
BYTE cbFirstValue=GetCardLogicValue(cbCardData);
if (cbCardData==0x41)
{
cbFirstColor=GetCardColor(cbCardData);
cbFirstValue=GetCardLogicValue(cbCardData);
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==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={cbCardData,0,0,0};
BYTE cbLogicValue=GetCardValue(cbCardData);
//获取同牌
for (int j=i+1;j<5;j++)
{
//逻辑对比
if (GetCardLogicValue(cbCardData)!=cbLogicValue) break;
cbShowCard=true;
cbShowCard=true;
//设置扑克
cbSameCardData=cbCardData;
}
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)>=8)
{
cbShowCard=true;
}
}
return;
}
//////////////////////////////////////////////////////////////////////////
页:
[1]