Exemplo n.º 1
0
        private PlayerCombination IsRoyalFlush(StructuredBoardCards cards)
        {
            if (!HasHash(cards.RankHash, this.straightHashes[CardRank.Ace]))
            {
                // not A high straight
                return(PlayerCombination.Failed);
            }

            foreach (var(suit, hash) in this.flashHashes)
            {
                if (!HasHash(cards.SuitHash, hash))
                {
                    // not flash
                    continue;
                }

                var flashCards = cards.SuitGroup[suit].Take(5).ToArray();

                if (flashCards.GetRankHash() != this.straightHashes[CardRank.Ace])
                {
                    // not royal flash
                    continue;
                }

                return(new PlayerCombination(flashCards, HandCombination.RoyalFlush));
            }

            return(PlayerCombination.Failed);
        }
Exemplo n.º 2
0
        private PlayerCombination IsTwoPair(StructuredBoardCards board)
        {
            foreach (var(pair1Rank, pair1Cards) in board.RankGroup)
            {
                if (pair1Cards.Length != 2)
                {
                    // no pair
                    continue;
                }

                foreach (var(pair2Rank, pair2Cards) in board.RankGroup)
                {
                    if (pair1Rank == pair2Rank || pair2Cards.Length != 2)
                    {
                        // no 2nd pair
                        continue;
                    }

                    var pairs  = pair1Cards.Concat(pair2Cards);
                    var kicker = board.Cards.Where(x => !pairs.Contains(x)).Take(1);

                    return(new PlayerCombination(pairs.Concat(kicker).ToArray(), HandCombination.TwoPair));
                }
            }

            return(PlayerCombination.Failed);
        }
Exemplo n.º 3
0
        private PlayerCombination IsStraightFlush(StructuredBoardCards board)
        {
            foreach (var(_, flashHash) in this.flashHashes)
            {
                if (!HasHash(board.SuitHash, flashHash))
                {
                    // not flash
                    continue;
                }

                foreach (var(rank, straightHash) in this.straightHashes)
                {
                    if (!HasHash(board.RankHash, straightHash))
                    {
                        // not straight
                        continue;
                    }

                    // need only rank for combination strength evaluation
                    var combination = new[] { new Card(rank, CardSuit.Hearth) };

                    return(new PlayerCombination(combination, HandCombination.StraightFlush));
                }
            }

            return(PlayerCombination.Failed);
        }
Exemplo n.º 4
0
        private PlayerCombination IsFullHouse(StructuredBoardCards board)
        {
            foreach (var(rank3, cards3) in board.RankGroup)
            {
                if (cards3.Length != 3)
                {
                    // no 3 kind
                    continue;
                }

                foreach (var(rank2, cards2) in board.RankGroup)
                {
                    if (rank3 == rank2 || cards2.Length < 2)
                    {
                        // no pair
                        continue;
                    }

                    var combination = cards3.Concat(cards2).Take(5).ToArray();
                    return(new PlayerCombination(combination, HandCombination.FullHouse));
                }
            }

            return(PlayerCombination.Failed);
        }
Exemplo n.º 5
0
        private PlayerCombination IsThreeOfaKind(StructuredBoardCards board)
        {
            foreach (var(rank, cards) in board.RankGroup)
            {
                if (cards.Length != 3)
                {
                    // not three of a kind
                    continue;
                }

                var combination = cards.Concat(board.Cards.Where(x => x.Rank != rank).Take(2)).ToArray();
                return(new PlayerCombination(combination, HandCombination.ThreeOfaKind));
            }

            return(PlayerCombination.Failed);
        }
Exemplo n.º 6
0
        private PlayerCombination IsFourOfaKind(StructuredBoardCards board)
        {
            foreach (var(rank, cards) in board.RankGroup)
            {
                if (cards.Length != 4)
                {
                    // no 4 kind
                    continue;
                }

                // need only kicker for combination strength evaluation
                var combination = board.Cards.Where(x => x.Rank != rank).Take(1).ToArray();
                return(new PlayerCombination(combination, HandCombination.FourOfAKind));
            }

            return(PlayerCombination.Failed);
        }
Exemplo n.º 7
0
        private PlayerCombination IsPair(StructuredBoardCards board)
        {
            foreach (var(_, cards) in board.RankGroup)
            {
                if (cards.Length != 2)
                {
                    // no pair
                    continue;
                }

                var pairs   = cards;
                var kickers = board.Cards.Where(x => !pairs.Contains(x)).Take(3);

                return(new PlayerCombination(pairs.Concat(kickers).ToArray(), HandCombination.OnePair));
            }

            return(PlayerCombination.Failed);
        }
Exemplo n.º 8
0
 private PlayerCombination GetHighCards(StructuredBoardCards cards)
 {
     return(new PlayerCombination(cards.Cards.Take(5).ToArray(), HandCombination.HighCard));
 }
Exemplo n.º 9
0
        private PlayerCombination GetCombination(Hand hand, Board board)
        {
            var cached = new StructuredBoardCards(board.Concat(hand));
            PlayerCombination combination;

            // some checks can be merged, but too lazy

            combination = this.IsRoyalFlush(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            combination = this.IsStraightFlush(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            combination = this.IsFourOfaKind(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            combination = this.IsFullHouse(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            combination = this.IsFlush(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            combination = this.IsStraight(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            combination = this.IsThreeOfaKind(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            combination = this.IsTwoPair(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            combination = this.IsPair(cached);
            if (combination.IsSuccessful)
            {
                return(combination);
            }

            return(this.GetHighCards(cached));
        }