/// <summary> /// Creates a new BetManager for the hand. /// </summary> /// <param name="namesToChips">A dictionary that maps player names to the amount of money they started the hand with.</param> /// <param name="structure">The type of betting structure this hand is.</param> /// <param name="ante">The ante for this hand. If there is no ante, it should be set to -1.</param> public BetManager(Dictionary <string, double> namesToChips, BettingStructure structure, double[] blinds, double ante) { round = 0; bs = structure; numberBlindsPosted = 0; this.smallBlind = blinds.Length > 1 ? blinds[0] : -1; this.bigBlind = blinds.Length > 1 ? blinds[1] : blinds[0]; this.ante = ante; this.minimumRaise = bigBlind; numberPlayersIn = namesToChips.Keys.Count; numberPlayersCanStillBet = numberPlayersIn; numberCalls = 0; betLevel = 0; committedThisRound = new Dictionary <string, double>(); committedTotal = new Dictionary <string, double>(); startingChips = new Dictionary <string, double>(); foreach (string name in namesToChips.Keys) { committedTotal[name] = 0; committedThisRound[name] = 0; startingChips[name] = namesToChips[name]; } }
/// <summary> /// Creates a new BetManager for the hand. /// </summary> /// <param name="namesToChips">A dictionary that maps player names to the amount of money they started the hand with.</param> /// <param name="structure">The type of betting structure this hand is.</param> /// <param name="ante">The ante for this hand. If there is no ante, it should be set to -1.</param> public BetManager(Dictionary<string,double> namesToChips, BettingStructure structure, double[] blinds, double ante ) { round = 0; bs = structure; numberBlindsPosted = 0; this.smallBlind = blinds.Length > 1 ? blinds[0] : -1; this.bigBlind = blinds.Length > 1 ? blinds[1] : blinds[0]; this.ante = ante; this.minimumRaise = bigBlind; numberPlayersIn = namesToChips.Keys.Count; numberPlayersCanStillBet = numberPlayersIn; numberCalls = 0; betLevel = 0; committedThisRound = new Dictionary<string, double>(); committedTotal = new Dictionary<string, double>(); startingChips = new Dictionary<string, double>(); foreach (string name in namesToChips.Keys) { committedTotal[name] = 0; committedThisRound[name] = 0; startingChips[name] = namesToChips[name]; } }
public HandHistory(Seat[] players, ulong handNumber, uint button, double[] blinds, double ante, BettingStructure bs) { this.button = button; predealActions = new List <Action>(); preflopActions = new List <Action>(); flopActions = new List <Action>(); turnActions = new List <Action>(); riverActions = new List <Action>(); Folded = new bool[players.Length]; AllIn = new bool[players.Length]; this.players = players; hc = new ulong[players.Length]; startingChips = new double[players.Length]; for (int i = 0; i < startingChips.Length; i++) { startingChips[i] = players[i].Chips; } this.handNumber = handNumber; switch (blinds.Length) { case 1: this.bigBlind = blinds[0]; break; case 2: this.smallBlind = blinds[0]; this.bigBlind = blinds[1]; break; default: break; } this.ante = ante; BettingStructure = bs; allBlinds = blinds; site = "SimulatedPokerSite"; CurrentRound = Round.Predeal; CurrentBetLevel = 1; }
public TournamentHandHistory(Seat[] players, ulong handNumber, uint button, double[] blinds, double ante, BettingStructure bs) : base(players, handNumber, button, blinds, ante, bs) { }
public HandHistory Resume(PokerHand savedHand, CachedHand cache) { _cache = cache; #region Restore hand context _seats = new Seat[savedHand.Players.Length]; var orderedPlayers = savedHand.Players.OrderBy(p => p.Seat); for (int i = 0; i < _seats.Length; i++) { var player = orderedPlayers.ElementAt(i); _seats[i] = new Seat(player.Seat, player.Name, (double)player.Stack); } ulong handNum = ulong.Parse(savedHand.Context.ID); uint button = (uint)savedHand.Context.Button; List <double> blinds = new List <double>(); if (savedHand.Context.SmallBlind > 0m) { blinds.Add((double)savedHand.Context.SmallBlind); } if (savedHand.Context.BigBlind > 0m) { blinds.Add((double)savedHand.Context.BigBlind); } double ante = (double)savedHand.Context.Ante; BettingStructure bs = BettingStructure.None; switch (savedHand.Context.BettingType) { case BettingType.FixedLimit: bs = BettingStructure.Limit; break; case BettingType.NoLimit: bs = BettingStructure.NoLimit; break; case BettingType.PotLimit: bs = BettingStructure.PotLimit; break; default: throw new Exception("Unspecified betting structure."); } _history = new HandHistory(_seats, handNum, button, blinds.ToArray(), ante, bs); #endregion //Create a new map from player names to player chips for the BetManager Dictionary <string, double> namesToChips = new Dictionary <string, double>(); //Create a new list of players for the PlayerManager _playerIndices = new CircularList <int>(); _playerIndices.Loop = true; // Initialize the names to chips map and find the index of the button for (int i = 0; i < _seats.Length; i++) { namesToChips[_seats[i].Name] = _seats[i].Chips; if (_seats[i].SeatNumber == _history.Button) { _buttonIdx = i; _utgIdx = (i + 1) % _seats.Length; } } // Create a circular list of players, in order of first to act for (int i = (_buttonIdx + 1) % _seats.Length; _playerIndices.Count < _seats.Length;) { _playerIndices.Add(i); i = (i + 1) % _seats.Length; } _betManager = new BetManager(namesToChips, _history.BettingStructure, _history.AllBlinds, _history.Ante); _potManager = new PotManager(_seats); _history.CurrentRound = Round.Predeal; if (savedHand.Blinds == null) { savedHand.Blinds = new Blind[0]; } if (!restoreBlinds(savedHand)) { return(_history); } DealHoleCards(); if (_betManager.In <= 1) { _history.CurrentRound = Round.Over; return(_history); } _history.CurrentRound = Round.Preflop; if (_betManager.CanStillBet > 1) { if (savedHand.Rounds == null || savedHand.Rounds.Length == 0) { savedHand.Rounds = new PokerHandHistory.Round[] { new PokerHandHistory.Round() { Actions = new PokerHandHistory.Action[0] } } } ; else if (savedHand.Rounds[0].Actions == null) { savedHand.Rounds[0].Actions = new PokerHandHistory.Action[0]; } if (!restoreBets(savedHand.Rounds[0].Actions, _history.PreflopActions)) { return(_history); } } if (_betManager.In <= 1) { payWinners(); _history.CurrentRound = Round.Over; return(_history); } DealFlop(); _history.CurrentRound = Round.Flop; if (_betManager.CanStillBet > 1) { if (savedHand.Rounds.Length < 2) { savedHand.Rounds = new PokerHandHistory.Round[] { savedHand.Rounds[0], new PokerHandHistory.Round() { Actions = new PokerHandHistory.Action[0] } } } ; else if (savedHand.Rounds[1].Actions == null) { savedHand.Rounds[1].Actions = new PokerHandHistory.Action[0]; } if (!restoreBets(savedHand.Rounds[1].Actions, _history.FlopActions)) { return(_history); } } if (_betManager.In <= 1) { payWinners(); _history.CurrentRound = Round.Over; return(_history); } DealTurn(); _history.CurrentRound = Round.Turn; if (_betManager.CanStillBet > 1) { if (savedHand.Rounds.Length < 3) { savedHand.Rounds = new PokerHandHistory.Round[] { savedHand.Rounds[0], savedHand.Rounds[1], new PokerHandHistory.Round() { Actions = new PokerHandHistory.Action[0] } } } ; else if (savedHand.Rounds[2].Actions == null) { savedHand.Rounds[2].Actions = new PokerHandHistory.Action[0]; } if (!restoreBets(savedHand.Rounds[2].Actions, _history.TurnActions)) { return(_history); } } if (_betManager.In <= 1) { payWinners(); _history.CurrentRound = Round.Over; return(_history); } DealRiver(); _history.CurrentRound = Round.River; if (_betManager.CanStillBet > 1) { if (savedHand.Rounds.Length < 4) { savedHand.Rounds = new PokerHandHistory.Round[] { savedHand.Rounds[0], savedHand.Rounds[1], savedHand.Rounds[2], new PokerHandHistory.Round() { Actions = new PokerHandHistory.Action[0] } } } ; else if (savedHand.Rounds[3].Actions == null) { savedHand.Rounds[3].Actions = new PokerHandHistory.Action[0]; } if (!restoreBets(savedHand.Rounds[3].Actions, _history.RiverActions)) { return(_history); } } if (_betManager.In <= 1) { payWinners(); _history.CurrentRound = Round.Over; return(_history); } payWinners(); _history.ShowDown = true; _history.CurrentRound = Round.Over; return(_history); }