public Results(Consts.GameTypes gameType, Board board, String handHistory) { error = false; simulations = new ArrayList(); this.board = board; this.gameType = gameType; this.handHistory = handHistory; }
public Calculator(Deck deck, ArrayList hands, Board board, Consts.GameTypes gameType) { this.deck = deck; this.hands = hands; this.board = board; values = new double[hands.Count]; if (gameType == Consts.GameTypes.OmahaHiLo) { evaluator = EvaluateOmahaHiLoShowdown; } else if (gameType == Consts.GameTypes.Omaha) { evaluator = EvaluateOmahaHiShowdown; } else { evaluator = EvaluateHoldemShowdown; } }
private void SimulateFromAnalyzer(object param) { object[] parameters = (object[])param; Consts.GameTypes gameType = (Consts.GameTypes)parameters[0]; ArrayList hands = (ArrayList)parameters[1]; Board board = (Board)parameters[2]; Deck deck = (Deck)parameters[3]; Calculator calc = new Calculator(deck, hands, board, gameType); //Calculate Equities double[] preflopEquities = null; double[] flopEquities = null; double[] turnEquities = null; double[] riverEquities = null; preflopEquities = calc.CalculatePreflopEquity(); if (board.Cards.Count > 2) { flopEquities = calc.CalculateFlopEquity(); } if (board.Cards.Count > 3) { turnEquities = calc.CalculateTurnEquity(); } if (board.Cards.Count > 4) { riverEquities = calc.CalculateRiverEquity(); } Simulation simulation = new Simulation((IHand[])hands.ToArray(typeof(IHand)), preflopEquities, flopEquities, turnEquities, riverEquities); Results tempResults = new Results(gameType, board, ""); tempResults.AddSimulation(simulation); CompleteSimulationDelegate del = new CompleteSimulationDelegate(CompleteSimulationFromAnalyzer); analyzerResultsRichTextBox.Invoke(del, new object[] { tempResults }); }
private void previousSessionsTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Parent != null) { int key = e.Node.Index + (e.Node.Parent.Index << 16); displayHistoryResults(savedHistoryResults[key]); } else if (e.Node.Nodes.Count == 0 && !e.Node.Text.Equals(String.Empty)) { XmlTextReader reader = new XmlTextReader((String)savedHistoryFileNames[e.Node.Index]); reader.WhitespaceHandling = WhitespaceHandling.None; reader.Read(); reader.Read(); if (!reader.Name.Equals("session")) { return; //invalid file } reader.Read(); int index = 0; while (reader.Name.Equals("result")) { reader.MoveToNextAttribute(); String summary = reader.Value; reader.Read(); Board board = Board.Parse(reader.ReadElementContentAsString()); double time = reader.ReadElementContentAsDouble(); Consts.GameTypes gameType = (Consts.GameTypes)Enum.Parse(typeof(Consts.GameTypes), reader.ReadElementContentAsString()); reader.Read(); ArrayList simulations = new ArrayList(); while (reader.Name.Equals("simulation")) { ArrayList cards = new ArrayList(); ArrayList playerNames = new ArrayList(); ArrayList preflopEquities = new ArrayList(); ArrayList flopEquities = new ArrayList(); ArrayList turnEquities = new ArrayList(); ArrayList riverEquities = new ArrayList(); reader.Read(); while (reader.Name.Equals("hand")) { reader.MoveToNextAttribute(); cards.Add(Cards.Parse(reader.Value)); reader.MoveToNextAttribute(); playerNames.Add(reader.Value); reader.Read(); preflopEquities.Add(reader.ReadElementContentAsDouble()); flopEquities.Add(reader.ReadElementContentAsDouble()); turnEquities.Add(reader.ReadElementContentAsDouble()); riverEquities.Add(reader.ReadElementContentAsDouble()); reader.Read(); } simulations.Add(new Simulation((Cards[])cards.ToArray(typeof(Cards)), (String[])playerNames.ToArray(typeof(String)), (double[])preflopEquities.ToArray(typeof(double)), (double[])flopEquities.ToArray(typeof(double)), (double[])turnEquities.ToArray(typeof(double)), (double[])riverEquities.ToArray(typeof(double)))); reader.Read(); } reader.Read(); String handHistory = reader.ReadElementContentAsString(); Results result = new Results(gameType, board, handHistory); foreach (Simulation simulation in simulations) { result.AddSimulation(simulation); } result.Time = time; result.Summary = summary; int key = index + (e.Node.Index << 16); savedHistoryResults[key] = result; e.Node.Nodes.Add(result.Summary); reader.Read(); index++; } e.Node.Expand(); reader.Close(); } }
private void simulateButton_Click(object sender, EventArgs e) { analyzerResultsRichTextBox.Text = "Simulating..."; DisableButtons(); object[] parameters = new object[4]; Consts.GameTypes gameType = (Consts.GameTypes)gameComboBox.SelectedIndex; parameters[0] = gameType; ArrayList hands = new ArrayList(); try { foreach (TextBox handTextBox in handTextBoxes) { if (handTextBox.Text.Length > 0) { String handText = handTextBox.Text.Replace(" ", ""); if (gameType == Consts.GameTypes.Holdem) { hands.Add(new HoldemHand(Card.Parse(handText.Substring(0, 2)), Card.Parse(handText.Substring(2, 2)))); } else { hands.Add(new OmahaHand(Card.Parse(handText.Substring(0, 2)), Card.Parse(handText.Substring(2, 2)), Card.Parse(handText.Substring(4, 2)), Card.Parse(handText.Substring(6, 2)))); } } } } catch (Exception) { analyzerResultsRichTextBox.Text = "Error parsing hands."; EnableButtons(); return; } parameters[1] = hands; Board board = new Board(); try { String boardText = boardTextBox.Text.Replace(" ", ""); for (int n = 0; n < boardText.Length - 1; n += 2) { board.Add(Card.Parse(boardText.Substring(n, 2))); } } catch (Exception) { analyzerResultsRichTextBox.Text = "Error parsing board."; EnableButtons(); return; } if ((board.Cards.Count < 3 && board.Cards.Count > 0) || board.Cards.Count > 5) { analyzerResultsRichTextBox.Text = "Error parsing board. Invalid number of cards."; EnableButtons(); return; } parameters[2] = board; ArrayList deadCards = new ArrayList(); try { String deadCardsText = deadCardsTextBox.Text.Replace(" ", ""); for (int n = 0; n < deadCardsText.Length - 1; n += 2) { deadCards.Add(Card.Parse(deadCardsText.Substring(n, 2))); } } catch (Exception) { analyzerResultsRichTextBox.Text = "Error parsing dead cards."; EnableButtons(); return; } Deck deck = new Deck(); foreach (IHand hand in hands) { foreach (Card card in hand.Cards) { if (deck.Cards.Contains(card)) { deck.Cards.Remove(card); } else { analyzerResultsRichTextBox.Text = "Error. Duplicate cards detected in simulation."; EnableButtons(); return; } } } foreach (Card card in deadCards) { if (deck.Cards.Contains(card)) { deck.Cards.Remove(card); } else { analyzerResultsRichTextBox.Text = "Error. Duplicate cards detected in simulation."; EnableButtons(); return; } } foreach (Card card in board.Cards) { if (deck.Cards.Contains(card)) { deck.Cards.Remove(card); } else { analyzerResultsRichTextBox.Text = "Error. Duplicate cards detected in simulation."; EnableButtons(); return; } } foreach (Card card in board.Cards) { deck.Cards.Add(card); } parameters[3] = deck; calculateThread = new Thread(SimulateFromAnalyzer); calculateThread.IsBackground = true; calculateThread.Start(parameters); }