public static void PlayGame(string botName) { var players = new[] { PlayerInvite.Create(MeID, PlayerInvite.NoTeam, null), PlayerInvite.Create("*****@*****.**", PlayerInvite.NoTeam, null) }; AILog.Log("StressTest", "Creating game..."); var gameID = BotGameAPI.CreateGame(players, "AI Competition", null, gameSettings => { gameSettings["MaxCardsHold"] = 999; gameSettings["Map"] = 52545; //53822; //hex earth, 3200 territories //gameSettings["Map"] = 24591; //big USA, 3066 territories //gameSettings["Map"] = 42717; //thirty years war, 2264 territories //gameSettings["Map"] = 34083; //Africa big, 1544 territories gameSettings["DistributionMode"] = 0; //full dist gameSettings["TerritoryLimit"] = 0; //terr limit gameSettings["MultiAttack"] = true; gameSettings["AllowPercentageAttacks"] = true; //gameSettings["AutomaticTerritoryDistribution"] = "Automatic"; //skip picking, if you're only looking to optimize orders }); var settings = BotGameAPI.GetGameSettings(gameID); try { while (true) { var game = BotGameAPI.GetGameInfo(gameID, MeID); if (game.State == GameState.Finished || game.NumberOfTurns >= 2) { break; } if (!EntryPoint.PlayGame(botName, game, MeID, settings.Item1, settings.Item2, picks => BotGameAPI.SendPicks(game.ID, MeID, picks), orders => BotGameAPI.SendOrders(game.ID, MeID, orders, game.NumberOfTurns + 1))) { break; } Thread.Sleep(100); } } finally { ExportGame(gameID); BotGameAPI.DeleteGame(gameID); } }
public static void PlayGame(string botName) { var players = new[] { PlayerInvite.Create(MeID, (TeamIDType)3, null) }.Concat(Enumerable.Range(0, 6).Select(o => PlayerInvite.Create("*****@*****.**", (TeamIDType)(o % 2), null))); AILog.Log("PlayAI", "Creating game..."); var gameID = BotGameAPI.CreateGame(players, "Crazy Challenge", 16, gameSettings => { gameSettings["MaxCardsHold"] = 999; gameSettings["Fog"] = "NoFog"; }); AILog.Log("PlayAI", "Created game " + gameID); var settings = BotGameAPI.GetGameSettings(gameID); bool?weWon = null; try { while (true) { var game = BotGameAPI.GetGameInfo(gameID, MeID); if (game.State == GameState.Finished) { weWon = GameFinished(game); break; } if (!EntryPoint.PlayGame(botName, game, MeID, settings.Item1, settings.Item2, picks => BotGameAPI.SendPicks(game.ID, MeID, picks), orders => BotGameAPI.SendOrders(game.ID, MeID, orders, game.NumberOfTurns + 1))) { weWon = GameFinished(game); break; } Thread.Sleep(100); } } finally { ExportGame(gameID, weWon); BotGameAPI.DeleteGame(gameID); } }
private static void GameFinished(GameIDType gameID) { ExportGame(gameID); BotGameAPI.DeleteGame(gameID); }
static void PlayGame(string botName, string opponent, int threadNum, int gameNum) { var usID = (PlayerIDType)10; var oppID = (PlayerIDType)11; var invite = new List <PlayerInvite>(); invite.Add(PlayerInvite.Create(usID, PlayerInvite.NoTeam, null)); if (opponent == AIBotIdentifier) { invite.Add(PlayerInvite.Create("*****@*****.**", PlayerInvite.NoTeam, null)); } else { invite.Add(PlayerInvite.Create(oppID, PlayerInvite.NoTeam, null)); } AILog.Log("Compete", "Creating game..."); var gameID = BotGameAPI.CreateGame(invite, "Compete", null, gameSettings => { gameSettings["MaxCardsHold"] = 999; gameSettings["ReinforcementCard"] = "none"; }); AILog.Log("Compete", "Created game " + gameID); var settings = BotGameAPI.GetGameSettings(gameID); var game = BotGameAPI.GetGameInfo(gameID, null); bool?won = null; try { while (true) { game = BotGameAPI.GetGameInfo(gameID, null); if (game.State == GameState.Finished) { won = game.Players.Values.Single(o => o.State == GamePlayerState.Won).ID == usID; _botStats.GetOrAdd(opponent, _ => new Stats()).Record(won.Value); Console.WriteLine("T" + threadNum.ToString("00") + " G" + gameNum.ToString("00") + ": " + (won.Value ? "Won " : "Lost") + " game vs " + opponent + " " + gameID + " finished. Totals: " + _botStats.OrderBy(o => o.Key).Select(o => o.Key + "=" + o.Value).JoinStrings(", ")); break; } //Play ourselves var pg = BotGameAPI.GetGameInfo(gameID, usID); EntryPoint.PlayGame(botName, pg, usID, settings.Item1, settings.Item2, picks => BotGameAPI.SendPicks(pg.ID, usID, picks), orders => BotGameAPI.SendOrders(pg.ID, usID, orders, pg.NumberOfTurns + 1)); //Play opponent if (opponent != AIBotIdentifier) { pg = BotGameAPI.GetGameInfo(gameID, oppID); EntryPoint.PlayGame(opponent, pg, oppID, settings.Item1, settings.Item2, picks => BotGameAPI.SendPicks(pg.ID, oppID, picks), orders => BotGameAPI.SendOrders(pg.ID, oppID, orders, pg.NumberOfTurns + 1)); } Thread.Sleep(100); } } finally { ExportGame(gameID, opponent, won); BotGameAPI.DeleteGame(gameID); } }