예제 #1
0
        public WinningHand CompareHands(IHand firstHand, IHand secondHand)
        {
            var          handStrengthRecognizer = new HandStrengthRecognizer();
            HandStrength firstHandStrenght      = handStrengthRecognizer.RecognizeHandStrength(firstHand);
            HandStrength secondHandStrength     = handStrengthRecognizer.RecognizeHandStrength(secondHand);

            if (firstHandStrenght == secondHandStrength)
            {
                switch (firstHandStrenght)
                {
                case HandStrength.HighCard:
                {
                    return(this.FindWinningHandByKickers(firstHand.Cards.ToList(), secondHand.Cards.ToList()));
                }

                case HandStrength.OnePair:
                {
                    return(this.CompareOnePairHands(firstHand, secondHand));
                }

                case HandStrength.TwoPairs:
                {
                    return(this.CompareTwoPairsHands(firstHand, secondHand));
                }

                case HandStrength.ThreeOfAKind:
                {
                    return(this.CompareThreeOfAKindHands(firstHand, secondHand));
                }

                case HandStrength.Straight:
                {
                    return(this.CompareStraightHands(firstHand, secondHand));
                }

                case HandStrength.Flush:
                {
                    return(this.CompareFlushHands(firstHand, secondHand));
                }

                case HandStrength.FullHouse:
                {
                    return(this.CompareFullHouseHands(firstHand, secondHand));
                }

                case HandStrength.FourOfAKind:
                {
                    return(this.CompareFourOfAKindHands(firstHand, secondHand));
                }

                case HandStrength.StraightFlush:
                {
                    return(this.CompareStraightFlushHands(firstHand, secondHand));
                }

                default:
                {
                    throw new ArgumentException("Invalid hand strength!");
                }
                }
            }

            return(firstHandStrenght > secondHandStrength ? WinningHand.FirstHandWins : WinningHand.SeconHandWins);
        }
        public WinningHand CompareHands(IHand firstHand, IHand secondHand)
        {
            var handStrengthRecognizer = new HandStrengthRecognizer();
            HandStrength firstHandStrenght = handStrengthRecognizer.RecognizeHandStrength(firstHand);
            HandStrength secondHandStrength = handStrengthRecognizer.RecognizeHandStrength(secondHand);

            if (firstHandStrenght == secondHandStrength)
            {
                switch (firstHandStrenght)
                {
                    case HandStrength.HighCard:
                        {
                            return this.FindWinningHandByKickers(firstHand.Cards.ToList(), secondHand.Cards.ToList());
                        }

                    case HandStrength.OnePair:
                        {
                            return this.CompareOnePairHands(firstHand, secondHand);
                        }

                    case HandStrength.TwoPairs:
                        {
                            return this.CompareTwoPairsHands(firstHand, secondHand);
                        }

                    case HandStrength.ThreeOfAKind:
                        {
                            return this.CompareThreeOfAKindHands(firstHand, secondHand);
                        }

                    case HandStrength.Straight:
                        {
                            return this.CompareStraightHands(firstHand, secondHand);
                        }

                    case HandStrength.Flush:
                        {
                            return this.CompareFlushHands(firstHand, secondHand);
                        }

                    case HandStrength.FullHouse:
                        {
                            return this.CompareFullHouseHands(firstHand, secondHand);
                        }

                    case HandStrength.FourOfAKind:
                        {
                            return this.CompareFourOfAKindHands(firstHand, secondHand);
                        }

                    case HandStrength.StraightFlush:
                        {
                            return this.CompareStraightFlushHands(firstHand, secondHand);
                        }

                    default:
                        {
                            throw new ArgumentException("Invalid hand strength!");
                        }
                }
            }

            return firstHandStrenght > secondHandStrength ? WinningHand.FirstHandWins : WinningHand.SeconHandWins;
        }