Exemplo n.º 1
0
 public static PokerScoreOuts CalculateRiver(SixCardHand cards)
 {
     //if there are 4 of the same suit there are 9 more of that suit we can hit
     return(cards.CountFlush() == 4
         ? PokerHelper.CreateRiverOuts(9)
         : PokerHelper.CreateRiverOuts(0));
 }
Exemplo n.º 2
0
 public static int CalculateRiver(SixCardHand cards)
 {
     //if there are 4 of the same suit there are 9 more of that suit we can hit
     return(cards.CountFlush() == 4 ? 9 : 0);
 }
Exemplo n.º 3
0
        public static PokerScoreOuts CalculateRiver(SixCardHand cards)
        {
            ISet <int> inside  = new HashSet <int>(),
                       outside = new HashSet <int>();

            var withoutPair = cards.RemovePairs();
            var handList    = new List <int> {
                cards.Cards[0].ToInt(), cards.Cards[1].ToInt(), cards.Cards[2].ToInt(), cards.Cards[3].ToInt(), cards.Cards[4].ToInt(), cards.Cards[5].ToInt()
            };

            if (cards.CountFlush() < 4)
            {
                return(PokerHelper.CreateTurnOuts(0, false));
            }

            if (withoutPair.Count <= 3)
            {
                return(PokerHelper.CreateRiverOuts(0));
            }
            if (withoutPair.Count == 4)
            {
                if (!withoutPair.AreSameSuit())
                {
                    return(PokerHelper.CreateTurnOuts(0, false));
                }

                if (withoutPair[3].Rank == Rank.Ace && withoutPair[2].Rank <= Rank.Five)
                {
                    withoutPair = new List <Card> {
                        withoutPair[3], withoutPair[0], withoutPair[1], withoutPair[2]
                    }
                }
                ;

                outside = PokerHelper.CountOutsideStraightDraws(handList, withoutPair);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateTurnOuts(outside.Count, false));
                }

                inside = PokerHelper.CountInsideStraightDraws(handList, withoutPair);
                if (inside.Count > 0)
                {
                    return(PokerHelper.CreateTurnOuts(inside.Count, false));
                }

                return(PokerHelper.CreateRiverOuts(0));
            }
            if (withoutPair.Count == 5)
            {
                if (withoutPair.MaxSuit() < 4)
                {
                    return(PokerHelper.CreateTurnOuts(0, false));
                }

                if (withoutPair[4].Rank == Rank.Ace && withoutPair[2].Rank <= Rank.Five)
                {
                    var comb = new List <Card> {
                        withoutPair[4], withoutPair[0], withoutPair[1], withoutPair[2]
                    };

                    if (comb.AreSameSuit())
                    {
                        outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                        inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                    }
                }

                foreach (var comb in PokerEnumerator.GetFourCardsFromFive(withoutPair).Where(comb => comb.AreSameSuit()))
                {
                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                }

                outside.UnionWith(inside);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateRiverOuts(outside.Count));
                }
                return(PokerHelper.CreateRiverOuts(0));
            }
            if (withoutPair.Count == 6)
            {
                if (withoutPair.MaxSuit() < 4)
                {
                    return(PokerHelper.CreateTurnOuts(0, false));
                }

                if (withoutPair[5].Rank == Rank.Ace && withoutPair[2].Rank <= Rank.Five)
                {
                    var comb = new List <Card> {
                        withoutPair[5], withoutPair[0], withoutPair[1], withoutPair[2]
                    };

                    if (comb.AreSameSuit())
                    {
                        outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                        inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                    }
                }

                foreach (var comb in PokerEnumerator.GetFourCardsFromSix(withoutPair).Where(comb => comb.AreSameSuit()))
                {
                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                }

                outside.UnionWith(inside);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateRiverOuts(outside.Count));
                }
                return(PokerHelper.CreateRiverOuts(0));
            }
            throw new ArgumentException("Without pair count should never be more than six");
        }
    }