Exemple #1
0
        private static void PlayGame(string[] args)
        {
            var botName = args[0];

            AILog.Log("PlayFFA", "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("PlayFFA", "Created game " + gameID);

            var settings = BotGameAPI.GetGameSettings(gameID);

            try
            {
                while (true)
                {
                    var game = BotGameAPI.GetGameInfo(gameID, null);
                    if (game.State == GameState.Finished)
                    {
                        AILog.Log("PlayFFA", "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);
            }
        }
Exemple #2
0
        /// <summary>
        /// Save it off in case we want to look at it later.  To look at it, go to https://www.warlight.net/Play, press Ctrl+Shift+E then click Import
        /// </summary>
        private static void ExportGame(GameIDType gameID, bool?weWon)
        {
            var export = BotGameAPI.ExportGame(gameID);
            var dir    = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "PlayAI");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            File.WriteAllText(Path.Combine(dir, gameID + (!weWon.HasValue ? "" : weWon.Value ? "_win" : "_loss") + ".txt"), export);
        }
Exemple #3
0
        /// <summary>
        /// Save it off in case we want to look at it later.  To look at it, go to https://www.warlight.net/Play, press Ctrl+Shift+E then click Import
        /// </summary>
        private static void ExportGame(GameIDType gameID)
        {
            var export = BotGameAPI.ExportGame(gameID);
            var dir    = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "PlayFFA");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            File.WriteAllText(Path.Combine(dir, gameID + ".txt"), export);
        }
        public static void Go(string[] args)
        {
            var botName    = args[0];
            var folder     = args[1];
            var gameID     = (GameIDType)int.Parse(args[2]);
            var playerID   = (PlayerIDType)int.Parse(args[3]);
            var turnNumber = args[4].ToLower() == "latest" ? (int?)null : int.Parse(args[4]) - 1;

            var details = BotGameAPI.GetBotExportedGame(gameID, ReadExported(folder, gameID), playerID, turnNumber);

            EntryPoint.PlayGame(botName, details.Item3, playerID, details.Item1, details.Item2, picks => { }, orders => { });
        }
Exemple #5
0
        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);
            }
        }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
 private static void GameFinished(GameIDType gameID)
 {
     ExportGame(gameID);
     BotGameAPI.DeleteGame(gameID);
 }
Exemple #8
0
        private static void PlayGame(List <string> bots, bool parallel)
        {
            AILog.Log("PlayBots", "Creating game...");
            var templateID = 1;
            var gameID     = BotGameAPI.CreateGame(Enumerable.Range(10, bots.Count).Select(o => PlayerInvite.Create((PlayerIDType)o, PlayerInvite.NoTeam, null)), "PlayBots", templateID, gameSettings =>
            {
                gameSettings["MaxCardsHold"]      = 999;
                gameSettings["ReinforcementCard"] = "none";
                //gameSettings["Fog"] = GameFogLevel.NoFog.ToString();
                //gameSettings["Fog"] = GameFogLevel.ModerateFog.ToString();
                //gameSettings["Fog"] = GameFogLevel.ExtremeFog.ToString();
                //gameSettings["OneArmyStandsGuard"] = false;
                //ZeroAllBonuses(gameSettings);
                //gameSettings["Map"] = 16114; //Rise of Rome -- use to test how bots respond to super bonuses
                //gameSettings["Map"] = 24591; //big USA, 3066 territories
                //gameSettings["MultiAttack"] = true;
                //gameSettings["AllowPercentageAttacks"] = false;
                //gameSettings["AllowAttackOnly"] = false;
                //gameSettings["AllowTransferOnly"] = false;

                //var wastelands = new JObject();
                //wastelands["NumberOfWastelands"] = 0;
                //wastelands["WastelandSize"] = 10;
                //gameSettings["Wastelands"] = wastelands;
                //gameSettings["BombCard"] = new JObject(new JProperty("InitialPieces", 0), new JProperty("MinimumPiecesPerTurn", 1), new JProperty("NumPieces", 4), new JProperty("Weight", 1));
                //gameSettings["SanctionsCard"] = new JObject(new JProperty("InitialPieces", 0), new JProperty("MinimumPiecesPerTurn", 1), new JProperty("NumPieces", 4), new JProperty("Weight", 1), new JProperty("Duration", 1), new JProperty("Percentage", 0.5));
                //gameSettings["BlockadeCard"] = new JObject(new JProperty("InitialPieces", 50), new JProperty("MinimumPiecesPerTurn", 1), new JProperty("NumPieces", 1), new JProperty("Weight", 1), new JProperty("MultiplyAmount", 10));
                //gameSettings["DiplomacyCard"] = new JObject(new JProperty("InitialPieces", 0), new JProperty("MinimumPiecesPerTurn", 1), new JProperty("NumPieces", 1), new JProperty("Weight", 1), new JProperty("Duration", 1));
                //gameSettings["NumberOfCardsToReceiveEachTurn"] = 4;
            });

            AILog.Log("PlayBots", "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 (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);
            }
        }
Exemple #9
0
        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);
            }
        }