示例#1
0
        private static bool Pair(Hand hand, Hand bestHand)
        {
            if (hand.Count < 2)
            {
                return(false);
            }

            //see if there are 2 lots of exactly 2 cards card the same rank.
            var groups  = hand.GroupBy(card => card.Value);
            var pairs   = groups.Where(group => group.Count() == 2);
            var hasPair = pairs.Any();

            //	High-ify any Aces
            foreach (var grouping in pairs)
            {
                if (grouping.Key == 1)
                {
                    grouping.ToList().ForEach(c => c.Value = 14);
                }
            }
            var orderedPairs = pairs.OrderByDescending(p => p.Key);
            var highestPairs = orderedPairs.Take(1);             //.SelectMany<Card>(c => c.GetEnumerator().Current);
            var bestCards    = highestPairs.SelectMany(g => g.Take(g.Count()));

            bestHand.Clear();
            bestHand.AddRange(bestCards);

            return(hasPair);
        }
示例#2
0
        protected bool HasAtLeastOfAKind(Hand hand, int number)
        {
            int maxOfAKind = hand
                             .GroupBy(card => card.Rank)
                             .Select(group => group.Count())
                             .Max();

            return(maxOfAKind >= number);
        }
示例#3
0
 public override HandEvaluation Evaluate(Hand hand)
 {
     if (hand.GroupBy(card => card.Rank).Count() == 2 &&
         hand.First().Rank != hand.Last().Rank)
     {
         return(HandEvaluation.FullHouse);
     }
     else
     {
         return(_next.Evaluate(hand));
     }
 }
示例#4
0
 public override HandEvaluation Evaluate(Hand hand)
 {
     if (hand.GroupBy(card => card.Rank)
         .Where(group => group.Count() >= 2)
         .Count()
         >= 2)
     {
         return(HandEvaluation.TwoPairs);
     }
     else
     {
         return(_next.Evaluate(hand));
     }
 }
示例#5
0
        public override HandEvaluation Evaluate(Hand hand)
        {
            var rankGroups = hand
                             .GroupBy(card => card.Rank)
            ;

            if (rankGroups.Count() == 2 &&
                rankGroups.All(g => g.Count() >= 2)
                )
            {
                return(HandEvaluation.FullHouse);
            }
            else
            {
                return(_next.Evaluate(hand));
            }
        }
示例#6
0
        private static bool FourOfAKind(Hand hand, Hand bestHand)
        {
            if (hand.Count < 4)
            {
                return(false);
            }

            //see if exactly 4 cards card the same rank.
            var groups         = hand.GroupBy(card => card.Value);
            var fours          = groups.Where(group => group.Count() == 4);
            var hasFourOfAKind = fours.Any();

            var orderedFours = fours.OrderByDescending(p => p.Key);
            var highestFours = orderedFours.Take(1);
            var bestCards    = highestFours.SelectMany(g => g.Take(g.Count()));

            bestHand.Clear();
            bestHand.AddRange(bestCards);

            return(hasFourOfAKind);
        }
示例#7
0
 protected bool HasFlush(Hand hand) =>
 hand.GroupBy(card => card.Suit)
 .Count()
 == 1;
示例#8
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);
        }