示例#1
0
        public HandType Eval() //returns the hands value and type
        {
            HandType handType;

            if (IsRoyalStraightFlush)
            {
                handType = HandType.RoyalStraightFlush;
            }
            else if (IsStraightFlush)
            {
                handType = HandType.StraightFlush;
            }
            else if (IsFourOfAKind)
            {
                handType = HandType.FourOfAKind;
            }
            else if (IsFullHouse)
            {
                handType = HandType.FullHouse;
            }
            else if (IsFlush)
            {
                handType = HandType.Flush;
            }
            else if (IsStraight)
            {
                handType = HandType.Straight;
            }
            else if (IsThreeOfAKind)
            {
                handType = HandType.ThreeOfAKind;
            }
            else if (IsTwoPair)
            {
                handType = HandType.TwoPairs;
            }
            else if (IsPair)
            {
                handType = HandType.Pair;
            }
            else
            {
                handType = HandType.HighCard;
            }

            CardRank = Hand.Select(card => card.Rank)
                       .OrderBy(r => r).ToList();

            if (handType == HandType.Pair || handType == HandType.TwoPairs)
            {
                DuplicateRank = Hand.GroupBy(card => card.Rank)
                                .Where(group => group.Count() == 2)
                                .Select(group => group.Key)
                                .OrderByDescending(x => x).ToList();
            }
            if (handType == HandType.ThreeOfAKind || handType == HandType.FullHouse)
            {
                ThreeDuplicateRank = Hand.GroupBy(card => card.Rank)
                                     .Where(group => group.Count() == 3)
                                     .Select(group => group.Key)
                                     .OrderByDescending(x => x).ToList();
            }
            if (handType == HandType.FourOfAKind)
            {
                FourDuplicateRank = Hand.GroupBy(card => card.Rank)
                                    .Where(group => group.Count() == 4)
                                    .Select(group => group.Key)
                                    .OrderByDescending(x => x).ToList();
            }
            HandType = handType;
            return(handType);
        }
示例#2
0
 protected bool HasStraight(Hand hand) =>
 hand.Select(c => c.Rank).Distinct().Count() == 5 &&
 hand.Last().Rank - hand.First().Rank == 4;