牌型的定义在http://blog.csdn.net/csdn_cjt/article/details/78593140 第一章 这是第二章
下面是代码
#region isSelectCardCanPut
public static bool isSelectCardCanPut(List myCards,DDZ_POKER_TYPE myCardType, List lastCards, DDZ_POKER_TYPE lastCardTye)
{
// 我的牌和上家的牌都不能为null
if (myCards == null || lastCards == null)
{
return false;
}
if (myCardType == null || lastCardTye == null)
{
Debug.Log("上家出的牌不合法,所以不能出。");
return false;
}
// 上一首牌的个数
int prevSize = lastCards.Count;
int mySize = myCards.Count;
// 我先出牌,上家没有牌
if (prevSize == 0 && mySize != 0)
{
return true;
}
// 集中判断是否王炸,免得多次判断王炸
if (lastCardTye == DDZ_POKER_TYPE.KingBomb)
{
Debug.Log("上家王炸,肯定不能出。");
return false;
}
else if (myCardType == DDZ_POKER_TYPE.KingBomb)
{
Debug.Log("我王炸,肯定能出。");
return true;
}
// 集中判断对方不是炸弹,我出炸弹的情况
if (lastCardTye != DDZ_POKER_TYPE.FourBomb && myCardType == DDZ_POKER_TYPE.FourBomb)
{
return true;
}
//所有牌提前排序过了
int myGrade = myCards[0];
int prevGrade = lastCards[0];
// 比较2家的牌,主要有2种情况,1.我出和上家一种类型的牌,即对子管对子;
// 2.我出炸弹,此时,和上家的牌的类型可能不同
// 王炸的情况已经排除
// 单
if (lastCardTye == DDZ_POKER_TYPE.Single && myCardType == DDZ_POKER_TYPE.Single)
{
// 一张牌可以大过上家的牌
return compareGrade(myGrade, prevGrade);
}
// 对子
else if (lastCardTye == DDZ_POKER_TYPE.Twin
&& myCardType == DDZ_POKER_TYPE.Twin)
{
// 2张牌可以大过上家的牌
return compareGrade(myGrade, prevGrade);
}
// 3不带
else if (lastCardTye == DDZ_POKER_TYPE.Triple
&& myCardType == DDZ_POKER_TYPE.Triple)
{
// 3张牌可以大过上家的牌
return compareGrade(myGrade, prevGrade);
}
// 炸弹
else if (lastCardTye == DDZ_POKER_TYPE.FourBomb
&& myCardType == DDZ_POKER_TYPE.FourBomb)
{
// 4张牌可以大过上家的牌
return compareGrade(myGrade, prevGrade);
}
// 3带1
else if (lastCardTye == DDZ_POKER_TYPE.TripleWithSingle)
{
// 3带1只需比较第2张牌的大小
myGrade = myCards[1];
prevGrade = lastCards[1];
return compareGrade(myGrade, prevGrade);
}
else if (lastCardTye == DDZ_POKER_TYPE.TripleWithTwin)
{
// 3带2只需比较第3张牌的大小
myGrade = myCards[2];
prevGrade = lastCards[2];
return compareGrade(myGrade, prevGrade);
}
// 4带2
else if (lastCardTye == DDZ_POKER_TYPE.FourWithSingle
&& myCardType == DDZ_POKER_TYPE.FourWithSingle)
{
// 4带2只需比较第3张牌的大小
myGrade = myCards[2];
prevGrade = lastCards[2];
}
// 4带2对子
else if (lastCardTye == DDZ_POKER_TYPE.FourWithSingle
&& myCardType == DDZ_POKER_TYPE.FourWithSingle)
{
myGrade = myCards[2];
prevGrade = lastCards[2];
}
// 顺子
else if (lastCardTye == DDZ_POKER_TYPE.StraightSingle
&& myCardType == DDZ_POKER_TYPE.StraightSingle)
{
if (mySize != prevSize)
{
return false;
}
else
{
// 顺子只需比较最大的1张牌的大小
myGrade = myCards[mySize-1];
prevGrade = lastCards[prevSize - 1];
return compareGrade(myGrade, prevGrade);
}
}
// 连对
else if (lastCardTye == DDZ_POKER_TYPE.StraightTwin
&& myCardType == DDZ_POKER_TYPE.StraightTwin)
{
if (mySize != prevSize)
{
return false;
}
else
{
// 顺子只需比较最大的1张牌的大小
myGrade = myCards[mySize - 1];
prevGrade = lastCards[prevSize - 1];
return compareGrade(myGrade, prevGrade);
}
}
// 飞机不带
else if (lastCardTye == DDZ_POKER_TYPE.PlanePure
&& myCardType == DDZ_POKER_TYPE.PlanePure)
{
if (mySize != prevSize)
{
return false;
}
else
{
//333444555666算飞机不带 不算飞机带单
myGrade = myCards[4];
prevGrade = lastCards[4];
return compareGrade(myGrade, prevGrade);
}
}
//飞机带单
else if (lastCardTye == DDZ_POKER_TYPE.PlaneWithSingle
&& myCardType == DDZ_POKER_TYPE.PlaneWithSingle)
{
if (mySize != prevSize)
{
return false;
}
else
{
List tempThreeList = new List();
for (int i = 0; i < myCards.Count; i++)
{
int tempInt = 0;
for (int j = 0; j < myCards.Count; j++)
{
if (myCards[i] == myCards[j])
{
tempInt++;
}
}
if (tempInt == 3)
{
tempThreeList.Add(myCards[i]);
}
}
myGrade = tempThreeList[4];
prevGrade = lastCards[4];
return compareGrade(myGrade, prevGrade);
}
}
//飞机带双
else if (lastCardTye == DDZ_POKER_TYPE.PlaneWithTwin
&& myCardType == DDZ_POKER_TYPE.PlaneWithTwin)
{
if (mySize != prevSize)
{
return false;
}
else
{
List tempThreeList = new List();
List tempTwoList = new List();
for (int i = 0; i < myCards.Count; i++)
{
int tempInt = 0;
for (int j = 0; j < myCards.Count; j++)
{
if (myCards[i] == myCards[j])
{
tempInt++;
}
}
if (tempInt == 3)
{
tempThreeList.Add(myCards[i]);
}
else if (tempInt == 2)
{
tempTwoList.Add(myCards[i]);
}
}
myGrade = tempThreeList[4];
prevGrade = lastCards[4];
if (compareGrade(myGrade, prevGrade))
{
return DDZCardRule.IsAllDouble(tempTwoList);
}
}
}
// 默认不能出牌
return false;
}
#endregion