Пример #1
0
        public static PokerHandType GetPokerHandType(V1Hand hand)
        {
            var isFlush    = IsFlush(hand);
            var isStraight = IsStraight(hand);

            if (isStraight && isFlush)
            {
                return(hand.Cards.Min(x => x.Rank) == 10 ? PokerHandType.RoyalFlush : PokerHandType.StraightFlush);
            }

            var rankDic         = hand.Cards.GroupBy(x => x.Rank).ToDictionary(x => x.Key, x => x.Count());
            var uniqueRankCount = rankDic.Keys.Count;
            var mostOfRank      = rankDic.Max(x => x.Value);

            if (uniqueRankCount == 2)
            {
                return(mostOfRank == 4 ? PokerHandType.FourOfAKind : PokerHandType.FullHouse);
            }

            if (isFlush)
            {
                return(PokerHandType.Flush);
            }

            if (isStraight)
            {
                return(PokerHandType.Straight);
            }

            if (mostOfRank == 3)
            {
                return(PokerHandType.ThreeOfAKind);
            }

            var pairCount = rankDic.Values.Count(x => x == 2);

            if (pairCount == 2)
            {
                return(PokerHandType.TwoPair);
            }
            else if (pairCount == 1)
            {
                return(PokerHandType.Pair);
            }

            return(PokerHandType.HighCard);
        }
Пример #2
0
 private static bool IsStraight(V1Hand hand)
 {
     return(hand.Cards.Select(x => x.Rank).OrderBy(x => x).IsConsecutive());
 }
Пример #3
0
 private static bool IsFlush(V1Hand hand)
 {
     return(hand.Cards.All(x => x.Suite == hand.Cards[0].Suite));
 }