Пример #1
0
//吃胡分析
BYTE CGameLogic::AnalyseChiHuCard(const BYTE cbCardIndex[MAX_INDEX], const tagWeaveItem WeaveItem[], BYTE cbWeaveCount, BYTE cbCurrentCard, CChiHuRight &ChiHuRight)
{

	//变量定义
	BYTE cbChiHuKind=WIK_NULL;
	CAnalyseItemArray AnalyseItemArray;

	//设置变量
	AnalyseItemArray.RemoveAll();
	ChiHuRight.SetEmpty();

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


	//构造扑克
	BYTE cbCardIndexTemp2[MAX_INDEX];
	ZeroMemory(cbCardIndexTemp2,sizeof(cbCardIndexTemp2));
	m_cbGenCount = 0;
	BYTE cbFanShu = 0;
	CChiHuRight tmpChiHuRight;
	

	//cbCurrentCard一定不为0			!!!!!!!!!
	ASSERT( cbCurrentCard != 0 );
	if( cbCurrentCard == 0 ) return WIK_NULL;

	/*
	//	特殊番型
	*/

	//七小对牌
	if( IsQiXiaoDui(cbCardIndex,WeaveItem,cbWeaveCount,cbCurrentCard) ) 
	{
		ChiHuRight |= CHR_QI_XIAO_DUI;
	}

	if( !ChiHuRight.IsEmpty() )
		cbChiHuKind = WIK_CHI_HU;

	//插入扑克
	if (cbCurrentCard!=0)
		cbCardIndexTemp[SwitchToCardIndex(cbCurrentCard)]++;

	//必须缺一门
	if( IsHuaZhu(cbCardIndexTemp,WeaveItem,cbWeaveCount) )
	{
		return WIK_NULL;
	}



	//胡牌分析
 if((ChiHuRight&CHR_QI_XIAO_DUI).IsEmpty())
 {
		//分析扑克
	AnalyseCard(cbCardIndexTemp,WeaveItem,cbWeaveCount,AnalyseItemArray);
	if (AnalyseItemArray.GetCount()>0)
	{
		cbChiHuKind = WIK_CHI_HU;
	
		//牌型分析
		for (INT_PTR i=0;i<AnalyseItemArray.GetCount();i++)
		{
			//变量定义
			tagAnalyseItem * pAnalyseItem=&AnalyseItemArray[i];


			ZeroMemory(cbCardIndexTemp2,sizeof(cbCardIndexTemp2));
			cbCardIndexTemp2[SwitchToCardIndex(pAnalyseItem->cbCardEye)] = 2;
			BYTE cbTmpFanShu = 0;
			tmpChiHuRight.SetEmpty();
			for (BYTE k =0;k<4;k++)
			{

				if (pAnalyseItem->cbWeaveKind[k] == WIK_LEFT)
				{
					BYTE cbTmpIndex =  SwitchToCardIndex(pAnalyseItem->cbCenterCard[k]);
					for (BYTE t = 0;t < 3;t ++)
					{
						cbCardIndexTemp2[cbTmpIndex]++;
						cbTmpIndex++;
					}
					
				}else if (pAnalyseItem->cbWeaveKind[k] == WIK_PENG || pAnalyseItem->cbWeaveKind[k] == WIK_TIE_PAI)
				{
					BYTE cbTmpIndex =  SwitchToCardIndex(pAnalyseItem->cbCenterCard[k]);
					for (BYTE t = 0;t < 3;t ++)
					{
						cbCardIndexTemp2[cbTmpIndex]++; 
					}
				}else if (pAnalyseItem->cbWeaveKind[k] == WIK_GANG)
				{
					BYTE cbTmpIndex =  SwitchToCardIndex(pAnalyseItem->cbCenterCard[k]);
					for (BYTE t = 0;t < 4;t ++)
					{
						cbCardIndexTemp2[cbTmpIndex]++; 
					}

				}

			}


	//  分析根
		BYTE tmpCount = 0;
		for (BYTE k = 0;k<MAX_INDEX;k++)
		{
			// 分析碰贴牌,在手上牌中查找是否有根
			if (cbCardIndexTemp2[k] == 4)
			{
				tmpCount++;
				cbTmpFanShu++;
			}
	
		}
	
		// 判断是否有3个牌精
		if (HaveThreePaiJin(cbCardIndexTemp2,WeaveItem,cbWeaveCount))
		{
			tmpChiHuRight |= CHR_WITH_THREE_PAI_JIN;
			cbTmpFanShu = (cbTmpFanShu == 0)?2:(cbTmpFanShu+=1);
			
		}


			/*
			//	判断番型
			*/
			//碰碰和
			if( IsPengPeng(pAnalyseItem) ) 
			{
				tmpChiHuRight |= CHR_DA_DUI_ZI;
				cbTmpFanShu+=3;
			}



			if(cbTmpFanShu>cbFanShu)
			{
				cbFanShu = cbTmpFanShu;
				DWORD wRightData =0;
				tmpChiHuRight.GetRightData(&wRightData, MAX_RIGHT_COUNT);
				ChiHuRight.SetRightData(&wRightData, MAX_RIGHT_COUNT);
				m_cbGenCount = tmpCount;

			}
	
#if 0

			//带幺
			if( IsDaiYao(pAnalyseItem) )
				ChiHuRight |= CHR_DAI_YAO;
			//将对
			if( IsJiangDui(pAnalyseItem) )
				ChiHuRight |= CHR_JIANG_DUI;
#endif 
		}
	}
 }
	


	if(!(ChiHuRight&CHR_QI_XIAO_DUI).IsEmpty())
	{
		BYTE cbTingYongCardCount = cbCardIndexTemp[m_cbMagicIndex];
		BYTE cbOneCount = 0,cbThreeCount = 0;

		ChiHuRight &=~CHR_DA_DUI_ZI;
		for(BYTE k = 0;k<MAX_INDEX-7;k++)
		{

			if( k == m_cbMagicIndex ) continue;

			if(cbCardIndexTemp[k] == 4)
			{
				m_cbGenCount++;
			}

			BYTE cbCardCount=cbCardIndexTemp[k];
			if(cbCardCount == 1)
			{
				cbOneCount++; 
			}else if(cbCardCount == 3)
			{
				cbThreeCount++; 
			}


		}


		switch (cbTingYongCardCount)
		{
		case 1:
			if (cbThreeCount == 1)
				m_cbGenCount++;
			break;
		case 2:
			if (cbThreeCount == 2 && cbOneCount == 0)
				m_cbGenCount+=2;
			else if (cbThreeCount == 1 && cbOneCount == 1)
				m_cbGenCount++;

			break;
		case 3:
			if (cbThreeCount == 1 && cbOneCount == 0)
				m_cbGenCount+=2;
			else if (cbThreeCount == 3 && cbOneCount == 0)
				m_cbGenCount+=cbThreeCount;
			else if ( cbThreeCount == 2 && cbOneCount == 1)
				m_cbGenCount+=cbThreeCount;
			else if (cbThreeCount == 1 && cbOneCount == 2)
				m_cbGenCount+=cbThreeCount;

			break;
		case 4:
			if (cbThreeCount == 2 && cbOneCount == 0)
 				m_cbGenCount+=3;
			else if (cbThreeCount == 1 && cbOneCount == 1)
				m_cbGenCount+=2;
			else if ( cbThreeCount == 2 && cbOneCount == 2)
				m_cbGenCount+=cbThreeCount;
			else if (cbThreeCount == 1 && cbOneCount == 3)
				m_cbGenCount+=cbThreeCount;

			break;
		default:
			break;
		}

	}
	

	if( cbChiHuKind == WIK_CHI_HU )
	{
		//清一色牌
		if( IsQingYiSe(cbCardIndex,WeaveItem,cbWeaveCount,cbCurrentCard) )
		{
			ChiHuRight |= CHR_QING_YI_SE;
		}

		if (!HaveMagicCard(cbCardIndex,WeaveItem,cbWeaveCount) && IsMagicCard(cbCurrentCard)==false) // 缺听用
		{
			ChiHuRight |= CHR_WITHOUT_TING_YONG;

		}

		if (IsDaDanDiao(cbCardIndex,cbWeaveCount)) // 大单吊
  	    {
			ChiHuRight |= CHR_DA_DAN_DIAO;
		}



		switch(m_cbGenCount)
		{
			case 1:
				ChiHuRight|= CHR_GENG_COUNT_ONE;
				break;
			case 2:
				ChiHuRight|= CHR_GENG_COUNT_TWO;
				break;
			case 3:
				ChiHuRight|= CHR_GENG_COUNT_THREE;
				break;
			case 4:
				ChiHuRight|= CHR_GENG_COUNT_FOUR;
				break;
						
		}

		//素番
		if( cbChiHuKind == WIK_CHI_HU && ChiHuRight.IsEmpty() )
			ChiHuRight |= CHR_SHU_FAN;

	}

	return cbChiHuKind;
}
Пример #2
0
//吃胡分析
BYTE CGameLogic::AnalyseChiHuCard(const BYTE cbCardIndex[MAX_INDEX], const tagWeaveItem WeaveItem[], BYTE cbWeaveCount, BYTE cbCurrentCard, CChiHuRight &ChiHuRight)
{
	//变量定义
	BYTE cbChiHuKind=WIK_NULL;
	CAnalyseItemArray AnalyseItemArray;

	//设置变量
	AnalyseItemArray.RemoveAll();
	ChiHuRight.SetEmpty();

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

	//cbCurrentCard一定不为0			!!!!!!!!!
	ASSERT( cbCurrentCard != 0 );
	if( cbCurrentCard == 0 ) return WIK_NULL;

	/*
	//	特殊番型
	*/
	//七小对牌
	if( IsQiXiaoDui(cbCardIndex,WeaveItem,cbWeaveCount,cbCurrentCard) ) 
		ChiHuRight |= CHR_QI_XIAO_DUI;

	if( !ChiHuRight.IsEmpty() )
		cbChiHuKind = WIK_CHI_HU;

	//插入扑克
	if (cbCurrentCard!=0)
		cbCardIndexTemp[SwitchToCardIndex(cbCurrentCard)]++;

	//必须缺一门
	if( IsHuaZhu(cbCardIndexTemp,WeaveItem,cbWeaveCount) ) return WIK_NULL;

	//分析扑克
	AnalyseCard(cbCardIndexTemp,WeaveItem,cbWeaveCount,AnalyseItemArray);

	//胡牌分析
	if (AnalyseItemArray.GetCount()>0)
	{
		//
		cbChiHuKind = WIK_CHI_HU;

		//牌型分析
		for (INT_PTR i=0;i<AnalyseItemArray.GetCount();i++)
		{
			//变量定义
			tagAnalyseItem * pAnalyseItem=&AnalyseItemArray[i];

			/*
			//	判断番型
			*/
			//碰碰和
			if( IsPengPeng(pAnalyseItem) ) 
				ChiHuRight |= CHR_DA_DUI_ZI;
			//带幺
			if( IsDaiYao(pAnalyseItem) )
				ChiHuRight |= CHR_DAI_YAO;
			//将对
			if( IsJiangDui(pAnalyseItem) )
				ChiHuRight |= CHR_JIANG_DUI;
		}
	}

	//素番
	if( cbChiHuKind == WIK_CHI_HU && ChiHuRight.IsEmpty() )
		ChiHuRight |= CHR_SHU_FAN;

	if( cbChiHuKind == WIK_CHI_HU )
	{
		//清一色牌
		if( IsQingYiSe(cbCardIndex,WeaveItem,cbWeaveCount,cbCurrentCard) )
			ChiHuRight |= CHR_QING_YI_SE;
	}

	return cbChiHuKind;
}
Пример #3
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;
}
Пример #4
0
//吃胡分析
BYTE CGameLogic::AnalyseChiHuCard(BYTE cbCardIndex[MAX_INDEX], tagWeaveItem WeaveItem[], BYTE cbWeaveCount, BYTE cbCurrentCard, DWORD dwChiHuRight, tagChiHuResult & ChiHuResult)
{
	//变量定义
	DWORD dwChiHuKind=CHK_NULL;
	static CAnalyseItemArray AnalyseItemArray;

	//设置变量
	AnalyseItemArray.RemoveAll();
	ZeroMemory(&ChiHuResult,sizeof(ChiHuResult));

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

	//插入扑克
	if (cbCurrentCard!=0)
		cbCardIndexTemp[SwitchToCardIndex(cbCurrentCard)]++;

	//权位处理
	if ((cbCurrentCard!=0)&&(cbWeaveCount==4))
		dwChiHuRight|=CHK_QUAN_QIU_REN;

	//分析扑克
	AnalyseCard(cbCardIndexTemp,WeaveItem,cbWeaveCount,AnalyseItemArray);

	//胡牌分析
	if (AnalyseItemArray.GetCount()>0)
	{
		//牌型分析
		for (INT_PTR i=0;i<AnalyseItemArray.GetCount();i++)
		{
			//变量定义
			bool bLianCard=false,bPengCard=false;
			tagAnalyseItem * pAnalyseItem=&AnalyseItemArray[i];


			//牌型分析
			for (BYTE j=0;j<CountArray(pAnalyseItem->cbWeaveKind);j++)
			{
				BYTE cbWeaveKind=pAnalyseItem->cbWeaveKind[j];
				bPengCard=((cbWeaveKind&(WIK_GANG|WIK_PENG))!=0)?true:bPengCard;
				bLianCard=((cbWeaveKind&(WIK_LEFT|WIK_CENTER|WIK_RIGHT))!=0)?true:bLianCard;
			}

			//牌型判断
			ASSERT((bLianCard==true)||(bPengCard==true));

			//碰碰牌型
			if ((bLianCard==false)&&(bPengCard==true)) 
				dwChiHuKind|=CHK_PENG_PENG;
			if ((bLianCard==true)&&(bPengCard==true)) 
				dwChiHuKind|=CHK_JI_HU;
			if ((bLianCard==true)&&(bPengCard==false)) 
				dwChiHuKind|=CHK_PING_HU;

		}
	}
	//牌权判断
	if (IsQingYiSe(cbCardIndexTemp,WeaveItem,cbWeaveCount)==true) dwChiHuRight|=CHR_QING_YI_SE;

	//大胡牌型
	if (IsQiXiaoDui(cbCardIndexTemp,WeaveItem,cbWeaveCount)==true) dwChiHuKind|=CHK_QI_XIAO_DUI;
	if (IsShiSanYao(cbCardIndexTemp,WeaveItem,cbWeaveCount)==true) dwChiHuKind|=CHK_SHI_SAN_YAO;

	//结果判断
	if (dwChiHuKind!=CHK_NULL)
	{
		//变量定义
		WORD wGreatHuCount=0;
		DWORD dwGreatKind=dwChiHuKind&CHK_MASK_GREAT;
		DWORD dwGreatRight=dwChiHuRight&CHR_MASK_GREAT;

		//番数统计
		for (BYTE i=0;i<32;i++) 
		{
			//设置变量
			dwGreatKind>>=1;
			dwGreatRight>>=1;

			//结果判断
			if ((dwGreatKind&0x00000001)!=0) wGreatHuCount++;
			if ((dwGreatRight&0x00000001)!=0) wGreatHuCount++;
		}

		//设置牌型
		ChiHuResult.dwChiHuKind=dwChiHuKind;
		ChiHuResult.dwChiHuRight=dwChiHuRight;

		//设置番数
		if (wGreatHuCount==0) ChiHuResult.dwWinTimes=1;
		else if (wGreatHuCount>=1) ChiHuResult.dwWinTimes=2;

		return WIK_CHI_HU;
		return WIK_CHI_HU;
	}