Exemple #1
0
//扑克转换
BYTE CGameLogic::SwitchToCardData(BYTE cbCardIndex[MAX_INDEX], BYTE cbCardData[], BYTE bMaxCount)
{
	//转换扑克 王牌放到最前面
	BYTE bPosition=0;
	if(cbCardIndex[CARD_KING_INDEX] > 0)
	{
		for (BYTE j=0;j<cbCardIndex[CARD_KING_INDEX];j++)
		{
			ASSERT(bPosition<bMaxCount);
			cbCardData[bPosition++]=SwitchToCardData(CARD_KING_INDEX);
		}
	}
	
	for (BYTE i=0;i<MAX_INDEX;i++) 
	{
		if(i == CARD_KING_INDEX)
		{
			continue;
		}
		if (cbCardIndex[i]!=0)
		{
			for (BYTE j=0;j<cbCardIndex[i];j++)
			{
				ASSERT(bPosition<bMaxCount);
				cbCardData[bPosition++]=SwitchToCardData(i);
			}
		}
	}

	return bPosition;
}
Exemple #2
0
//扑克转换
BYTE CGameLogic::SwitchToCardData(const BYTE cbCardIndex[MAX_INDEX], BYTE cbCardData[MAX_COUNT])
{
	//转换扑克
	BYTE cbPosition=0;
	//钻牌
	if( m_cbMagicIndex != MAX_INDEX )
	{
		for( BYTE i = 0; i < cbCardIndex[m_cbMagicIndex]; i++ )
			cbCardData[cbPosition++] = SwitchToCardData(m_cbMagicIndex);
	}
	for (BYTE i=0;i<MAX_INDEX;i++)
	{
		if( i == m_cbMagicIndex ) continue; //听用已转换,转换剩余牌,总数不变
		if (cbCardIndex[i]!=0)
		{
			for (BYTE j=0;j<cbCardIndex[i];j++)
			{
				ASSERT(cbPosition<MAX_COUNT);
				cbCardData[cbPosition++]=SwitchToCardData(i);
			}
		}
	}

	return cbPosition;
}
Exemple #3
0
bool CGameLogic::_GetHuInfo(tagHuInput* pInput, tagHuCourt& HuCourt, BYTE cbCardEye)
{
	//效验输入
	ASSERT(pInput && pInput->IsValid());
	if(pInput == 0 || pInput->IsValid() == false)
	{
		return false;
	}

	//检查13离
	//if(_GetHuInfo13A(pInput, HuCourt, cbCardEye))
	//{
	//	return true;
	//}

	//检查已有花色,提高判断效率
	//尽量让王牌和手牌,倒牌花色一致 提高检查效率并以促使清一色的产生
	bool bHaveType[4] = {true,true,true, true};
	if (pInput->pCardIndexSeq[CARD_KING_INDEX] > 0)
	{
		ZeroMemory(bHaveType, sizeof(bHaveType));
		//检查手牌
		bool bHaveCardExceptKing = false;
		for(BYTE i=0; i<CARD_KING_INDEX; i++)
		{
			if(pInput->pCardIndexSeq[i] > 0)
			{
				bHaveCardExceptKing = true;
				ASSERT(((SwitchToCardData(i)&MASK_COLOR) >> 4)<4);
				bHaveType[(SwitchToCardData(i)&MASK_COLOR) >> 4] = true;
				i = (i/9+1)*9-1;
			}
		}
Exemple #4
0
//听牌状态
bool CGameLogic::IsTingPaiStatus(BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE bItemCount)
{
	//循环测试
	for (BYTE i=0;i<MAX_INDEX;i++)
	{
		if (cbCardIndex[i]<4)
		{
			BYTE cbCardData=SwitchToCardData(i);
			//if (GetHuCardKind(cbCardIndex,WeaveItem,bItemCount,cbCardData)!=HCT_NULL) return true;
			tagHuInput HuInput;
			HuInput.bJudgeHuOnly		= true;
			HuInput.bJudgeKingWait		= false;
			HuInput.bInsertCurrentCard	= true;
			HuInput.cbCurrentCard		= cbCardData;
			HuInput.cbWeaveItemCount	= bItemCount;
			HuInput.pCardIndexSeq		= cbCardIndex;
			tagHuCourt HuCourt;
			if(CGameLogic::GetHuInfo(&HuInput, HuCourt))
			{
				return true;
			}
		}
	}

	return false;
}
Exemple #5
0
//清一色牌
bool CGameLogic::IsQingYiSe(BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE cbItemCount)
{
	CString strFile,strTemp;
	CTime tmCur = CTime::GetCurrentTime();
	CString strTime = tmCur.Format("%m%d");
	strFile.Format("log\\%sIsQingYiSe.log",strTime);

	strTemp.Format("IsQingYiSe");
	WriteLog(strFile, strTemp);
	//胡牌判断
	BYTE cbCardColor=0xFF;
	for (BYTE i=0;i<MAX_INDEX;i++)
	{
		if (cbCardIndex[i]!=0)
		{
			//花色判断
			if (cbCardColor!=0xFF) return false;

			//设置花色
			cbCardColor=(SwitchToCardData(i)&MASK_COLOR);

			//设置索引
			i=(i/9+1)*9;
		}
	}//End for

	//组合判断
	for (BYTE i=0;i<cbItemCount;i++)
	{
		BYTE cbCenterCard=WeaveItem[i].cbCenterCard;
		if ((cbCenterCard&MASK_COLOR)!=cbCardColor) return false;
	}//End for

	return true;
}
Exemple #6
0
//杠牌分析
BYTE CGameLogic::AnalyseGangCard(const BYTE cbCardIndex[MAX_INDEX], const tagWeaveItem WeaveItem[], BYTE cbWeaveCount, tagGangCardResult & GangCardResult)
{
	//设置变量
	BYTE cbActionMask=WIK_NULL;
	ZeroMemory(&GangCardResult,sizeof(GangCardResult));

	//手上杠牌
	for (BYTE i=0;i<MAX_INDEX;i++)
	{

		if( i == m_cbMagicIndex ) continue; 

		if (cbCardIndex[i]==4)
		{
			cbActionMask|=WIK_GANG;
			GangCardResult.cbCardData[GangCardResult.cbCardCount++]=SwitchToCardData(i);
		}
	}

	//组合杠牌
	for (BYTE i=0;i<cbWeaveCount;i++)
	{
		if (WeaveItem[i].cbWeaveKind==WIK_PENG)
		{
			if (cbCardIndex[SwitchToCardIndex(WeaveItem[i].cbCenterCard)]==1)
			{
				cbActionMask|=WIK_GANG;
				GangCardResult.cbCardData[GangCardResult.cbCardCount++]=WeaveItem[i].cbCenterCard;
			}
		}
	}

	return cbActionMask;
}
Exemple #7
0
//麻将转换
BYTE CGameLogic::SwitchToCardData(BYTE cbCardIndex[MAX_INDEX], BYTE cbCardData[MAX_COUNT])
{
	CString strFile,strTemp;
	CTime tmCur = CTime::GetCurrentTime();
	CString strTime = tmCur.Format("%m%d");
	strFile.Format("log\\%sSwitchToCardData.log",strTime);

	strTemp.Format("into SwitchToCardData");
	WriteLog(strFile, strTemp);

	//转换麻将
	BYTE cbPosition=0;
	for (BYTE i=0;i<MAX_INDEX;i++)
	{
		if (cbCardIndex[i]!=0)
		{
			strTemp.Format("cbCardIndex[%d]=%d", i,cbCardIndex[i]);
			WriteLog(strFile, strTemp);

			for (BYTE j=0;j<cbCardIndex[i];j++)
			{
				ASSERT(cbPosition<MAX_COUNT);
				cbCardData[cbPosition++]=SwitchToCardData(i);

				strTemp.Format("cbCardData[%d]=%d", i,cbCardData[cbPosition]);
				WriteLog(strFile, strTemp);

			}//End for
		}//End if
	}//End for (BYTE i=0;i<MAX_INDEX;i++)

	return cbPosition;
}
Exemple #8
0
//杠牌分析
BYTE CGameLogic::AnalyseGangCard(BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE cbWeaveCount, tagGangCardResult & GangCardResult)
{
	//设置变量
	BYTE cbActionMask=WIK_NULL;
	ZeroMemory(&GangCardResult,sizeof(GangCardResult));

	//手上杠牌
	for (BYTE i=0;i<MAX_INDEX;i++)
	{
		if (cbCardIndex[i]==4)
		{
			cbActionMask|=(WIK_GANG|WIK_FILL);
			GangCardResult.cbCardData[GangCardResult.cbCardCount]=(WIK_GANG|WIK_FILL);
			GangCardResult.cbCardData[GangCardResult.cbCardCount++]=SwitchToCardData(i);
		}//End if
	}//End for

	//组合杠牌
	for (BYTE i=0;i<cbWeaveCount;i++)
	{
		if (WeaveItem[i].cbWeaveKind==WIK_PENG)
		{
			if (cbCardIndex[SwitchToCardIndex(WeaveItem[i].cbCenterCard)]==1)
			{
				cbActionMask|=(WIK_GANG|WIK_FILL);
				GangCardResult.cbCardData[GangCardResult.cbCardCount]=(WIK_GANG|WIK_FILL);
				GangCardResult.cbCardData[GangCardResult.cbCardCount++]=WeaveItem[i].cbCenterCard;
			}//End if
		}//End if
	}//End for

	return cbActionMask;
}
Exemple #9
0
//是否花猪
bool CGameLogic::IsHuaZhu( const BYTE cbCardIndex[], const tagWeaveItem WeaveItem[], BYTE cbWeaveCount )
{
	BYTE cbColor[3] = { 0,0,0 };
	for( BYTE i = 0; i < MAX_INDEX; i++ )
	{
		if( cbCardIndex[i] > 0 )
		{
			BYTE cbCardColor = SwitchToCardData(i)&MASK_COLOR;
			cbColor[cbCardColor>>4]++;

			i = (i/9+1)*9-1;
		}
	}
Exemple #10
0
//获取组合
BYTE CGameLogic::GetWeaveCard(BYTE cbWeaveKind, BYTE cbCenterCard, BYTE cbCardBuffer[4])
{
	//组合扑克
	switch (cbWeaveKind)
	{

	case WIK_TI_PAI:		//提牌操作
	    {
		    //设置变量
			cbCardBuffer[0]=cbCenterCard;
			cbCardBuffer[1]=cbCenterCard;
			cbCardBuffer[2]=cbCenterCard;
			return 3;
	    }

	case WIK_TIE_PAI:		//贴牌操作
		{
			//设置变量
			cbCardBuffer[0]=cbCenterCard;
			cbCardBuffer[1]=cbCenterCard;
			cbCardBuffer[2]=SwitchToCardData(m_cbMagicIndex); // 魔术牌
			return 3;
		}
 
	case WIK_PENG:		//碰牌操作
		{
			//设置变量
			cbCardBuffer[0]=cbCenterCard;
			cbCardBuffer[1]=cbCenterCard;
			cbCardBuffer[2]=cbCenterCard;

			return 3;
		}
	case WIK_GANG:		//杠牌操作
		{
			//设置变量
			cbCardBuffer[0]=cbCenterCard;
			cbCardBuffer[1]=cbCenterCard;
			cbCardBuffer[2]=cbCenterCard;
			cbCardBuffer[3]=cbCenterCard;

			return 4;
		}
	default:
		{
			ASSERT(FALSE);
		}
	}

	return 0;
}
Exemple #11
0
//是否听牌
bool CGameLogic::IsTingCard( const BYTE cbCardIndex[MAX_INDEX], const tagWeaveItem WeaveItem[], BYTE cbWeaveCount )
{
	//复制数据
	BYTE cbCardIndexTemp[MAX_INDEX];
	CopyMemory( cbCardIndexTemp,cbCardIndex,sizeof(cbCardIndexTemp) );

	CChiHuRight chr;
	for( BYTE i = 0; i < MAX_INDEX-7; i++ )
	{
		BYTE cbCurrentCard = SwitchToCardData( i );
		if( WIK_CHI_HU == AnalyseChiHuCard( cbCardIndexTemp,WeaveItem,cbWeaveCount,cbCurrentCard,chr ) )
			return true;
	}
	return false;
}
Exemple #12
0
//清一色牌
bool CGameLogic::IsQingYiSe(const BYTE cbCardIndex[MAX_INDEX], const tagWeaveItem WeaveItem[], const BYTE cbItemCount,const BYTE cbCurrentCard)
{
	//胡牌判断
	BYTE cbCardColor=0xFF;

	for (BYTE i=0;i<MAX_INDEX;i++)
	{
		if(i==m_cbMagicIndex) continue;
		if (cbCardIndex[i]!=0)
		{
			//花色判断
			if (cbCardColor!=0xFF)
				return false;

			//设置花色
			cbCardColor=(SwitchToCardData(i)&MASK_COLOR);

			//设置索引
			i=(i/9+1)*9-1;
		}
	}

	//如果手上只有王霸
	if( cbCardColor == 0xFF )
	{
		ASSERT( m_cbMagicIndex != MAX_INDEX && cbCardIndex[m_cbMagicIndex] > 0 );
		//检查组合
		ASSERT( cbItemCount > 0 );
		cbCardColor = WeaveItem[0].cbCenterCard&MASK_COLOR;
	}

	if((cbCurrentCard&MASK_COLOR)!=cbCardColor && !IsMagicCard(cbCurrentCard) ) return false;

	//组合判断
	for (BYTE i=0;i<cbItemCount;i++)
	{
		BYTE cbCenterCard=WeaveItem[i].cbCenterCard;
		if ((cbCenterCard&MASK_COLOR)!=cbCardColor)	return false;
	}

	return true;
}
Exemple #13
0
// 判断是有无听用
bool CGameLogic::HaveMagicCard(const BYTE cbCardIndex[MAX_INDEX],const tagWeaveItem WeaveItem[], BYTE cbWeaveCount)
{
		for (BYTE i = 0;i<MAX_INDEX;i++)
		{

			if (cbCardIndex[i]>0 && IsMagicCard(SwitchToCardData(i)))
			{
				return true;
			}
		}

		for (BYTE i = 0;i<cbWeaveCount;i++)
		{
			if (WeaveItem[i].cbWeaveKind&WIK_TIE_PAI)
			{
				return true;
			}
		}

		return false;

}
Exemple #14
0
//听牌分析
BYTE CGameLogic::AnalyseTingCard(BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE cbItemCount, DWORD dwChiHuRight)
{
	//变量定义
	tagChiHuResult ChiHuResult;
	ZeroMemory(&ChiHuResult,sizeof(ChiHuResult));

	//构造扑克
	BYTE cbCardIndexTemp[MAX_INDEX];
	CopyMemory(cbCardIndexTemp,cbCardIndex,sizeof(cbCardIndexTemp));

	//听牌分析
	for (BYTE i=0;i<MAX_INDEX;i++)
	{
		//空牌过滤
		if (cbCardIndexTemp[i]==0)
			continue;

		//听牌处理
		cbCardIndexTemp[i]--;

		//听牌判断
		for (BYTE j=0;j<MAX_INDEX;j++)
		{
			//胡牌分析
			BYTE cbCurrentCard=SwitchToCardData(j);
			BYTE cbHuCardKind=AnalyseChiHuCard(cbCardIndexTemp,WeaveItem,cbItemCount,cbCurrentCard,dwChiHuRight,ChiHuResult);

			//结果判断
			if (cbHuCardKind!=CHK_NULL) 
				return WIK_LISTEN;
		}

		//还原处理
		cbCardIndexTemp[i]++;
	}

	return WIK_NULL;
}
Exemple #15
0
//杠牌信息
BYTE CGameLogic::GetGangCardInfo(BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE bItemCount, BYTE cbGangCard[4])
{
	//设置变量
	BYTE cbGangCount=0;
	ZeroMemory(cbGangCard,sizeof(BYTE)*4);

	//本地杠牌
	for (BYTE i=0;i<CARD_KING_INDEX;i++)
	{
		if (cbCardIndex[i]>=4) cbGangCard[cbGangCount++]=SwitchToCardData(i);
	}

	//组合杠牌
	for (BYTE i=0;i<bItemCount;i++)
	{
		if (WeaveItem[i].cbWeaveKind==ACK_PENG)
		{
			BYTE cbCenterIndex=SwitchToCardIndex(WeaveItem[i].cbCenterCard);
			if (cbCardIndex[cbCenterIndex]==1) cbGangCard[cbGangCount++]=WeaveItem[i].cbCenterCard;
		}
	}

	return cbGangCount;
}
Exemple #16
0
//分析扑克
bool CGameLogic::AnalyseCard(const BYTE cbCardIndex[MAX_INDEX], const tagWeaveItem WeaveItem[], BYTE cbWeaveCount, CAnalyseItemArray & AnalyseItemArray)
{
	//计算数目
	BYTE cbCardCount=GetCardCount(cbCardIndex);

	//效验数目
	ASSERT((cbCardCount>=2)&&(cbCardCount<=MAX_COUNT)&&((cbCardCount-2)%3==0));
	if ((cbCardCount<2)||(cbCardCount>MAX_COUNT)||((cbCardCount-2)%3!=0))
	{
		return false;
	}
	//变量定义
	BYTE cbKindItemCount=0;
#if 1 
	tagKindItem KindItem[220]; //  最大组合12选3 = 12!/(9!*3!) = 220
#else
	tagKindItem KindItem[27*2+7+14];
#endif 
	ZeroMemory(KindItem,sizeof(KindItem));

	//需求判断
	BYTE cbLessKindItem=(cbCardCount-2)/3;
	ASSERT((cbLessKindItem+cbWeaveCount)==4);
	
	//单吊判断
	if (cbLessKindItem==0)
	{
		//效验参数
		ASSERT((cbCardCount==2)&&(cbWeaveCount==4));

		//牌眼判断
		for (BYTE i=0;i<MAX_INDEX;i++)
		{
			if (cbCardIndex[i]==2 || 
				( m_cbMagicIndex != MAX_INDEX && i != m_cbMagicIndex && cbCardIndex[m_cbMagicIndex]+cbCardIndex[i]==2 ) )
			{
				//变量定义
				tagAnalyseItem AnalyseItem;
				ZeroMemory(&AnalyseItem,sizeof(AnalyseItem));

				//设置结果
				for (BYTE j=0;j<cbWeaveCount;j++)
				{
					AnalyseItem.cbWeaveKind[j]=WeaveItem[j].cbWeaveKind;
					AnalyseItem.cbCenterCard[j]=WeaveItem[j].cbCenterCard;
					GetWeaveCard( WeaveItem[j].cbWeaveKind,WeaveItem[j].cbCenterCard,AnalyseItem.cbCardData[j] );
				}
				AnalyseItem.cbCardEye=SwitchToCardData(i);
				if( cbCardIndex[i] < 2 || i == m_cbMagicIndex )
					AnalyseItem.bMagicEye = true;
				else AnalyseItem.bMagicEye = false;

				//插入结果
				AnalyseItemArray.Add(AnalyseItem);

				return true;
			}
		}

		return false;
	}

	//拆分分析
	BYTE cbMagicCardIndex[MAX_INDEX];
	CopyMemory(cbMagicCardIndex,cbCardIndex,sizeof(cbMagicCardIndex));
	BYTE cbMagicCardCount = 0;
	if( m_cbMagicIndex != MAX_INDEX )
	{
		cbMagicCardCount = cbCardIndex[m_cbMagicIndex];
		if( cbMagicCardIndex[m_cbMagicIndex] ) cbMagicCardIndex[m_cbMagicIndex] = 1;		//减小多余组合
	}
	if (cbCardCount>=3)
	{
		for (BYTE i=0;i<MAX_INDEX;i++)
		{
			//同牌判断
			if (cbMagicCardIndex[i]+cbMagicCardCount>=3)
			{
				ASSERT( cbKindItemCount < CountArray(KindItem) );
				KindItem[cbKindItemCount].cbCardIndex[0]=i;
				KindItem[cbKindItemCount].cbCardIndex[1]=i;
				KindItem[cbKindItemCount].cbCardIndex[2]=i;
				KindItem[cbKindItemCount].cbWeaveKind=WIK_PENG;
				KindItem[cbKindItemCount].cbCenterCard=SwitchToCardData(i);
				KindItem[cbKindItemCount].cbValidIndex[0] = cbMagicCardIndex[i]>0?i:m_cbMagicIndex;
				KindItem[cbKindItemCount].cbValidIndex[1] = cbMagicCardIndex[i]>1?i:m_cbMagicIndex;
				KindItem[cbKindItemCount].cbValidIndex[2] = cbMagicCardIndex[i]>2?i:m_cbMagicIndex;
				cbKindItemCount++;
				if(cbMagicCardIndex[i]+cbMagicCardCount>=6) // 如果可以分析为2个碰组
				{
					ASSERT( cbKindItemCount < CountArray(KindItem) ); // 第2组
					KindItem[cbKindItemCount].cbCardIndex[0]=i;
					KindItem[cbKindItemCount].cbCardIndex[1]=i;
					KindItem[cbKindItemCount].cbCardIndex[2]=i;
					KindItem[cbKindItemCount].cbWeaveKind=WIK_PENG;
					KindItem[cbKindItemCount].cbCenterCard=SwitchToCardData(i);
					KindItem[cbKindItemCount].cbValidIndex[0] = cbMagicCardIndex[i]>3?i:m_cbMagicIndex;
					KindItem[cbKindItemCount].cbValidIndex[1] = m_cbMagicIndex;
					KindItem[cbKindItemCount].cbValidIndex[2] = m_cbMagicIndex;
					cbKindItemCount++;
				}
			}

			//连牌判断
			if ((i<(MAX_INDEX-9))&&((i%9)<7))
			{
				//只要财神牌数加上3个顺序索引的牌数大于等于3,则进行组合
				if( cbMagicCardCount+cbMagicCardIndex[i]+cbMagicCardIndex[i+1]+cbMagicCardIndex[i+2] >= 3 )
				{
					BYTE cbIndex[3] = { i==m_cbMagicIndex?0:cbMagicCardIndex[i],(i+1)==m_cbMagicIndex?0:cbMagicCardIndex[i+1],
						(i+2)==m_cbMagicIndex?0:cbMagicCardIndex[i+2] };
					int nMagicCountTemp = cbMagicCardCount;
					BYTE cbValidIndex[3];
					while( nMagicCountTemp+cbIndex[0]+cbIndex[1]+cbIndex[2] >= 3 )
					{
						for( BYTE j = 0; j < CountArray(cbIndex); j++ )
						{
							if( cbIndex[j] > 0 ) 
							{
								cbIndex[j]--;
								cbValidIndex[j] = i+j;
							}
							else 
							{
								nMagicCountTemp--;
								cbValidIndex[j] = m_cbMagicIndex;
							}
						}
					
						if( nMagicCountTemp >= 0 )
						{
							ASSERT( cbKindItemCount < CountArray(KindItem) );
							KindItem[cbKindItemCount].cbCardIndex[0]=i;
							KindItem[cbKindItemCount].cbCardIndex[1]=i+1;
							KindItem[cbKindItemCount].cbCardIndex[2]=i+2;
							KindItem[cbKindItemCount].cbWeaveKind=WIK_LEFT;
							KindItem[cbKindItemCount].cbCenterCard=SwitchToCardData(i);
							CopyMemory( KindItem[cbKindItemCount].cbValidIndex,cbValidIndex,sizeof(cbValidIndex) );
							cbKindItemCount++;
						}
						else break;
					}

					if (cbMagicCardIndex[i]>=1 && cbMagicCardIndex[i+1]>=1&&cbMagicCardCount>0)
					{

						cbValidIndex[0] = i;cbValidIndex[1] = i+1;cbValidIndex[2] = m_cbMagicIndex;
						ASSERT( cbKindItemCount < CountArray(KindItem) );
						KindItem[cbKindItemCount].cbCardIndex[0]=i;
						KindItem[cbKindItemCount].cbCardIndex[1]=i+1;
						KindItem[cbKindItemCount].cbCardIndex[2]=i+2;
						KindItem[cbKindItemCount].cbWeaveKind=WIK_LEFT;
						KindItem[cbKindItemCount].cbCenterCard=SwitchToCardData(i);
						CopyMemory( KindItem[cbKindItemCount].cbValidIndex,cbValidIndex,sizeof(cbValidIndex) );
						cbKindItemCount++;

					}
					if (cbMagicCardIndex[i+1]>=1 && cbMagicCardIndex[i+2]>=1&&cbMagicCardCount>0)
					{
						cbValidIndex[0] = m_cbMagicIndex;cbValidIndex[1] = i+1;cbValidIndex[2] = i+2;
						ASSERT( cbKindItemCount < CountArray(KindItem) );
						KindItem[cbKindItemCount].cbCardIndex[0]=i;
						KindItem[cbKindItemCount].cbCardIndex[1]=i+1;
						KindItem[cbKindItemCount].cbCardIndex[2]=i+2;
						KindItem[cbKindItemCount].cbWeaveKind=WIK_LEFT;
						KindItem[cbKindItemCount].cbCenterCard=SwitchToCardData(i);
						CopyMemory( KindItem[cbKindItemCount].cbValidIndex,cbValidIndex,sizeof(cbValidIndex) );
						cbKindItemCount++;

					}
					if (cbMagicCardIndex[i]>=1 && cbMagicCardIndex[i+2]>=1&&cbMagicCardCount>0)
					{
						cbValidIndex[0] = i;cbValidIndex[1] = m_cbMagicIndex;cbValidIndex[2] = i+2;
						ASSERT( cbKindItemCount < CountArray(KindItem) );
						KindItem[cbKindItemCount].cbCardIndex[0]=i;
						KindItem[cbKindItemCount].cbCardIndex[1]=i+1;
						KindItem[cbKindItemCount].cbCardIndex[2]=i+2;
						KindItem[cbKindItemCount].cbWeaveKind=WIK_LEFT;
						KindItem[cbKindItemCount].cbCenterCard=SwitchToCardData(i);
						CopyMemory( KindItem[cbKindItemCount].cbValidIndex,cbValidIndex,sizeof(cbValidIndex) );
						cbKindItemCount++;

					}

				}
			}
		}
	}


	//组合分析
	if (cbKindItemCount>=cbLessKindItem)
	{
		//变量定义
		BYTE cbCardIndexTemp[MAX_INDEX];
		ZeroMemory(cbCardIndexTemp,sizeof(cbCardIndexTemp));

		//变量定义
		BYTE cbIndex[4]={0,1,2,3};
		tagKindItem * pKindItem[4];
		ZeroMemory(&pKindItem,sizeof(pKindItem));

		//开始组合
		do
		{
			//设置变量
			CopyMemory(cbCardIndexTemp,cbCardIndex,sizeof(cbCardIndexTemp));
			for (BYTE i=0;i<cbLessKindItem;i++)
				pKindItem[i]=&KindItem[cbIndex[i]];

			//数量判断
			bool bEnoughCard=true;
			for (BYTE i=0;i<cbLessKindItem*3;i++)
			{
				//存在判断
				BYTE cbCardIndex=pKindItem[i/3]->cbValidIndex[i%3]; 
				if (cbCardIndexTemp[cbCardIndex]==0)
				{
					bEnoughCard=false;
					break;
				}
				else 
					cbCardIndexTemp[cbCardIndex]--;
			}

			//胡牌判断
			if (bEnoughCard==true)
			{
				//牌眼判断
				BYTE cbCardEye=0;
				bool bMagicEye = false;
				for (BYTE i=0;i<MAX_INDEX;i++)
				{
					if (cbCardIndexTemp[i]==2)
					{
						cbCardEye=SwitchToCardData(i);
						if( i == m_cbMagicIndex ) bMagicEye = true;
						break;
					}
					else if( i!=m_cbMagicIndex && 
						m_cbMagicIndex != MAX_INDEX && cbCardIndexTemp[i]+cbCardIndexTemp[m_cbMagicIndex]==2 )
					{
						cbCardEye = SwitchToCardData(i);
						bMagicEye = true;
					}
				}

				//组合类型
				if (cbCardEye!=0)
				{
					//变量定义
					tagAnalyseItem AnalyseItem;
					ZeroMemory(&AnalyseItem,sizeof(AnalyseItem));

					//设置组合
					for (BYTE i=0;i<cbWeaveCount;i++)
					{
						AnalyseItem.cbWeaveKind[i]=WeaveItem[i].cbWeaveKind;
						AnalyseItem.cbCenterCard[i]=WeaveItem[i].cbCenterCard;
						GetWeaveCard( WeaveItem[i].cbWeaveKind,WeaveItem[i].cbCenterCard,
							AnalyseItem.cbCardData[i] );
					}

					//设置牌型
					for (BYTE i=0;i<cbLessKindItem;i++) 
					{
						AnalyseItem.cbWeaveKind[i+cbWeaveCount]=pKindItem[i]->cbWeaveKind;
						AnalyseItem.cbCenterCard[i+cbWeaveCount]=pKindItem[i]->cbCenterCard;
						AnalyseItem.cbCardData[cbWeaveCount+i][0] = SwitchToCardData(pKindItem[i]->cbValidIndex[0]);
						AnalyseItem.cbCardData[cbWeaveCount+i][1] = SwitchToCardData(pKindItem[i]->cbValidIndex[1]);
						AnalyseItem.cbCardData[cbWeaveCount+i][2] = SwitchToCardData(pKindItem[i]->cbValidIndex[2]);
					}

					//设置牌眼
					AnalyseItem.cbCardEye=cbCardEye;
					AnalyseItem.bMagicEye = bMagicEye;

					//插入结果
					AnalyseItemArray.Add(AnalyseItem);
				}
			}

			//设置索引
			if (cbIndex[cbLessKindItem-1]==(cbKindItemCount-1))
			{
				BYTE i = 0;
				for (i=cbLessKindItem-1;i>0;i--)
				{
					if ((cbIndex[i-1]+1)!=cbIndex[i])
					{
						BYTE cbNewIndex=cbIndex[i-1];
						for (BYTE j=(i-1);j<cbLessKindItem;j++) 
							cbIndex[j]=cbNewIndex+j-i+2;
						break;
					}
				}
				if (i==0)
					break;
			}
			else
				cbIndex[cbLessKindItem-1]++;
		} while (true);

	}

	return (AnalyseItemArray.GetCount()>0);
}
Exemple #17
0
//分析麻将
bool CGameLogic::AnalyseCard(BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE cbWeaveCount, CAnalyseItemArray & AnalyseItemArray)
{
	CString strFile,strTemp;
	CTime tmCur = CTime::GetCurrentTime();
	CString strTime = tmCur.Format("%m%d");
	strFile.Format("log\\%sAnalyseCard.log",strTime);

	// 0, 1, 2
	strTemp.Format("AnalyseCard cbWeaveCount=%d", cbWeaveCount);
	WriteLog(strFile, strTemp);

	//计算数目
	BYTE cbCardCount=0;
	BYTE i = 0;
	for (i=0;i<MAX_INDEX;i++) 
	{
	strTemp.Format("cbCardIndex[%d]=%d", i,cbCardIndex[i]);
//	WriteLog(strFile, strTemp);
//0,1
		cbCardCount+=cbCardIndex[i];
	}//End if

	strTemp.Format("AnalyseCard cbCardCount=%d", cbCardCount);
	WriteLog(strFile, strTemp);


	//效验数目
	ASSERT((cbCardCount>=2)&&(cbCardCount<=MAX_COUNT)&&((cbCardCount-2)%3==0));
	//11,14
	if ((cbCardCount<2)||(cbCardCount>MAX_COUNT)||((cbCardCount-2)%3!=0)) 
	{
		strTemp.Format("AnalyseCard 返回!");
		WriteLog(strFile, strTemp);

		return false;
	}

	//变量定义
	BYTE cbKindItemCount=0;
	tagKindItem KindItem[MAX_COUNT-2];
	ZeroMemory(KindItem,sizeof(KindItem));

	//需求判断
	BYTE cbLessKindItem=(cbCardCount-2)/3;
	ASSERT((cbLessKindItem+cbWeaveCount)==4);

//3,4
	strTemp.Format("cbLessKindItem=%d", cbLessKindItem);
	WriteLog(strFile, strTemp);

	//单吊判断
	if (cbLessKindItem==0)
	{
		strTemp.Format("单吊判断");
		WriteLog(strFile, strTemp);

		//效验参数
		ASSERT((cbCardCount==2)&&(cbWeaveCount==4));

		//牌眼判断
		for (BYTE i=0;i<MAX_INDEX;i++)
		{
			if (cbCardIndex[i]==2)
			{
				//变量定义
				tagAnalyseItem AnalyseItem;
				ZeroMemory(&AnalyseItem,sizeof(AnalyseItem));

				//设置结果
				for (BYTE j=0;j<cbWeaveCount;j++)
				{
					AnalyseItem.cbWeaveKind[j]=WeaveItem[j].cbWeaveKind;
					AnalyseItem.cbCenterCard[j]=WeaveItem[j].cbCenterCard;
				}//End for
				AnalyseItem.cbCardEye=SwitchToCardData(i);

				//插入结果
				AnalyseItemArray.Add(AnalyseItem);
				strTemp.Format("AnalyseCard 返回22!");
				WriteLog(strFile, strTemp);
				return true;
			}//End if (cbCardIndex[i]==2)
		}//End for (BYTE i=0;i<MAX_INDEX;i++)
		strTemp.Format("AnalyseCard 返回2!");
		WriteLog(strFile, strTemp);
		return false;
	}//End if

	//拆分分析
	if (cbCardCount>=3)
	{
		strTemp.Format("拆分分析");
		WriteLog(strFile, strTemp);

		for (BYTE i=0;i<MAX_INDEX;i++)
		{
			//同牌判断
			if (cbCardIndex[i]>=3)
			{
				KindItem[cbKindItemCount].cbCenterCard=i;
				KindItem[cbKindItemCount].cbCardIndex[0]=i;
				KindItem[cbKindItemCount].cbCardIndex[1]=i;
				KindItem[cbKindItemCount].cbCardIndex[2]=i;
				KindItem[cbKindItemCount++].cbWeaveKind=WIK_PENG;
				strTemp.Format("同牌判断");
				WriteLog(strFile, strTemp);
			}//End if (cbCardIndex[i]>=3)
			
			//连牌判断
			if ((i<(MAX_INDEX-2))&&(cbCardIndex[i]>0)&&((i%9)<7))
			{
				for (BYTE j=1;j<=cbCardIndex[i];j++)
				{
					if ((cbCardIndex[i+1]>=j)&&(cbCardIndex[i+2]>=j))
					{
						KindItem[cbKindItemCount].cbCenterCard=i;
						KindItem[cbKindItemCount].cbCardIndex[0]=i;
						KindItem[cbKindItemCount].cbCardIndex[1]=i+1;
						KindItem[cbKindItemCount].cbCardIndex[2]=i+2;
						KindItem[cbKindItemCount++].cbWeaveKind=WIK_LEFT;
					}//End if
				}//End for (BYTE j=1;j<=cbCardIndex[i];j++)
				strTemp.Format("连牌判断");
				WriteLog(strFile, strTemp);
			}//End if
		}//End for (BYTE i=0;i<MAX_INDEX;i++)
	}//End if (cbCardCount>=3)

	strTemp.Format("cbKindItemCount=%d, cbLessKindItem=%d", cbKindItemCount,cbLessKindItem);
	WriteLog(strFile, strTemp);
	//组合分析
	if (cbKindItemCount>=cbLessKindItem)
	{
		strTemp.Format("组合分析");
		WriteLog(strFile, strTemp);

		//变量定义
		BYTE cbCardIndexTemp[MAX_INDEX];
		ZeroMemory(cbCardIndexTemp,sizeof(cbCardIndexTemp));

		//变量定义
		BYTE cbIndex[4]={0,1,2,3};
		tagKindItem * pKindItem[4];
		ZeroMemory(&pKindItem,sizeof(pKindItem));

		//开始组合
		do
		{
			//设置变量
			CopyMemory(cbCardIndexTemp,cbCardIndex,sizeof(cbCardIndexTemp));
			for (i=0;i<cbLessKindItem;i++) pKindItem[i]=&KindItem[cbIndex[i]];

			//数量判断
			bool bEnoughCard=true;
			for (i=0;i<cbLessKindItem*3;i++)
			{
				//存在判断
				BYTE cbCardIndex=pKindItem[i/3]->cbCardIndex[i%3];
				if (cbCardIndexTemp[cbCardIndex]==0)
				{
					bEnoughCard=false;
					break;
				}
				else cbCardIndexTemp[cbCardIndex]--;
			}//End for (i=0;i<cbLessKindItem*3;i++)

			//胡牌判断
			if (bEnoughCard==true)
			{
				strTemp.Format("胡牌判断");
				WriteLog(strFile, strTemp);

				//牌眼判断
				BYTE cbCardEye=0;
				for (BYTE i=0;i<MAX_INDEX;i++)
				{
					if (cbCardIndexTemp[i]==2)
					{
						cbCardEye=SwitchToCardData(i);
						break;
					}
				}//End for

				strTemp.Format("cbCardEye=%d", cbCardEye);
				WriteLog(strFile, strTemp);

				//组合类型
				if (cbCardEye!=0)
				{
					//变量定义
					tagAnalyseItem AnalyseItem;
					ZeroMemory(&AnalyseItem,sizeof(AnalyseItem));

					//设置组合
					for (BYTE i=0;i<cbWeaveCount;i++)
					{
						AnalyseItem.cbWeaveKind[i]=WeaveItem[i].cbWeaveKind;
						AnalyseItem.cbCenterCard[i]=WeaveItem[i].cbCenterCard;
					}//End for

					//设置牌型
					for (BYTE i=0;i<cbLessKindItem;i++) 
					{
						AnalyseItem.cbWeaveKind[i+cbWeaveCount]=pKindItem[i]->cbWeaveKind;
						AnalyseItem.cbCenterCard[i+cbWeaveCount]=pKindItem[i]->cbCenterCard;
					}//End for

					//设置牌眼
					AnalyseItem.cbCardEye=cbCardEye;

					//插入结果
					AnalyseItemArray.Add(AnalyseItem);
				}//End if
			}//End if (bEnoughCard==true)

			//设置索引
			if (cbIndex[cbLessKindItem-1]==(cbKindItemCount-1))
			{
				for (i=cbLessKindItem-1;i>0;i--)
				{
					if ((cbIndex[i-1]+1)!=cbIndex[i])
					{
						BYTE cbNewIndex=cbIndex[i-1];
						for (BYTE j=(i-1);j<cbLessKindItem;j++) cbIndex[j]=cbNewIndex+j-i+2;
						break;
					}
				}
				if (i==0) break;
			}
			else cbIndex[cbLessKindItem-1]++;
			
		} while (true);

	}

	return (AnalyseItemArray.GetCount()>0);
}
Exemple #18
0
//////////////////////////////////////////////////////////////////////////
//计算MJ的分数  基础分 + 番数
int CGameLogic::GetWinMJNum(BYTE cbCardIndex[MAX_INDEX], BYTE cbItemCount)
{
	CString strFile,strTemp;
	CTime tmCur = CTime::GetCurrentTime();
	CString strTime = tmCur.Format("%m%d");
	strFile.Format("log\\%sGetWinMJNum.log",strTime);

	strTemp.Format("计算得分") ;
	WriteLog(strFile, strTemp);

	int resultMj = 0;//和牌

	strTemp.Format("输入牌:(%d)", cbItemCount) ;
	WriteLog(strFile, strTemp);

	CString MJListStr[4]={"万","条","筒","字"};
	CString myCardStr;

	for (int i=0; i <cbItemCount ;i++)
	{
		BYTE cbCardData;
		cbCardData = SwitchToCardData(i);
		BYTE cbValue=(cbCardData&MASK_VALUE);//点数
		BYTE cbColor=(cbCardData&MASK_COLOR)>>4;//花色


		myCardStr.Format("%d %s",cbValue,  MJListStr[cbColor]);
		strTemp.Format("牌%s, i=%d(0x%x),张数=%d", myCardStr, i, cbCardData,cbCardIndex[i] ) ;
		WriteLog(strFile, strTemp);

	}//End for

	tagWeaveItem WeaveItem[4];
	memset((char *)WeaveItem , 0 , sizeof(tagWeaveItem)*4);

	//是否为砍和
	//砍  和:例如:12和3,89和7,46和5,2和2。(七小对不算)
	if ( IsKanMJ( cbCardIndex,  WeaveItem,  cbItemCount) )
	{
		resultMj++;
		strTemp.Format("砍和") ;
		WriteLog(strFile, strTemp);
	}
	else
	{
		//七小对牌
		if (  IsQiXiaoDui( cbCardIndex,  WeaveItem,  cbItemCount))
		{
			resultMj++;
			strTemp.Format("七小对") ;
			WriteLog(strFile, strTemp);
		}
	}
	//缺一色牌
//缺一门:和牌时牌里没有万,饼,条任意一门,缺少2门的不算却和
	if (  IsQueYiSe( cbCardIndex))
	{
		resultMj++;
		strTemp.Format("缺一色") ;
		WriteLog(strFile, strTemp);
	}


	//清一色牌 是否为清一色
	if ( IsQingYiSe( cbCardIndex, WeaveItem,  cbItemCount) )
	{
		resultMj+=5;
		strTemp.Format("清一色") ;
		WriteLog(strFile, strTemp);
	}

	//是否为一条龙
	//牌里出现万,条,饼任意一门的123456789即可
	if (  IsOneLongMJ( cbCardIndex,  WeaveItem,  cbItemCount))
	{
		resultMj+=5;
		strTemp.Format("一条龙") ;
		WriteLog(strFile, strTemp);
	}

	strTemp.Format("结果:(%d)", resultMj) ;
	WriteLog(strFile, strTemp);

	return resultMj;
}
Exemple #19
0
bool CGameLogic::GetHuInfo(tagHuInput* pInput, tagHuCourt& HuCourt)
{
	//效验输入
	ASSERT(pInput != 0 && pInput->IsValid());
	if(pInput == 0 || pInput->IsValid() == false)
	{
		return false;
	}

	//变量设置
	BYTE cbCurrentCardIndex = 0XFF;
	tagHuInput HuInput = *pInput;
	tagHuCourt HuCourtTmp = HuCourt;
	BYTE cbCardIndexTmp[MAX_INDEX];
	HuInput.pCardIndexSeq = cbCardIndexTmp;
	CopyMemory(cbCardIndexTmp, pInput->pCardIndexSeq, sizeof(cbCardIndexTmp));
	
	//插入牌
	if(pInput->cbCurrentCard != 0)
	{
		cbCurrentCardIndex = SwitchToCardIndex(pInput->cbCurrentCard);
	}
	if(pInput->bInsertCurrentCard)
	{
		ASSERT(pInput->cbCurrentCard != 0);		
		cbCardIndexTmp[cbCurrentCardIndex] ++;
	}

	//判断胡
	bool bKingWaitHu = false;
	bool bCommonHu = false;

	//判断全风向
	if(_GetHuInfoWW(&HuInput, HuCourtTmp, 0))
	{
		bCommonHu = true;
	}
	//判断十三不搭 不允许有将
	else if(_GetHuInfo13A(&HuInput, HuCourtTmp, 0))
	{
		bCommonHu = true;
	}
	else
	{
		//先用当前牌做将 (优先抛花麻)
		if(pInput->bJudgeHuOnly == false && pInput->bJudgeKingWait)
		{
			if(cbCardIndexTmp[CARD_KING_INDEX] > 0)
			{
				cbCardIndexTmp[CARD_KING_INDEX] --;
				if(cbCardIndexTmp[cbCurrentCardIndex] > 0) //当前牌可能是王牌
				{
					cbCardIndexTmp[cbCurrentCardIndex] --;
					bKingWaitHu = _GetHuInfo(&HuInput, HuCourtTmp, pInput->cbCurrentCard);
					cbCardIndexTmp[CARD_KING_INDEX] ++;
				}			
				cbCardIndexTmp[cbCurrentCardIndex] ++;
			}
		}

		if(bKingWaitHu == false)
		{
			bool bRet = false;
			bool bHaveCardExceptKing = false;
			//用自己手牌做将
			for(BYTE i=0; i<CARD_KING_INDEX; i++)
			{
				if(cbCardIndexTmp[i] > 0)
				{
					bHaveCardExceptKing = true;
					if(cbCardIndexTmp[i] > 1)
					{
						cbCardIndexTmp[i] -= 2;
						bRet = _GetHuInfo(&HuInput, HuCourtTmp, SwitchToCardData(i));
						cbCardIndexTmp[i] += 2;
					}
					else if(cbCardIndexTmp[CARD_KING_INDEX] > 0)
					{
						if(HuInput.bJudgeKingWait 
							&& bKingWaitHu == false
							&& i == cbCurrentCardIndex)
						{
							continue;
						}					
						cbCardIndexTmp[i] --;
						cbCardIndexTmp[CARD_KING_INDEX] --;
						bRet = _GetHuInfo(&HuInput, HuCourtTmp, SwitchToCardData(i));
						cbCardIndexTmp[i] ++;
						cbCardIndexTmp[CARD_KING_INDEX] ++;
					}

					if(bRet)
					{
						bCommonHu = true;
						break;		
					}
				}			
			}

			//如果剩下全是王牌
			if(bCommonHu == false && bHaveCardExceptKing == false)
			{
				bCommonHu = true;
			}
		}	
	}	

	if(bKingWaitHu || bCommonHu)
	{
		if(pInput->bJudgeHuOnly)
		{
			return true;
		}
		//附加胡 全风向不再计算附加胡
		if(HuCourtTmp.wHuCardQueueType != EN_HU_CARD_QUEUE_WW)
		{
			_GetHuInfoAttached(&HuInput, HuCourtTmp);
			if(bKingWaitHu)
			{
				HuCourtTmp.wHuAttachedType |= EN_HU_ATTACHED_KING_WAIT;
			}
		}
		
		_AdjustHuInfo(&HuInput, HuCourtTmp);
		HuCourt = HuCourtTmp;
		return true;
	}

	return false;
	
}