Example #1
0
        /// <summary>
        /// Compares the full houses.
        /// </summary>
        /// <param name="currentWinners">The current winners.</param>
        /// <param name="challenger">The challenger.</param>
        /// <returns>List&lt;PokerHandDto&gt;.</returns>
        private List <PokerHandDto> CompareTwoPairs(List <PokerHandDto> currentWinners, PokerHandDto challenger)
        {
            //Card Freq list to query
            //Hand 1
            List <Card>          winnersCards        = GetCardListFromHand(currentWinners[0]);
            List <CardFrequency> winnersCardRankList = new CardFrequencyList().GetCardFrequencyList(winnersCards);
            //Hand 2
            List <Card>          challengerCards        = GetCardListFromHand(challenger);
            List <CardFrequency> challengerCardRankList = new CardFrequencyList().GetCardFrequencyList(challengerCards);

            var winnersTwoPairs    = winnersCardRankList.Where(cr => cr.Frequency == 2).OrderByDescending(c => c.Rank).ToList();
            var challengerTwoPairs = challengerCardRankList.Where(cr => cr.Frequency == 2).OrderByDescending(c => c.Rank).ToList();

            int i = 0;

            while (i < 2)
            {
                if (winnersTwoPairs[i].Rank > challengerTwoPairs[i].Rank)
                {
                    return(currentWinners);
                }
                else if (winnersTwoPairs[i].Rank < challengerTwoPairs[i].Rank)
                {
                    return(new List <PokerHandDto> {
                        challenger
                    });
                }
                i++;
            }

            //Would only be possible to get here in multi deck games. One full house should always be stronger with one deck.
            int winnersKickRank      = winnersCardRankList.Where(cr => cr.Frequency == 1).FirstOrDefault().Rank;
            int challengerKickerRank = challengerCardRankList.Where(cr => cr.Frequency == 1).FirstOrDefault().Rank;

            //compare the strength of pairs
            if (winnersKickRank > challengerKickerRank)
            {
                return(currentWinners);
            }
            else if (winnersKickRank < challengerKickerRank)
            {
                return(new List <PokerHandDto> {
                    challenger
                });
            }

            //hands are the same in terms of rank. Pot will be chopped.
            currentWinners.Add(challenger);
            return(currentWinners);
        }
Example #2
0
        /// <summary>
        /// Compares the rank repated hand. (Pair, trips, quads)
        /// </summary>
        /// <param name="currentWinners">The current winners.</param>
        /// <param name="challenger">The challenger.</param>
        /// <param name="numberOfRankRepeats">The number of rank repeats.</param>
        /// <returns>List&lt;PokerHandDto&gt;.</returns>
        private List <PokerHandDto> CompareRankRepatedHand(List <PokerHandDto> currentWinners, PokerHandDto challenger, int numberOfRankRepeats)
        {
            //Card Freq list to query
            //Hand 1
            List <Card>          currentWinnersCards        = GetCardListFromHand(currentWinners[0]);
            List <CardFrequency> currentWinnersCardRankList = new CardFrequencyList().GetCardFrequencyList(currentWinnersCards);
            //Hand 2
            List <Card>          challengersCards        = GetCardListFromHand(challenger);
            List <CardFrequency> challengerscardRankList = new CardFrequencyList().GetCardFrequencyList(challengersCards);

            int currentWinnerscardRank = currentWinnersCardRankList.Where(cr => cr.Frequency == numberOfRankRepeats).FirstOrDefault().Rank;
            int challengerscardRank    = challengerscardRankList.Where(cr => cr.Frequency == numberOfRankRepeats).FirstOrDefault().Rank;

            //compare the strength of trips
            if (currentWinnerscardRank > challengerscardRank)
            {
                return(currentWinners);
            }
            else if (currentWinnerscardRank < challengerscardRank)
            {
                return(new List <PokerHandDto> {
                    challenger
                });
            }

            //repeated rank cards are the same only possible to get here for duos
            var kickers1 = currentWinnersCardRankList.Where(cr => cr.Frequency == 1).OrderByDescending(c => c.Rank).ToList();
            var kickers2 = challengerscardRankList.Where(cr => cr.Frequency == 1).OrderByDescending(c => c.Rank).ToList();

            //repeated cards are the same so kickers will be examined
            for (int i = 0; i < kickers1.Count; i++)
            {
                if (kickers1[i].Rank > kickers2[i].Rank)
                {
                    return(currentWinners);
                }
                else if (kickers1[i].Rank < kickers2[i].Rank)
                {
                    return(new List <PokerHandDto> {
                        challenger
                    });
                }
            }

            //hands are the same in terms of rank. Pot will be chopped.
            currentWinners.Add(challenger);
            return(currentWinners);
        }
Example #3
0
        /// <summary>
        /// Compares the full houses.
        /// </summary>
        /// <param name="currentWinners">The current winners.</param>
        /// <param name="challenger">The challenger.</param>
        /// <returns>List&lt;PokerHandDto&gt;.</returns>
        private List <PokerHandDto> CompareFullHouse(List <PokerHandDto> currentWinners, PokerHandDto challenger)
        {
            //Card Freq list to query
            //Hand 1
            List <Card>          cards1        = GetCardListFromHand(currentWinners[0]);
            List <CardFrequency> cardRankList1 = new CardFrequencyList().GetCardFrequencyList(cards1);
            //Hand 2
            List <Card>          cards2        = GetCardListFromHand(challenger);
            List <CardFrequency> cardRankList2 = new CardFrequencyList().GetCardFrequencyList(cards2);

            int currentWinnersTripsRank = cardRankList1.Where(cr => cr.Frequency == 3).FirstOrDefault().Rank;
            int challengerTripsRank     = cardRankList2.Where(cr => cr.Frequency == 3).FirstOrDefault().Rank;

            if (currentWinnersTripsRank > challengerTripsRank)
            {
                return(currentWinners);
            }
            else if (currentWinnersTripsRank < challengerTripsRank)
            {
                return(new List <PokerHandDto> {
                    challenger
                });
            }

            //Would only be possible to get here in multi deck games. One full house should always be stronger with one deck.
            int currentWinnersPairRank = cardRankList1.Where(cr => cr.Frequency == 2).FirstOrDefault().Rank;
            int challengerPairRank     = cardRankList1.Where(cr => cr.Frequency == 2).FirstOrDefault().Rank;

            //compare the strength of pairs
            if (currentWinnersPairRank > challengerPairRank)
            {
                return(currentWinners);
            }
            else if (currentWinnersPairRank < challengerPairRank)
            {
                return(new List <PokerHandDto> {
                    challenger
                });
            }

            //hands are the same in terms of rank. Pot will be chopped.
            currentWinners.Add(challenger);
            return(currentWinners);
        }
Example #4
0
        /// <summary>
        /// Gets the type of the hand.
        /// </summary>
        /// <param name="hand">The hand.</param>
        /// <returns>HandType.</returns>
        /// <exception cref="ArgumentNullException">Provided poker hand is null.</exception>
        public HandType GetHandType(PokerHand hand)
        {
            //null check
            if (hand == null)
            {
                throw new ArgumentNullException(nameof(hand));
            }

            List <Card> cardsInHand = GetListOfCardsFromHand(hand);

            //check if hand is Straight
            bool isHandStraight = IsHandStraight(cardsInHand);
            //check if hand is flush
            bool isHandFlush = IsHandFlush(cardsInHand);

            //check is hand straight flush
            if (isHandStraight && isHandFlush)
            {
                return(_handTypes.GetHandTypeByTypeName("Straight Flush"));
            }

            //return if flush
            if (isHandFlush)
            {
                return(_handTypes.GetHandTypeByTypeName("Flush"));
            }

            //return if straight
            if (isHandStraight)
            {
                return(_handTypes.GetHandTypeByTypeName("Straight"));
            }

            //Get list of card frequencies
            List <CardFrequency> repeatedHandRankList = new CardFrequencyList().GetCardFrequencyList(cardsInHand);

            //check for quads
            var quads = repeatedHandRankList.Where(cr => cr.Frequency == 4).FirstOrDefault();

            if (quads != null)
            {
                return(_handTypes.GetHandTypeByTypeName("Four of a Kind"));
            }

            //check for full house
            var trips = repeatedHandRankList.Where(cr => cr.Frequency == 3).FirstOrDefault();

            if (trips != null)
            {
                //check for full house
                var pairNeededForBoat = repeatedHandRankList.Where(cr => cr.Frequency == 2).FirstOrDefault();
                if (pairNeededForBoat != null)
                {
                    return(_handTypes.GetHandTypeByTypeName("Full House"));
                }
            }

            //check for trips
            if (trips != null)
            {
                return(_handTypes.GetHandTypeByTypeName("Three of a Kind"));
            }

            //check for two pair
            var pairs = repeatedHandRankList.Where(cr => cr.Frequency == 2);

            if (pairs.Any())
            {
                if (pairs.Count() == 2)
                {
                    return(_handTypes.GetHandTypeByTypeName("Two Pair"));
                }
                //must be pair
                return(_handTypes.GetHandTypeByTypeName("Pair"));
            }

            //With all other options exausted hand must be a high card
            return(_handTypes.GetHandTypeByTypeName("High Card"));
        }