/// <summary> /// 检查顺子 /// </summary> /// <param name="cards">排序后的原始牌</param> /// <param name="kingCount">癞子数量</param> /// <param name="handCards">比较牌</param> /// <returns></returns> public static bool CheckStraight(List<int> cards, int kingCount, out List<int> handCards) { handCards = new List<int>(); var cards2 = cards.Take(cards.Count - kingCount).ToList(); for (int i = 0; i < cards2.Count; i++) { var pre = cards2[i]; handCards.Add(pre); if (i == cards2.Count - 1) { break; } var cur = cards2[i + 1]; var interval = (cur%100) - (pre%100); if (interval == 1) { continue; } else if(interval>1&&kingCount > 0) { pre = pre % 100; while (interval > 1) { if (kingCount<=0) { return false; } kingCount--; pre++; handCards.Add(pre); interval--; } } else { return false; } } if (kingCount>0) { var first = handCards.First(); var last=handCards.Last(); while (14-(last%100)>0&&kingCount>0)//先从后面补 { var newlast = (last % 100) + 1; handCards.Add(newlast); kingCount--; last = newlast; } if (kingCount > 0)//最后从前面补 { while ((first%100)-2>0&&kingCount>0) { var newfirst = (first % 100) - 1; handCards.Insert(0, newfirst); kingCount--; first = newfirst; } } } handCards.Reverse(); return true; }
例如:110,212,113,癞子,癞子
110%100 表示10
110/100 表示花色,方块