public HoldemHand.Classification GetHandClassification(HoldemGamePhase phase, HoldemBoard board) { HoldemHand.Classification classification = GetClassification(phase, board); Trace.WriteLine(String.Format("Rating hand [{0}] for {1} on board [{2}]: {3}", base.ToString(), phase.ToString(), board.ToString(), classification.ToString())); return classification; }
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; }