private void LoadConfig() { XDocument doc = XDocument.Load("HoldemConfig.xml"); var gameRules = doc.Element("HoldemConfig").Element("GameRules"); // Get game rules littleBlindSize = Convert.ToInt32(gameRules.Attribute("littleBlind").Value); bigBlindSize = Convert.ToInt32(gameRules.Attribute("bigBlind").Value); startingStack = Convert.ToInt32(gameRules.Attribute("startingStack").Value); maxNumRaisesPerBettingRound = Convert.ToInt32(gameRules.Attribute("maxNumRaisesPerBettingRound").Value); // Create players var xplayers = doc.Descendants("Player"); int i = 0; numPlayers = xplayers.Count(); players = new ServerHoldemPlayer[numPlayers]; foreach (var player in xplayers) { Console.WriteLine(player.Value); players[i] = new ServerHoldemPlayer(i, startingStack, player.Attribute("dll").Value); i++; } }
private void Showdown(Card[] board, ref List <int> winningPlayers, int lastToAct) { int currPlayer = GetNextActivePlayer(lastToAct); int firstToAct = currPlayer; Hand overallBestHand; // evaluate and show hand for first player to act - flag them as winning for now overallBestHand = Hand.FindPlayersBestHand(players[firstToAct].HoleCards(), board); BroadcastPlayerHand(firstToAct, overallBestHand); winningPlayers.Add(firstToAct); // Loop through other active players currPlayer = GetNextActivePlayer(currPlayer); do { ServerHoldemPlayer player = players[currPlayer]; eActionType playersAction; int playersAmount; // if not first to act then player may fold without showing cards player.GetAction(eStage.STAGE_SHOWDOWN, 0, 0, 0, 0, potSize, out playersAction, out playersAmount); if (playersAction == eActionType.ACTION_FOLD) { BroadcastAction(eStage.STAGE_SHOWDOWN, currPlayer, playersAction, 0); } else { Hand playerBestHand = Hand.FindPlayersBestHand(player.HoleCards(), board); BroadcastPlayerHand(currPlayer, playerBestHand); int result = Hand.compareHands(overallBestHand, playerBestHand); if (result == 1) { // this hand is better than current best hand winningPlayers.Clear(); } if (result >= 0) { // this hand is equal to or better than current best hand overallBestHand = playerBestHand; winningPlayers.Add(player.PlayerNum); } } currPlayer = GetNextActivePlayer(currPlayer); } while (currPlayer != firstToAct); }
internal void UpdatePlayer(ServerHoldemPlayer player) { var pos = _playerPositions[player.PlayerNum]; var x = pos.X; var y = pos.Y; var stack = player.StackSize + " "; ConsoleLine playerName; ConsoleLine stackSize; var holeCards = player.HoleCards(); List <ConsoleLine> cards; switch (pos.Type) { case PositionType.Top: playerName = new ConsoleLine(x, y, player.Name); stackSize = new ConsoleLine(x, y + 1, stack); cards = BuildCards(holeCards, x, y + 5, player.IsAlive); break; case PositionType.Right: playerName = new ConsoleLine(x + 15, y, player.Name); stackSize = new ConsoleLine(x + 15, y + 1, stack); cards = BuildCards(holeCards, x, y, player.IsAlive); break; case PositionType.Bottom: playerName = new ConsoleLine(x, y + 7, player.Name); stackSize = new ConsoleLine(x, y + 8, stack); cards = BuildCards(holeCards, x, y, player.IsAlive); break; case PositionType.Left: playerName = new ConsoleLine(x, y, player.Name); stackSize = new ConsoleLine(x, y + 1, stack); cards = BuildCards(holeCards, x + 12, y, player.IsAlive); break; default: throw new ArgumentOutOfRangeException(); } DrawLines(new List <ConsoleLine> { playerName, stackSize }, ConsoleColor.Black, ConsoleColor.White); DrawLines(cards, ConsoleColor.White, ConsoleColor.Black); }
private void LoadConfig(string sConfigFile, string sOutputBase) { var doc = XDocument.Load(sConfigFile); // This must happen before we write the first log message Logger.Initialize("logs\\" + sOutputBase + "_gamelog.txt"); TimingLogger.Initialize("logs\\" + sOutputBase + "_calllog.csv"); Logger.Log("--- *** CONFIG *** ---"); Logger.Log(doc.ToString()); var holdemConfig = doc.Element("HoldemConfig"); if (holdemConfig == null) { throw new Exception("Unable to find HoldemConfig element in HoldemConfig.xml"); } var gameRules = holdemConfig.Element("GameRules"); if (gameRules == null) { throw new Exception("Unable to find GameRules element in HoldemConfig.xml"); } // Get game rules var gameConfigSettings = new Dictionary <string, string> { { "smallBlind", _smallBlindSize.ToString() }, { "bigBlind", _bigBlindSize.ToString() }, { "startingStack", _startingStack.ToString() }, { "maxNumRaisesPerBettingRound", _maxNumRaisesPerBettingRound.ToString() }, { "maxHands", _maxHands.ToString() }, { "doubleBlindFrequency", _doubleBlindFrequency.ToString() }, { "botTimeOutMilliSeconds", _botTimeOutMilliSeconds.ToString() }, { "randomDealer", _bRandomDealer.ToString() }, { "randomSeating", _bRandomSeating.ToString() }, { "pauseAfterEachHand", _bPauseAfterEachHand.ToString() }, { "sleepAfterActionMilliSeconds", _sleepAfterActionMilliSeconds.ToString() }, { "graphicsDisplay", _bGraphicsDisplay.ToString() } }; // add defaults to dictionary // add or update values in dictionary from values in xml foreach (var attr in gameRules.Attributes()) { if (gameConfigSettings.ContainsKey(attr.Name.ToString())) { gameConfigSettings[attr.Name.ToString()] = attr.Value; } else { gameConfigSettings.Add(attr.Name.ToString(), attr.Value); } } // read values from dictionary _smallBlindSize = Convert.ToInt32(gameConfigSettings["smallBlind"]); _bigBlindSize = Convert.ToInt32(gameConfigSettings["bigBlind"]); _startingStack = Convert.ToInt32(gameConfigSettings["startingStack"]); _maxNumRaisesPerBettingRound = Convert.ToInt32(gameConfigSettings["maxNumRaisesPerBettingRound"]); _maxHands = Convert.ToInt32(gameConfigSettings["maxHands"]); _doubleBlindFrequency = Convert.ToInt32(gameConfigSettings["doubleBlindFrequency"]); _botTimeOutMilliSeconds = Convert.ToInt32(gameConfigSettings["botTimeOutMilliSeconds"]); _bRandomDealer = Convert.ToBoolean(gameConfigSettings["randomDealer"]); _bRandomSeating = Convert.ToBoolean(gameConfigSettings["randomSeating"]); _bPauseAfterEachHand = Convert.ToBoolean(gameConfigSettings["pauseAfterEachHand"]); _sleepAfterActionMilliSeconds = Convert.ToInt32(gameConfigSettings["sleepAfterActionMilliSeconds"]); _bGraphicsDisplay = Convert.ToBoolean(gameConfigSettings["graphicsDisplay"]); // setup displays if (_bGraphicsDisplay) { //_displays.Add(new GraphicsDisplay()); _eventHandlers.Add(new ConsoleDisplayHandler()); } if (_sleepAfterActionMilliSeconds > 0) { _eventHandlers.Add(new SleepHandler(_sleepAfterActionMilliSeconds)); } var textDisplay = new TextDisplay(); textDisplay.SetWriteToConsole(!_bGraphicsDisplay); _displays.Add(textDisplay); var gameConfig = new GameConfig { ConfigFileName = sConfigFile, OutputBase = sOutputBase, SmallBlindSize = _smallBlindSize, BigBlindSize = _bigBlindSize, StartingStack = _startingStack, MaxNumRaisesPerBettingRound = _maxNumRaisesPerBettingRound, MaxHands = _maxHands, DoubleBlindFrequency = _doubleBlindFrequency, BotTimeOutMilliSeconds = _botTimeOutMilliSeconds, RandomDealer = _bRandomDealer, RandomSeating = _bRandomSeating }; // Create players var xplayers = doc.Descendants("Player").ToList(); int i; var numBots = xplayers.Count; if (numBots == 0) { throw new Exception("No Player elements found in HoldemConfig.xml"); } _allBots = new List <ServerHoldemPlayer>(); var playerConfigSettingsList = new List <Dictionary <string, string> >(); // Create bots - work out how many player and how many observers var botNum = 0; foreach (var player in xplayers) { var playerConfigSettings = player.Attributes().ToDictionary(attr => attr.Name.ToString(), attr => attr.Value); // read player attributes, add to player config string sValue; bool isTrusted = false; if (playerConfigSettings.TryGetValue("trusted", out sValue)) { Boolean.TryParse(sValue, out isTrusted); } playerConfigSettingsList.Add(playerConfigSettings); var bot = new ServerHoldemPlayer(botNum, playerConfigSettings["dll"], isTrusted); _allBots.Add(bot); botNum++; if (!bot.IsObserver) { _numPlayers++; } } if (_numPlayers < 2 || _numPlayers > 23) { throw new Exception($"The number of live (non observer) players found is {_numPlayers}. It must be between 2 and 23"); } // Create array to hold players (actual players not observers) _players = new ServerHoldemPlayer[_numPlayers]; var rnd = new Random(); List <int> unusedSlots = new List <int>(); for (i = 0; i < _numPlayers; i++) { unusedSlots.Add(i); } // assign id to each bot and call InitPlayer int nextObserverId = _numPlayers; int nextPlayerId = 0; botNum = 0; foreach (var bot in _allBots) { int botId; // work out player id if (bot.IsObserver) { botId = nextObserverId; nextObserverId++; } else { if (_bRandomSeating) { int pos = rnd.Next(unusedSlots.Count); botId = unusedSlots[pos]; unusedSlots.RemoveAt(pos); } else { botId = nextPlayerId; nextPlayerId++; } } // Need to ensure that playerId matches a players index in _players because some code is relying on this bot.InitPlayer(botId, gameConfig, playerConfigSettingsList[botNum]); // Just call this to preload Name and write entry to timing log // ReSharper disable once UnusedVariable var sName = bot.Name; // todo: properties shouldn't do anything, so should handle whatever this is doing differently botNum++; if (!bot.IsObserver) { _players[botId] = bot; } } foreach (var display in _displays) { display.Initialise(gameConfig, _numPlayers, _sleepAfterActionMilliSeconds); } }
// private static void WriteToSpace(int x, int y, string text, ConsoleColor? color = null, ConsoleColor? backgroundColor = null) // { // if (color != null) // { // Console.ForegroundColor = color.Value; // } // if (backgroundColor != null) // { // Console.BackgroundColor = backgroundColor.Value; // } // var items = text.Replace(Environment.NewLine, "`").Split('`'); // foreach (var item in items) // { // Console.SetCursorPosition(x, y); // Console.Write(item); // y++; // } // // this will reset both even if only one is probided, so probably best to store the original value, and reset it afterward // if (color != null || backgroundColor != null) // { // Console.ResetColor(); // } // Console.SetCursorPosition(0, 0); // } private void LoadConfig() { var doc = XDocument.Load("HoldemConfig.xml"); Logger.Log("--- *** CONFIG *** ---"); Logger.Log(doc.ToString()); var holdemConfig = doc.Element("HoldemConfig"); if (holdemConfig == null) { throw new Exception("Unable to find HoldemConfig element in HoldemConfig.xml"); } var gameRules = holdemConfig.Element("GameRules"); if (gameRules == null) { throw new Exception("Unable to find GameRules element in HoldemConfig.xml"); } // Get game rules Dictionary <string, string> gameConfigSettings = new Dictionary <string, string>(); // add defaults to dictionary gameConfigSettings.Add("littleBlind", _littleBlindSize.ToString()); gameConfigSettings.Add("bigBlind", _bigBlindSize.ToString()); gameConfigSettings.Add("startingStack", _startingStack.ToString()); gameConfigSettings.Add("maxNumRaisesPerBettingRound", _maxNumRaisesPerBettingRound.ToString()); gameConfigSettings.Add("maxHands", _maxHands.ToString()); gameConfigSettings.Add("doubleBlindFrequency", _doubleBlindFrequency.ToString()); gameConfigSettings.Add("botTimeOutMilliSeconds", _botTimeOutMilliSeconds.ToString()); // add or update values in dictionary from values in xml foreach (XAttribute attr in gameRules.Attributes()) { if (gameConfigSettings.ContainsKey(attr.Name.ToString())) { gameConfigSettings[attr.Name.ToString()] = attr.Value; } else { gameConfigSettings.Add(attr.Name.ToString(), attr.Value); } } // read values from dictionary _littleBlindSize = Convert.ToInt32(gameConfigSettings["littleBlind"]); _bigBlindSize = Convert.ToInt32(gameConfigSettings["bigBlind"]); _startingStack = Convert.ToInt32(gameConfigSettings["startingStack"]); _maxNumRaisesPerBettingRound = Convert.ToInt32(gameConfigSettings["maxNumRaisesPerBettingRound"]); _maxHands = Convert.ToInt32(gameConfigSettings["maxHands"]); _doubleBlindFrequency = Convert.ToInt32(gameConfigSettings["doubleBlindFrequency"]); _botTimeOutMilliSeconds = Convert.ToInt32(gameConfigSettings["botTimeOutMilliSeconds"]); // Create players var xplayers = doc.Descendants("Player"); int i = 0; int numLivePlayers = 0; _numPlayers = xplayers.Count(); if (_numPlayers == 0) { throw new Exception("No Player elements found in HoldemConfig.xml"); } _players = new ServerHoldemPlayer[_numPlayers]; foreach (var player in xplayers) { // copy game config settings to player config Dictionary <string, string> playerConfigSettings = new Dictionary <string, string>(gameConfigSettings); // read player attributes, add to player config or override game settings foreach (XAttribute attr in player.Attributes()) { if (playerConfigSettings.ContainsKey(attr.Name.ToString())) { playerConfigSettings[attr.Name.ToString()] = attr.Value; } else { playerConfigSettings.Add(attr.Name.ToString(), attr.Value); } } _players[i] = new ServerHoldemPlayer(i, playerConfigSettings); if (_players[i].IsAlive) { numLivePlayers++; } i++; } if (numLivePlayers < 2 || numLivePlayers > 23) { throw new Exception(String.Format("The number of live (non observer) players found is {0}. It must be between 2 and 23", numLivePlayers)); } }
private void LoadConfig() { var doc = XDocument.Load("HoldemConfig.xml"); Logger.Log("--- *** CONFIG *** ---"); Logger.Log(doc.ToString()); var holdemConfig = doc.Element("HoldemConfig"); if(holdemConfig == null) { throw new Exception("Unable to find HoldemConfig element in HoldemConfig.xml"); } var gameRules = holdemConfig.Element("GameRules"); if (gameRules == null) { throw new Exception("Unable to find GameRules element in HoldemConfig.xml"); } // Get game rules Dictionary<string, string> gameConfigSettings = new Dictionary<string, string>(); // add defaults to dictionary gameConfigSettings.Add("littleBlind", _littleBlindSize.ToString()); gameConfigSettings.Add("bigBlind", _bigBlindSize.ToString()); gameConfigSettings.Add("startingStack", _startingStack.ToString()); gameConfigSettings.Add("maxNumRaisesPerBettingRound", _maxNumRaisesPerBettingRound.ToString()); gameConfigSettings.Add("maxHands", _maxHands.ToString()); gameConfigSettings.Add("doubleBlindFrequency", _doubleBlindFrequency.ToString()); gameConfigSettings.Add("botTimeOutMilliSeconds", _botTimeOutMilliSeconds.ToString()); // add or update values in dictionary from values in xml foreach(XAttribute attr in gameRules.Attributes()) { if (gameConfigSettings.ContainsKey(attr.Name.ToString())) { gameConfigSettings[attr.Name.ToString()] = attr.Value; } else { gameConfigSettings.Add(attr.Name.ToString(), attr.Value); } } // read values from dictionary _littleBlindSize = Convert.ToInt32(gameConfigSettings["littleBlind"]); _bigBlindSize = Convert.ToInt32(gameConfigSettings["bigBlind"]); _startingStack = Convert.ToInt32(gameConfigSettings["startingStack"]); _maxNumRaisesPerBettingRound = Convert.ToInt32(gameConfigSettings["maxNumRaisesPerBettingRound"]); _maxHands = Convert.ToInt32(gameConfigSettings["maxHands"]); _doubleBlindFrequency = Convert.ToInt32(gameConfigSettings["doubleBlindFrequency"]); _botTimeOutMilliSeconds = Convert.ToInt32(gameConfigSettings["botTimeOutMilliSeconds"]); // Create players var xplayers = doc.Descendants("Player"); int i = 0; int numLivePlayers = 0; _numPlayers = xplayers.Count(); if(_numPlayers == 0) { throw new Exception("No Player elements found in HoldemConfig.xml"); } _players = new ServerHoldemPlayer[_numPlayers]; foreach (var player in xplayers) { // copy game config settings to player config Dictionary<string, string> playerConfigSettings = new Dictionary<string, string>(gameConfigSettings); // read player attributes, add to player config or override game settings foreach (XAttribute attr in player.Attributes()) { if(playerConfigSettings.ContainsKey(attr.Name.ToString())) { playerConfigSettings[attr.Name.ToString()] = attr.Value; } else { playerConfigSettings.Add(attr.Name.ToString(), attr.Value); } } _players[i] = new ServerHoldemPlayer(i, playerConfigSettings); if(_players[i].IsAlive) { numLivePlayers++; } i++; } if(numLivePlayers < 2 || numLivePlayers > 23) { throw new Exception(String.Format("The number of live (non observer) players found is {0}. It must be between 2 and 23", numLivePlayers)); } }
private void LoadConfig() { var doc = XDocument.Load("HoldemConfig.xml"); Logger.Log("--- *** CONFIG *** ---"); Logger.Log(doc.ToString()); var holdemConfig = doc.Element("HoldemConfig"); if(holdemConfig == null) { throw new Exception("Unable to find HoldemConfig element in HoldemConfig.xml"); } var gameRules = holdemConfig.Element("GameRules"); if (gameRules == null) { throw new Exception("Unable to find GameRules element in HoldemConfig.xml"); } // Get game rules if (gameRules.Attribute("littleBlind") != null) { _littleBlindSize = Convert.ToInt32(gameRules.Attribute("littleBlind").Value); } if (gameRules.Attribute("bigBlind") != null) { _bigBlindSize = Convert.ToInt32(gameRules.Attribute("bigBlind").Value); } if (gameRules.Attribute("startingStack") != null) { _startingStack = Convert.ToInt32(gameRules.Attribute("startingStack").Value); } if (gameRules.Attribute("maxNumRaisesPerBettingRound") != null) { _maxNumRaisesPerBettingRound = Convert.ToInt32(gameRules.Attribute("maxNumRaisesPerBettingRound").Value); } if (gameRules.Attribute("maxHands") != null) { maxHands = Convert.ToInt32(gameRules.Attribute("maxHands").Value); } if (gameRules.Attribute("doubleBlindFrequency") != null) { doubleBlindFrequency = Convert.ToInt32(gameRules.Attribute("doubleBlindFrequency").Value); } // Create players var xplayers = doc.Descendants("Player"); int i = 0; int numLivePlayers = 0; _numPlayers = xplayers.Count(); if(_numPlayers == 0) { throw new Exception("No Player elements found in HoldemConfig.xml"); } _players = new ServerHoldemPlayer[_numPlayers]; foreach (var player in xplayers) { var playersStartingStack = player.Attribute("startingStack") != null ? Convert.ToInt32(player.Attribute("startingStack").Value) : _startingStack; _players[i] = new ServerHoldemPlayer(i, playersStartingStack, player.Attribute("dll").Value); if(_players[i].IsAlive) { numLivePlayers++; } i++; } if(numLivePlayers < 2 || numLivePlayers > 23) { throw new Exception(String.Format("The number of live (non observer) players found is {0}. It must be between 2 and 23", numLivePlayers)); } }
private void LoadConfig() { XDocument doc = XDocument.Load("HoldemConfig.xml"); var gameRules = doc.Element("HoldemConfig").Element("GameRules"); // Get game rules littleBlindSize = Convert.ToInt32(gameRules.Attribute("littleBlind").Value); bigBlindSize = Convert.ToInt32(gameRules.Attribute("bigBlind").Value); startingStack = Convert.ToInt32(gameRules.Attribute("startingStack").Value); maxNumRaisesPerBettingRound = Convert.ToInt32(gameRules.Attribute("maxNumRaisesPerBettingRound").Value); // Create players var xplayers = doc.Descendants("Player"); int i = 0; numPlayers = xplayers.Count(); players = new ServerHoldemPlayer[numPlayers]; foreach (var player in xplayers) { Console.WriteLine(player.Value); players[i] = new ServerHoldemPlayer(i, startingStack, player.Attribute("dll").Value); i++; } }