/// <summary>
/// 出牌的类型 过1,单张1,对子2,三张3,三带单4,三带对5,单顺6,双顺7,飞机8,飞机带单9,飞机带双10,四带两单11,四带对12,炸弹13,火箭14
/// </summary>
public enum SHOW_CARDS_TYPE
{
/// <summary>
/// 过,不出牌
/// </summary>
DDZ_PASS = 0,
/// <summary>
/// 单张
/// </summary>
SINGLE = 1,
/// <summary>
/// 对子
/// </summary>
TWIN = 2,
/// <summary>
/// 三张
/// </summary>
TRIPLE = 3,
/// <summary>
/// 三带单
/// </summary>
TRIPLE_WITH_SINGLE = 4,
/// <summary>
/// 三带对
/// </summary>
TRIPLE_WITH_TWIN = 5,
/// <summary>
/// 单顺
/// </summary>
STRAIGHT_SINGLE = 6,
/// <summary>
/// 双顺
/// </summary>
STRAIGHT_TWIN = 7,
/// <summary>
/// 飞机
/// </summary>
PLANE_PURE = 8,
/// <summary>
/// 飞机带单
/// </summary>
PLANE_WITH_SINGLE = 9,
/// <summary>
/// 飞机带双
/// </summary>
PLANE_WITH_TWIN = 10,
/// <summary>
/// 四带两单
/// </summary>
FOUR_WITH_SINGLE = 11,
/// <summary>
/// 四带对
/// </summary>
FOUR_WITH_TWIN = 12,
/// <summary>
/// 炸弹
/// </summary>
FOUR_BOMB = 13,
/// <summary>
/// 火箭
/// </summary>
KING_BOMB = 14,
}
然后写判断牌型的代码
这里的cardsList是要出的牌的链表
public static SHOW_CARDS_TYPE DcCardsTypeToList(List<CardData> cardsList )
通过链表进行判断,返回判断类型,不能出就返回 (过)得牌型
public static SHOW_CARDS_TYPE DcCardsTypeToList(List<CardData> cardsList )
{
//如果牌数为单
if (cardsList.Count==1)
{
//返回单排类型
return SHOW_CARDS_TYPE.SINGLE;
}
//如果排数为双
if (cardsList.Count==2)
{
//如果是对子
if (cardsList[0].size==cardsList[1].size)
{
//返回对子类型
return SHOW_CARDS_TYPE.TWIN;
}
if (cardsList[0].cardsType==4 && cardsList[1].cardsType==5 || cardsList[0].cardsType == 5 && cardsList[1].cardsType == 4)
{
//返回王炸(火箭);
return SHOW_CARDS_TYPE.KING_BOMB;
}
}
//如果排数是三张
if (cardsList.Count==3)
{
if (cardsList[0].size==cardsList[1].size && cardsList[1].size==cardsList[2].size)
{
return SHOW_CARDS_TYPE.TRIPLE;
}
}
//如果牌数是四张
if (cardsList.Count==4)
{
//创建数组,接收各个牌的值
int[] cardsSize = new int[4];
int num=0;//监听数组里数字的重复字数
cardsSize[0] = cardsList[0].size;
cardsSize[1] = cardsList[1].size;
cardsSize[2] = cardsList[2].size;
cardsSize[3] = cardsList[3].size;
foreach (var s in cardsSize.GroupBy(c => c))
{
if (s.Count() != 1)
{
num += s.Count();
}
}
//首先判断是不是炸弹;
if ((cardsSize[0]==cardsSize[1]) && (cardsSize[1]==cardsSize[2]) && (cardsSize[3] == cardsSize[0]))
{
return SHOW_CARDS_TYPE.FOUR_BOMB;
}
//有三个数字重复
else if (num==3)
{
return SHOW_CARDS_TYPE.TRIPLE_WITH_SINGLE;
}
}
//如果牌数是5张
if (cardsList.Count==5)
{
int[] sizeArray = new int[cardsList.Count];//接收要出的牌的值
int num = 0;//监听重复的牌的次数
for (int i = 0; i < cardsList.Count; i++)
{
//添加到数组中
sizeArray[i] = cardsList[i].size;
}
//判断是不是三带对
//找出数组中重复的元素次数
foreach (var s in sizeArray.GroupBy(c=>c))
{
if (s.Count()!=1)
{
num += s.Count();
}
}
if (num==5)
{
return SHOW_CARDS_TYPE.TRIPLE_WITH_TWIN; //三带对
}
//判断是不是顺子
Array.Sort(sizeArray);//让数组里的数据从小到大排序
for (int i = 0; i < sizeArray.Length-1; i++)
{
if (sizeArray[i]!=sizeArray[i+1]-1)
{
return SHOW_CARDS_TYPE.DDZ_PASS;
}
}
return SHOW_CARDS_TYPE.STRAIGHT_SINGLE;
}
//如果牌数等于6张
if (cardsList.Count==6)
{
int[] sizeArray = new int[cardsList.Count];//接收要出的牌的值
int num = 0;//监听三张一样的牌的次数
int oneTime = 0;//监听单排出现次数
int fourTime = 0;//监听是否有4张一样的数字
int twoTime = 0;//监听出现过两个相同的数字的次数
for (int i = 0; i < cardsList.Count; i++)
{
//添加到数组中
sizeArray[i] = cardsList[i].size;
}
//判断是不是飞机
//找出数组中重复有几个牌重复出现
foreach (var s in sizeArray.GroupBy(c => c))
{
if (s.Count()==1)
{
oneTime += 1;
}
if (s.Count()==2)
{
twoTime += 1;
}
if (s.Count() ==3)
{
num += 1;
}
if (s.Count()==4)
{
fourTime += 1;
}
}
Array.Sort(sizeArray);//给数组排序
if (num == 2 && sizeArray[2] == sizeArray[3] - 1)
{
return SHOW_CARDS_TYPE.PLANE_PURE;
}
if (fourTime==1)
{
if (twoTime==1)
{
return SHOW_CARDS_TYPE.FOUR_WITH_TWIN;
}
else
{
return SHOW_CARDS_TYPE.FOUR_WITH_SINGLE;
}
}
if (twoTime==3)
{
//判断是不是双顺
for (int i = 0; i < sizeArray.Length-2; i++)
{
if (sizeArray[i] != sizeArray[i + 2] - 1)
{
return SHOW_CARDS_TYPE.DDZ_PASS;
}
}
return SHOW_CARDS_TYPE.STRAIGHT_TWIN;
}
if (oneTime==cardsList.Count)
{
//判断是不是单顺
for (int i = 0; i < sizeArray.Length-1; i++)
{
if (sizeArray[i] != sizeArray[i + 1] - 1)
{
return SHOW_CARDS_TYPE.DDZ_PASS;
}
}
return SHOW_CARDS_TYPE.STRAIGHT_SINGLE;
}
}
//如果牌数大于6张
if (cardsList.Count>6)
{
int[] sizeArray = new int[cardsList.Count];//接收要出的牌的值
int threeTime = 0;//监三张一样的牌出现的次数
int oneTime = 0;//监听单张出现次数
int twoTime = 0;//监听出现过两个相同的牌的次数
for (int i = 0; i < cardsList.Count; i++)
{
//添加到数组中
sizeArray[i] = cardsList[i].size;
}
//判断是不是飞机
//找出数组中重复有几个数重复三次出现
foreach (var s in sizeArray.GroupBy(c => c))
{
if (s.Count()==1)
{
oneTime += 1;
}
if (s.Count() == 2)
{
twoTime += 1;
}
if (s.Count() == 3)
{
threeTime += 1;
}
}
Array.Sort(sizeArray);//从小到大排序
if (oneTime == cardsList.Count)
{
//判断是不是单顺
for (int i = 0; i < sizeArray.Length-1; i++)
{
if (sizeArray[i] != sizeArray[i + 1] - 1)
{
return SHOW_CARDS_TYPE.DDZ_PASS;
}
}
return SHOW_CARDS_TYPE.STRAIGHT_SINGLE;
}
if (cardsList.Count%2==0)//链表长度是偶数
{
if (twoTime >=3)
{
//判断是不是双顺
for (int i = 0; i < sizeArray.Length-2; i++)
{
if (sizeArray[i] != sizeArray[i + 2] - 1)
{
return SHOW_CARDS_TYPE.DDZ_PASS;
}
}
return SHOW_CARDS_TYPE.STRAIGHT_TWIN;
}
}
if (threeTime>1)//判断是不是飞机
{
if (threeTime==twoTime)//飞机带双
{
return SHOW_CARDS_TYPE.PLANE_WITH_TWIN;
}
if (threeTime==oneTime)//飞机带单
{
return SHOW_CARDS_TYPE.PLANE_WITH_SINGLE;
}
}
}
return SHOW_CARDS_TYPE.DDZ_PASS;
}