/// <summary> /// 检测牌型 /// </summary> /// <param name="cards">牌</param> /// <param name="line">第几行</param> /// <returns></returns> public CardType CheckCardType(List <int> cards, int line) { //除去可能产生的不必要的信息 cards = cards.GetRange(0, line == 0 ? 3 : 5); //检测牌型 bool isTongHua = line != 0; bool isShunZi = line != 0; int samecount = 1; List <int> sameNumList = new List <int>(); Resort(cards); int color = Help1.GetColor(cards[0]); int value = Help1.GetValue(cards[0]); for (int i = 1; i < cards.Count; i++) { int card = cards[i]; if (card == 0) { continue; } int cardColor = Help1.GetColor(card); int cardValue = Help1.GetValue(card); if (cardColor != color) { isTongHua = false; } if (cardValue - value != 1) { isShunZi = false; } if (cardValue == value) { samecount++; } else { if (samecount > 0) { sameNumList.Add(samecount); samecount = 1; } } value = cardValue; } sameNumList.Add(samecount); if (line == 0) { if (sameNumList.Count == 2) { return(CardType.yidui); } if (sameNumList.Count == 1) { return(CardType.santiao); } return(CardType.sanpai); } if (isTongHua && isShunZi) { return(CardType.tonghuashun); } if (isShunZi) { return(CardType.shunzi); } if (isTongHua) { return(CardType.tonghua); } if (sameNumList.Count > 0) { if (sameNumList.Count == 1) { samecount = sameNumList[0]; if (samecount == 2) { return(CardType.yidui); } else if (samecount == 3) { return(CardType.santiao); } else if (samecount == 4) { return(CardType.tiezhi); } } else if (sameNumList.Count == 2) { samecount = sameNumList[0]; int samecount1 = sameNumList[1]; if ((samecount == 2 && samecount1 == 3) || (samecount == 3 && samecount1 == 2)) { return(CardType.hulu); } else if (samecount == 4 || samecount1 == 4) { return(CardType.tiezhi); } } else if (sameNumList.Count == 3) { if (sameNumList.Any(item => item == 3)) { return(CardType.santiao); } return(CardType.liangdui); } else if (sameNumList.Count == 4) { return(CardType.yidui); } } return(CardType.sanpai); }
/// <summary> /// 根据牌面值对列表进行排序 /// </summary> /// <param name="list">要排序的牌列表</param> /// <param name="mode">1为升序,-1为降序,默认升序</param> void Resort(List <int> list, int mode = 1) { list.Sort((x, y) => mode * Help1.GetValue(x).CompareTo(Help1.GetValue(y))); }