private static void PlayGame(string[] args) { var botName = args[0]; AILog.Log("Creating game..."); var gameID = BotGameAPI.CreateGame(Enumerable.Range(10, 6).Select(o => PlayerInvite.Create((PlayerIDType)o, PlayerInvite.NoTeam, null)), "PlayFFA", null, gameSettings => //var gameID = BotGameAPI.CreateGame(Enumerable.Range(10, 6).Select(o => PlayerInvite.Create((PlayerIDType)o, (TeamIDType)(o == 0 ? 0 : 1), (SlotType)o)), "PlayFFA", 17, gameSettings => { //gameSettings["DistributionMode"] = 0; //full distribution, so we have plenty of starting territories //gameSettings["InitialNeutralsInDistribution"] = 2; //since we're full distribution, most territories an in-distribution one so we want them to start with 2s not 4s gameSettings["MaxCardsHold"] = 999; //gameSettings["AutomaticTerritoryDistribution"] = "Automatic"; }); AILog.Log("Created game " + gameID); var settings = BotGameAPI.GetGameSettings(gameID); try { while (true) { var game = BotGameAPI.GetGameInfo(gameID, null); if (game.State == GameState.Finished) { AILog.Log("Game finished: " + gameID); break; } var players = game.Players.Values.Where(o => o.State == GamePlayerState.Playing).ToList(); Action <GamePlayer> play = player => { var pg = BotGameAPI.GetGameInfo(gameID, player.ID); EntryPoint.PlayGame(botName, pg, player.ID, settings.Item1, settings.Item2, picks => BotGameAPI.SendPicks(pg.ID, player.ID, picks), orders => BotGameAPI.SendOrders(pg.ID, player.ID, orders, pg.NumberOfTurns + 1)); }; if (args.Any(o => o.ToLower() == "parallel")) //note: Parallel won't work when teammates, cards, and limited holding cards are involved. { players.AsParallel().ForAll(play); } else { players.ForEach(play); } Thread.Sleep(100); } } finally { GameFinished(gameID); } }
private static void PlayGame(string[] args) { var bots = args; AILog.Log("Creating game..."); var gameID = BotGameAPI.CreateGame(Enumerable.Range(10, bots.Length).Select(o => PlayerInvite.Create((PlayerIDType)o, PlayerInvite.NoTeam, null)), "PlayBots", null, gameSettings => { gameSettings["Fog"] = "NoFog"; //turn off fog so we can see what the AI is doing gameSettings["MaxCardsHold"] = 999; gameSettings["ReinforcementCard"] = "none"; }); AILog.Log("Created game " + gameID); var settings = BotGameAPI.GetGameSettings(gameID); var game = BotGameAPI.GetGameInfo(gameID, null); var botsDict = game.Players.Values.Zip(bots, (gp, bot) => new { Player = gp, Bot = bot }).ToDictionary(o => o.Player.ID, o => o.Bot); try { while (true) { game = BotGameAPI.GetGameInfo(gameID, null); if (game.State == GameState.Finished) { var winnerStr = game.Players.Values.Where(o => o.State == GamePlayerState.Won).Select(o => botsDict[o.ID]).JoinStrings(","); _totals.AddOrUpdate(winnerStr, 1, (_, i) => i + 1); Console.WriteLine("Game " + gameID + " finished. Winner=" + winnerStr + ", totals: " + _totals.OrderByDescending(o => o.Value).Select(o => o.Key + "=" + o.Value).JoinStrings(", ")); break; } var players = game.Players.Values.Where(o => o.State == GamePlayerState.Playing).ToList(); Action <GamePlayer> play = player => { var pg = BotGameAPI.GetGameInfo(gameID, player.ID); EntryPoint.PlayGame(botsDict[player.ID], pg, player.ID, settings.Item1, settings.Item2, picks => BotGameAPI.SendPicks(pg.ID, player.ID, picks), orders => BotGameAPI.SendOrders(pg.ID, player.ID, orders, pg.NumberOfTurns + 1)); }; if (args.Any(o => o.ToLower() == "parallel")) //note: Parallel won't work when teammates, cards, and limited holding cards are involved. { players.AsParallel().ForAll(play); } else { players.ForEach(play); } Thread.Sleep(100); } } finally { GameFinished(gameID); } }
private static void PlayGame(string botName, int numOpponents) { var players = new[] { PlayerInvite.Create(MeID, (TeamIDType)1, null) }.Concat(Enumerable.Range(0, numOpponents).Select(o => PlayerInvite.Create("*****@*****.**", (TeamIDType)2, null))); AILog.Log("Creating game..."); var gameID = BotGameAPI.CreateGame(players, "AI Competition", null, gameSettings => gameSettings["MaxCardsHold"] = 999); AILog.Log("Created game " + gameID); var settings = BotGameAPI.GetGameSettings(gameID); try { while (true) { var game = BotGameAPI.GetGameInfo(gameID, MeID); if (game.State == GameState.Finished) { 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))) { GameFinished(game); break; } Thread.Sleep(100); } } finally { ExportGame(gameID); BotGameAPI.DeleteGame(gameID); } }