想要查看内容赶紧注册登陆吧!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
#include "StdAfx.h"
#include "GameLogic.h"
//////////////////////////////////////////////////////////////////////////
//扑克数据
BYTE CGameLogic::m_cbCardListData[172-4]=
{
2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,\
2,4,6,8,10,12,14,16, 18,20,22,24,26,28,30,32,\
1,9,17,25,3,11,19,27,3,11,19,27, 5,13,21,29,5,\
13,21,29,5,13,21,29,7,15,23,31,7,15,23,31,7,15,23,31,7,15,23,31,\
2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,\
2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,\
2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,\
2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,\
2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,\
2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32\
};
//////////////////////////////////////////////////////////////////////////
//构造函数
CGameLogic::CGameLogic()
{
}
//析构函数
CGameLogic::~CGameLogic()
{
}
//混乱扑克
void CGameLogic::RandCardList(BYTE cbCardBuffer[], BYTE cbBufferCount)
{
//混乱准备
BYTE cbCardData[CountArray(m_cbCardListData)];
CopyMemory(cbCardData,m_cbCardListData,sizeof(m_cbCardListData));
//混乱扑克
BYTE cbRandCount=0,cbPosition=0;
do
{
cbPosition=rand()%(CountArray(cbCardData)-cbRandCount);
cbCardBuffer[cbRandCount++]=cbCardData[cbPosition];
cbCardData[cbPosition]=cbCardData[CountArray(cbCardData)-cbRandCount];
} while (cbRandCount<cbBufferCount);
return;
}
//获取牌型
BYTE CGameLogic::GetCardType(const BYTE cbCardData, BYTE cbCardCount,BYTE *bcOutCadDataWin )
{
ASSERT(1==cbCardCount);
if (!(1==cbCardCount) )return 0;
memset(bcOutCadDataWin,0,AREA_COUNT);
BYTE bcData =cbCardData;
if(0==bcData) return true;
//燕子X6 鸽子X8 孔雀X8 老鹰X12 狮子X12 熊猫X8 猴子X8 兔子X6 鲨鱼24 飞禽2 走兽2
//几率 4 3 3 2 2 3 3 4 1
//兔子3 鲨鱼 燕子3 鸽子3 鲨鱼 孔雀3 老鹰3 鲨鱼 狮子3 熊猫3 鲨鱼 猴子3
//兔子
if(1==bcData||bcData==2||bcData==3)
{
bcOutCadDataWin[1-1]= 12;
bcOutCadDataWin[11-1]= 2;
}
//燕子
else if(5==bcData||bcData==6||bcData==7)
{
bcOutCadDataWin[2-1]= 8;
bcOutCadDataWin[10-1]= 2;
}
//鸽子
else if(8==bcData||bcData==9||bcData==10)
{
bcOutCadDataWin[3-1]= 6;
bcOutCadDataWin[10-1]= 2;
}
//孔雀
else if(12==bcData||bcData==13||bcData==14)
{
bcOutCadDataWin[4-1]= 6;
bcOutCadDataWin[10-1]= 2;
}
//老鹰
else if(15==bcData||bcData==16||bcData==17)
{
bcOutCadDataWin[5-1]= 12;
bcOutCadDataWin[10-1]= 2;
}
//狮子
else if(19==bcData||bcData==20||bcData==21)
{
bcOutCadDataWin[6-1]= 8;
bcOutCadDataWin[11-1]= 2;
}
//熊猫
else if(22==bcData||bcData==23||bcData==24)
{
bcOutCadDataWin[7-1]= 6;
bcOutCadDataWin[11-1]= 2;
}
//猴子
else if(26==bcData||bcData==27||bcData==28)
{
bcOutCadDataWin[8-1]= 6;
bcOutCadDataWin[11-1]= 2;
}
//鲨鱼
else
{
for (WORD wAreaIndex = 1; wAreaIndex <= AREA_COUNT; ++wAreaIndex)
{
bcOutCadDataWin[wAreaIndex-1] = 1;
}
bcOutCadDataWin[9-1]= 24;
}
return true;
}
//大小比较
/*
cbNextCardData>cbFirstCardData 返回1
cbNextCardData<cbFirstCardData 返回-1
cbNextCardData==cbFirstCardData 返回0
*/
//Multiple 比较出来的倍数
int CGameLogic::CompareCard(const BYTE cbFirstCardData[], BYTE cbFirstCardCount,const BYTE cbNextCardData[], BYTE cbNextCardCount,BYTE &Multiple)
{
//合法判断
ASSERT(1==cbFirstCardCount && 1==cbNextCardCount);
if (!(1==cbFirstCardCount && 1==cbNextCardCount)) return 0;
return true;
}
//获取牌点
BYTE CGameLogic::GetCardListPip(const BYTE cbCardData[], BYTE cbCardCount)
{
//变量定义
BYTE cbPipCount=0;
//获取牌点
BYTE cbCardValue=0;
for (BYTE i=0;i<cbCardCount;i++)
{
cbCardValue=GetCardValue(cbCardData);
if(cbCardValue>10)
{
cbCardValue = 10;
}
cbPipCount+=cbCardValue;
}
return (cbPipCount%10);
}
BYTE CGameLogic::GetCardNewValue(BYTE cbCardData)
{
//扑克属性
BYTE cbCardColor=GetCardColor(cbCardData);
BYTE cbCardValue=GetCardValue(cbCardData);
//转换数值
if (cbCardColor==0x04) return cbCardValue+13+2;
return cbCardValue;
}
//逻辑大小
BYTE CGameLogic::GetCardLogicValue(BYTE cbCardData)
{
BYTE cbValue=GetCardValue(cbCardData);
//获取花色
BYTE cbColor=GetCardColor(cbCardData);
if(cbValue>10)
{
cbValue = 10;
}
if(cbColor==0x4)
{
return 11;
}
return cbValue;
}
//排列扑克
void CGameLogic::SortCardList(BYTE cbCardData[], BYTE cbCardCount, BYTE cbSortType)
{
//数目过虑
if (cbCardCount==0) return;
//转换数值
BYTE cbSortValue[CARD_COUNT];
if (ST_VALUE==cbSortType)
{
for (BYTE i=0;i<cbCardCount;i++) cbSortValue=GetCardValue(cbCardData);
}
else
{
if(cbSortType==ST_NEW)
{
for (BYTE i=0;i<cbCardCount;i++) cbSortValue=GetCardNewValue(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[i+1])||
((cbSortValue==cbSortValue[i+1])&&(cbCardData<cbCardData[i+1])))
{
//交换位置
cbThreeCount=cbCardData;
cbCardData=cbCardData[i+1];
cbCardData[i+1]=cbThreeCount;
cbThreeCount=cbSortValue;
cbSortValue=cbSortValue[i+1];
cbSortValue[i+1]=cbThreeCount;
bSorted=false;
}
}
cbLast--;
} while(bSorted==false);
return;
}
//////////////////////////////////////////////////////////////////////////
//混乱数组
void CGameLogic::RandArray( INT nArrayOne[], INT nCountOne, INT nArrayTwo[], INT nCountTwo )
{
ASSERT( nCountOne == nCountTwo );
if( nCountTwo != nCountOne )
return;
DWORD wTick = GetTickCount();
for (int i = 1; i < nCountOne; ++i)
{
int nTempIndex = (rand()+wTick)%nCountOne;
int nTempValueOne = nArrayOne;
nArrayOne = nArrayOne[nTempIndex];
nArrayOne[nTempIndex] = nTempValueOne;
int nTempValueTwo = nArrayTwo;
nArrayTwo = nArrayTwo[nTempIndex];
nArrayTwo[nTempIndex] = nTempValueTwo;
}
}
|