public static GameState CreateRaise50State(GameState parent) { var hero = new Player(parent.Hero); var villain = new Player(parent.Villain); var toPlay = hero.IsToPlay ? hero : villain; var raiseAmount = PotTools.GetRaiseAmount(Wager.Half, parent.Pot, parent.WagerToCall); var raise = toPlay.Wager(raiseAmount); var wagerToCall = System.Math.Abs(raise - parent.WagerToCall); var newPot = parent.Pot + raise; hero.IsToPlay = !hero.IsToPlay; villain.IsToPlay = !villain.IsToPlay; var state = new GameState( parent, parent.Board, parent.Street, hero, villain, newPot, wagerToCall, Action.Raise50); return(state); }
public static double Simulate(GameState root) { var traces = new Queue <string>(); var state = new GameState( (GameState)root.Parent, root.Board, root.Street, root.Hero, root.Villain, root.Pot, root.WagerToCall, root.LastAction); if (state.PlayerFolded) { var investedAmount = state.Hero.IsToPlay ? state.GetInvestedAmount() : -state.GetInvestedAmount(); return(investedAmount); } if (state.IsShowdown) { TryUpdateBoard(state, Street.Flop); return(Evaluator.Evaluate(state)); } state.Board = BoardGenerator.FillFromTo( state.Board, Street.Flop, state.Street, state.Hero.HoleCards); var stateValue = 0.0d; while (!GameState.IsOver(state.Street)) { switch (state.ToPlay.GetAction(state.WagerToCall)) { case Action.Check: { var isLastToAct = state.ToPlay.IsLastToAct(Action.Check); state.WagerToCall = 0.0d; state.LastAction = Action.Check; if (isLastToAct && state.Street.ShouldShowdown()) { state.Street = state.Street.GetNextStreet(); stateValue = Evaluator.Evaluate(state); break; } if (isLastToAct) { state.Board |= BoardGenerator.GenerateCard( state.Board | state.Hero.HoleCards); state.Street = state.Street.GetNextStreet(); } state.ToPlay = isLastToAct ? (state.Hero.IsFirstToActAfterFlop() ? state.Hero : state.Villain) : state.Hero.IsToPlay ? state.Villain : state.Hero; state.Hero.IsToPlay = false; state.Villain.IsToPlay = false; state.ToPlay.IsToPlay = true; traces.Enqueue(state.ToString()); break; } case Action.Bet50: { var bet = state.ToPlay.Wager(state.Pot.GetHalfPot()); state.Pot += bet; state.WagerToCall = bet; state.ToPlay = state.Hero.IsToPlay ? state.Villain : state.Hero; state.Hero.IsToPlay = false; state.Villain.IsToPlay = false; state.ToPlay.IsToPlay = true; state.LastAction = Action.Bet50; traces.Enqueue(state.ToString()); break; } case Action.Call: { var callAmount = state.ToPlay.Wager(state.WagerToCall); state.Pot += callAmount; state.WagerToCall = 0.0d; state.LastAction = Action.Call; if (state.Street.ShouldShowdown() || state.AnyAllIn) { state.Board = BoardGenerator.FillToRiver( state.Board, state.Street, state.Hero.HoleCards); state.Street = Street.Showdown; stateValue = Evaluator.Evaluate(state); break; } state.Board |= BoardGenerator.GenerateCard( state.Board | state.Hero.HoleCards); state.Street = state.Street.GetNextStreet(); state.ToPlay = state.Hero.IsFirstToActAfterFlop() ? state.Hero : state.Villain; state.Hero.IsToPlay = false; state.Villain.IsToPlay = false; state.ToPlay.IsToPlay = true; traces.Enqueue(state.ToString()); break; } case Action.Raise50: { var raiseAmount = PotTools.GetRaiseAmount( Wager.Half, state.Pot, state.WagerToCall); var raise = state.ToPlay.Wager(raiseAmount); state.WagerToCall = System.Math.Abs(raise - state.WagerToCall); state.Pot += raise; state.ToPlay = state.Hero.IsToPlay ? state.Villain : state.Hero; state.Hero.IsToPlay = false; state.Villain.IsToPlay = false; state.ToPlay.IsToPlay = true; state.LastAction = Action.Raise50; traces.Enqueue(state.ToString()); break; } case Action.Fold: { var investedAmount = state.GetInvestedAmount(); state.Street = Street.Fold; state.WagerToCall = 0.0d; state.LastAction = Action.Fold; stateValue = state.ToPlay.IsHero ? -investedAmount : investedAmount; break; } } } return(stateValue); }
public double Simulate(GameState state) { var stateCopy = GameState.CopyState(state); if (stateCopy.IsShowdown) { if (!state.AnyAllIn) { state.Board = this.generator.FillToRiver( state.Board, Street.Flop, state.Hero.HoleCards); } return(this.evaluator.Evaluate(stateCopy)); } if (stateCopy.Street == Street.Fold) { return(stateCopy.AverageValue); } stateCopy.Board = this.generator.FillFromTo( stateCopy.Board, Street.Flop, stateCopy.Street, stateCopy.Hero.HoleCards); var stateValue = 0.0d; while (!GameState.IsOver(stateCopy.Street)) { switch (stateCopy.ToPlay.GetAction(stateCopy.WagerToCall)) { case Action.Check: { var isLastToAct = stateCopy.ToPlay.IsLastToAct(Action.Check); stateCopy.WagerToCall = 0.0d; stateCopy.LastAction = Action.Check; if (isLastToAct && stateCopy.Street.ShouldShowdown()) { stateCopy.Street = stateCopy.Street.GetNextStreet(); stateValue = this.evaluator.Evaluate(stateCopy); break; } if (isLastToAct) { stateCopy.Board |= this.generator.GenerateCard( stateCopy.Board | stateCopy.Hero.HoleCards); stateCopy.Street = stateCopy.Street.GetNextStreet(); } stateCopy.ToPlay = isLastToAct ? (stateCopy.Hero.IsFirstToActAfterFlop() ? stateCopy.Hero : stateCopy.Villain) : stateCopy.Hero.IsToPlay ? stateCopy.Villain : stateCopy.Hero; stateCopy.Hero.IsToPlay = false; stateCopy.Villain.IsToPlay = false; stateCopy.ToPlay.IsToPlay = true; break; } case Action.Bet50: { var bet = stateCopy.ToPlay.Wager(stateCopy.Pot.GetHalfPot()); stateCopy.Pot += bet; stateCopy.WagerToCall = bet; stateCopy.ToPlay = stateCopy.Hero.IsToPlay ? stateCopy.Villain : stateCopy.Hero; stateCopy.Hero.IsToPlay = false; stateCopy.Villain.IsToPlay = false; stateCopy.ToPlay.IsToPlay = true; stateCopy.LastAction = Action.Bet50; break; } case Action.Call: { var callAmount = stateCopy.ToPlay.Wager(stateCopy.WagerToCall); stateCopy.Pot += callAmount; stateCopy.WagerToCall = 0.0d; stateCopy.LastAction = Action.Call; if (stateCopy.Street.ShouldShowdown()) { stateCopy.Street = stateCopy.Street.GetNextStreet(); stateValue = this.evaluator.Evaluate(stateCopy); break; } stateCopy.Board |= this.generator.GenerateCard( stateCopy.Board | stateCopy.Hero.HoleCards); stateCopy.Street = stateCopy.Street.GetNextStreet(); stateCopy.ToPlay = stateCopy.Hero.IsFirstToActAfterFlop() ? stateCopy.Hero : stateCopy.Villain; stateCopy.Hero.IsToPlay = false; stateCopy.Villain.IsToPlay = false; stateCopy.ToPlay.IsToPlay = true; break; } case Action.Raise50: { var raiseAmount = PotTools.GetRaiseAmount( Wager.Half, stateCopy.Pot, stateCopy.WagerToCall); var raise = stateCopy.ToPlay.Wager(raiseAmount); if (stateCopy.ToPlay.Stack <= 0) { } stateCopy.WagerToCall = System.Math.Abs(raise - stateCopy.WagerToCall); stateCopy.Pot += raise; stateCopy.ToPlay = stateCopy.Hero.IsToPlay ? stateCopy.Villain : stateCopy.Hero; stateCopy.Hero.IsToPlay = false; stateCopy.Villain.IsToPlay = false; stateCopy.ToPlay.IsToPlay = true; stateCopy.LastAction = Action.Raise50; break; } case Action.Fold: { if (stateCopy.ToPlay.Stack <= 0) { } stateCopy.Street = Street.Fold; stateCopy.WagerToCall = 0.0d; stateCopy.LastAction = Action.Fold; var investedAmount = (stateCopy.Pot - stateCopy.WagerToCall) / 2; stateValue = stateCopy.ToPlay.IsHero ? -investedAmount : investedAmount; break; } } } return(stateValue); }