Beispiel #1
0
        /* Checks that every possible hand is covered in the table */
        public static void TestPercentiles()
        {
            for (CardFace face1 = CardFace.Ace; face1 <= CardFace.King; face1++)
            {
                for (CardSuit suit1 = CardSuit.Clubs; suit1 <= CardSuit.Spades; suit1++)
                {
                    Card c1 = new Card(face1, suit1);

                    for (CardFace face2 = CardFace.Ace; face2 <= CardFace.King; face2++)
                    {
                        for (CardSuit suit2 = CardSuit.Clubs; suit2 <= CardSuit.Spades; suit2++)
                        {
                            Card c2 = new Card(face2, suit2);

                            HoldemHand hand = new HoldemHand(c1, c2);
                            Trace.Assert(HoldemHand.preflopPercentiles.ContainsKey(hand.ToString()), "Percentile not found for: " + hand.ToString());
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public ClassificationPreflop(HoldemHand hand)
 {
     this.percentile = (float)HoldemHand.preflopPercentiles[hand.ToString()];
 }
Beispiel #3
0
        /* Checks that every possible hand is covered in the table */
        public static void TestPercentiles()
        {
            for (CardFace face1 = CardFace.Ace; face1 <= CardFace.King; face1++)
            {
                for (CardSuit suit1 = CardSuit.Clubs; suit1 <= CardSuit.Spades; suit1++)
                {
                    Card c1 = new Card(face1, suit1);

                    for (CardFace face2 = CardFace.Ace; face2 <= CardFace.King; face2++)
                    {
                        for (CardSuit suit2 = CardSuit.Clubs; suit2 <= CardSuit.Spades; suit2++)
                        {
                            Card c2 = new Card(face2, suit2);

                            HoldemHand hand = new HoldemHand(c1, c2);
                            Trace.Assert(HoldemHand.preflopPercentiles.ContainsKey(hand.ToString()), "Percentile not found for: " + hand.ToString());
                        }
                    }
                }
            }
        }
Beispiel #4
0
 public ClassificationPreflop(HoldemHand hand)
 {
     this.percentile = (float)HoldemHand.preflopPercentiles[hand.ToString()];
 }
        public List <Statistic> Calculate(HoldemHand hand, HoldemBoard board)
        {
            List <Statistic> result = new List <Statistic>();

            // What game phase are we in (returns empty list if the board is invalid)
            HoldemGamePhase phase = HoldemGamePhase.Flop;

            if (board.Count == 3)
            {
                phase = HoldemGamePhase.Flop;
            }
            else if (board.Count == 4)
            {
                phase = HoldemGamePhase.Turn;
            }
            else if (board.Count == 5)
            {
                phase = HoldemGamePhase.River;
            }
            else
            {
                Trace.WriteLine("We were asked to calculate the odds for " + hand.ToString() + " and " + board.ToString() + " but the board seems to be invalid. Returning empty.");
                return(result);
            }

            HoldemHand.ClassificationPostflop                  classification   = (HoldemHand.ClassificationPostflop)hand.GetClassification(phase, board);
            HoldemHand.ClassificationPostflop.HandType         handType         = classification.GetHand();
            HoldemHand.ClassificationPostflop.DrawType         drawType         = classification.GetDraw();
            HoldemHand.ClassificationPostflop.StraightDrawType straightDrawType = classification.GetStraightDraw();

            result.Add(new Statistic(new StatisticsDescriptiveData("Your hand", classification.GetHandDescription())));

            if (phase == HoldemGamePhase.Flop || phase == HoldemGamePhase.Turn)
            {
                result.Add(new Statistic(new StatisticsDescriptiveData("Draws", classification.GetDrawsDescription())));

                if (handType == HoldemHand.ClassificationPostflop.HandType.HighCard)
                {
                    // Hold high card, hope to make a pair
                    result.Add(CreateOutsStatistic("Improve to a pair", 6, phase));
                }
                else if (handType == HoldemHand.ClassificationPostflop.HandType.Pair)
                {
                    // Hold a pair, hope to make three of a kind
                    result.Add(CreateOutsStatistic("Improve to three of a kind", 2, phase));
                }
                else if (handType == HoldemHand.ClassificationPostflop.HandType.TwoPair)
                {
                    // Hold two pair, hope to make a full house
                    result.Add(CreateOutsStatistic("Improve to a full house", 4, phase));
                }

                if (drawType == HoldemHand.ClassificationPostflop.DrawType.Flush)
                {
                    result.Add(CreateOutsStatistic("Improve to a flush", 9, phase));
                }
                else if (drawType == HoldemHand.ClassificationPostflop.DrawType.Straight)
                {
                    if (straightDrawType == HoldemHand.ClassificationPostflop.StraightDrawType.OpenEndedStraightDraw)
                    {
                        result.Add(CreateOutsStatistic("Improve to a straight", 8, phase));
                    }
                    else if (straightDrawType == HoldemHand.ClassificationPostflop.StraightDrawType.InsideStraightDraw)
                    {
                        result.Add(CreateOutsStatistic("Improve to a straight", 4, phase));
                    }
                    else
                    {
                        Trace.WriteLine("Warning! Straight draw detected when calculating odds but none of the cases was matched?");
                    }
                }
                else if (drawType == HoldemHand.ClassificationPostflop.DrawType.FlushAndStraight)
                {
                    // Open ended straight flush draw
                    if (straightDrawType == HoldemHand.ClassificationPostflop.StraightDrawType.OpenEndedStraightDraw)
                    {
                        // 9 outs for the flush + 6 outs (2 outs for the straight draw are the suit we need to make the flush)
                        result.Add(CreateOutsStatistic("Improve to a flush or straight", 15, phase));
                    }
                    else if (straightDrawType == HoldemHand.ClassificationPostflop.StraightDrawType.InsideStraightDraw)
                    {
                        // inside straight flushd draw, 9 outs + 3 (1 out is the suit we need)
                        result.Add(CreateOutsStatistic("Improve to a flush or straight", 12, phase));
                    }
                    else
                    {
                        Trace.WriteLine("Warning! Flush and straight draw detected when calculating odds but none of the cases was matched?");
                    }
                }
            }

            return(result);
        }
        public List<Statistic> Calculate(HoldemHand hand, HoldemBoard board)
        {
            List<Statistic> result = new List<Statistic>();

            // What game phase are we in (returns empty list if the board is invalid)
            HoldemGamePhase phase = HoldemGamePhase.Flop;
            if (board.Count == 3) phase = HoldemGamePhase.Flop;
            else if (board.Count == 4) phase = HoldemGamePhase.Turn;
            else if (board.Count == 5) phase = HoldemGamePhase.River;
            else
            {
                Trace.WriteLine("We were asked to calculate the odds for " + hand.ToString() + " and " + board.ToString() + " but the board seems to be invalid. Returning empty.");
                return result;
            }

            HoldemHand.ClassificationPostflop classification = (HoldemHand.ClassificationPostflop)hand.GetClassification(phase, board);
            HoldemHand.ClassificationPostflop.HandType handType = classification.GetHand();
            HoldemHand.ClassificationPostflop.DrawType drawType = classification.GetDraw();
            HoldemHand.ClassificationPostflop.StraightDrawType straightDrawType = classification.GetStraightDraw();

            result.Add(new Statistic(new StatisticsDescriptiveData("Your hand", classification.GetHandDescription())));

            if (phase == HoldemGamePhase.Flop || phase == HoldemGamePhase.Turn)
            {
                result.Add(new Statistic(new StatisticsDescriptiveData("Draws", classification.GetDrawsDescription())));

                if (handType == HoldemHand.ClassificationPostflop.HandType.HighCard)
                {
                    // Hold high card, hope to make a pair
                    result.Add(CreateOutsStatistic("Improve to a pair", 6, phase));
                }
                else if (handType == HoldemHand.ClassificationPostflop.HandType.Pair)
                {
                    // Hold a pair, hope to make three of a kind
                    result.Add(CreateOutsStatistic("Improve to three of a kind", 2, phase));
                }
                else if (handType == HoldemHand.ClassificationPostflop.HandType.TwoPair)
                {
                    // Hold two pair, hope to make a full house
                    result.Add(CreateOutsStatistic("Improve to a full house", 4, phase));
                }

                if (drawType == HoldemHand.ClassificationPostflop.DrawType.Flush)
                {
                    result.Add(CreateOutsStatistic("Improve to a flush", 9, phase));
                }
                else if (drawType == HoldemHand.ClassificationPostflop.DrawType.Straight)
                {
                    if (straightDrawType == HoldemHand.ClassificationPostflop.StraightDrawType.OpenEndedStraightDraw)
                    {
                        result.Add(CreateOutsStatistic("Improve to a straight", 8, phase));
                    }
                    else if (straightDrawType == HoldemHand.ClassificationPostflop.StraightDrawType.InsideStraightDraw)
                    {
                        result.Add(CreateOutsStatistic("Improve to a straight", 4, phase));
                    }
                    else
                    {
                        Trace.WriteLine("Warning! Straight draw detected when calculating odds but none of the cases was matched?");
                    }
                }
                else if (drawType == HoldemHand.ClassificationPostflop.DrawType.FlushAndStraight)
                {
                    // Open ended straight flush draw
                    if (straightDrawType == HoldemHand.ClassificationPostflop.StraightDrawType.OpenEndedStraightDraw)
                    {
                        // 9 outs for the flush + 6 outs (2 outs for the straight draw are the suit we need to make the flush)
                        result.Add(CreateOutsStatistic("Improve to a flush or straight", 15, phase));
                    }
                    else if (straightDrawType == HoldemHand.ClassificationPostflop.StraightDrawType.InsideStraightDraw)
                    {
                        // inside straight flushd draw, 9 outs + 3 (1 out is the suit we need)
                        result.Add(CreateOutsStatistic("Improve to a flush or straight", 12, phase));
                    }
                    else
                    {
                        Trace.WriteLine("Warning! Flush and straight draw detected when calculating odds but none of the cases was matched?");
                    }
                }
            }

            return result;
        }