コード例 #1
0
        public static Tuple <int, GameState> GetGameStatus(GameIDType gameID)
        {
            var gidNode  = new JObject(new JProperty("gameID", (int)gameID));
            var response = Communication.Call("GetGameStatus", gidNode);

            return(new Tuple <int, GameState>((int)response["turnNumber"], (GameState)(int)response["gameState"]));
        }
コード例 #2
0
        public static void AcceptGame(GameIDType gameID)
        {
            var input    = new JObject(new JProperty("gameID", (int)gameID));
            var response = Communication.Call("AcceptGame", input);

            Assert.Fatal(response["success"] != null);
        }
コード例 #3
0
        public static void PlayForTurn(string botName, GameIDType gameID, int playForTurn)
        {
            AILog.Log("PlayHuman", "Generating orders for game " + gameID + " turn " + playForTurn);
            var settings = HumanGameAPI.GetGameSettings(gameID);
            var game     = HumanGameAPI.GetGameInfo(gameID, playForTurn);

            EntryPoint.PlayGame(botName, game, MeID, settings.Item1, settings.Item2, picks => { }, orders => { });
        }
コード例 #4
0
        public static void SendPicks(GameIDType gameID, IEnumerable <TerritoryIDType> picks)
        {
            var input = new JObject(new JProperty("gameID", (int)gameID));

            input.Add("territoryIDs", new JArray(picks.Select(o => (int)o)));
            var response = Communication.Call("SendPicks", input);

            Assert.Fatal(response["success"] != null);
        }
コード例 #5
0
ファイル: BotGameAPI.cs プロジェクト: Norman1/Multiattack-Bot
        public static Tuple <GameSettings, MapDetails> GetGameSettings(GameIDType gameID)
        {
            var gidNode  = new JObject(new JProperty("gameID", (int)gameID));
            var response = Communication.Call("GetBotGameSettings", gidNode);

            var settings = Communication.ReadSettings(response["settings"]);
            var map      = Communication.ReadMap(response["map"]);

            return(new Tuple <GameSettings, MapDetails>(settings, map));
        }
コード例 #6
0
ファイル: PlayFFA.cs プロジェクト: Norman1/Multiattack-Bot
        /// <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);
        }
コード例 #7
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);
        }
コード例 #8
0
        public static void PlayLoop(string botName, GameIDType gameID, PlayerIDType playerID)
        {
            var settings = HumanGameAPI.GetGameSettings(gameID);

            int  turnNumber    = int.MinValue;
            bool checkedAccept = false;

            while (true)
            {
                var status = HumanGameAPI.GetGameStatus(gameID);
                if (status.Item2 == GameState.WaitingForPlayers)
                {
                    if (!checkedAccept)
                    {
                        var game = HumanGameAPI.GetGameInfo(gameID, null);
                        if (game.Players[playerID].State == GamePlayerState.Invited)
                        {
                            AILog.Log("PlayHuman", "Accepting invite...");
                            HumanGameAPI.AcceptGame(gameID);
                            AILog.Log("PlayHuman", "Accepted invite");
                        }

                        checkedAccept = true;
                    }
                }
                else if (status.Item2 == GameState.Finished)
                {
                    AILog.Log("PlayHuman", "Game finished");
                    break;
                }
                else if (status.Item1 > turnNumber)
                {
                    var game = HumanGameAPI.GetGameInfo(gameID, null);

                    if (!EntryPoint.PlayGame(botName, game, MeID, settings.Item1, settings.Item2, picks =>
                    {
                        HumanGameAPI.SendPicks(game.ID, picks);
                        AILog.Log("PlayHuman", "Sent picks");
                    }, orders =>
                    {
                        HumanGameAPI.SendOrders(game.ID, orders, game.NumberOfTurns + 1);
                        AILog.Log("PlayHuman", "Sent orders");
                    }))
                    {
                        AILog.Log("PlayHuman", "We're no longer alive");
                        break;
                    }
                    turnNumber = status.Item1;
                }

                Thread.Sleep(10000);
            }
        }
コード例 #9
0
        public static GameObject GetGameInfo(GameIDType gameID, int?turnNumber)
        {
            var input = new JObject();

            input["gameID"] = (int)gameID;

            if (turnNumber.HasValue)
            {
                input["turnNumber"] = turnNumber.Value;
            }

            var response = Communication.Call("GetGameInfo", input);

            return(Communication.ReadGameObject(response, gameID));
        }
コード例 #10
0
ファイル: BotGameAPI.cs プロジェクト: Norman1/Multiattack-Bot
        public static GameObject GetGameInfo(GameIDType gameID, PlayerIDType?playerID)
        {
            var input = new JObject();

            input["gameID"] = (int)gameID;

            if (playerID.HasValue)
            {
                input["playerID"] = (int)playerID.Value;
            }

            var response = Communication.Call("GetBotGameInfo", input);

            return(Communication.ReadGameObject(response, gameID));
        }
コード例 #11
0
        public static void SendOrders(GameIDType gameID, IEnumerable <GameOrder> orders, int turnNumber)
        {
            var ordersArray = new JArray();

            foreach (var order in orders)
            {
                var jOrder = new JObject();
                Communication.WriteOrder(jOrder, order);
                ordersArray.Add(jOrder);
            }
            var input = new JObject();

            input["gameID"]     = (int)gameID;
            input["orders"]     = ordersArray;
            input["turnNumber"] = turnNumber;

            var response = Communication.Call("SendOrders", input);

            Assert.Fatal(response["success"] != null);
        }
コード例 #12
0
        public static GameObject ReadGameObject(JToken response, GameIDType gameID)
        {
            var ret = new GameObject();

            var gameNode = response["game"];

            ret.ID            = gameID;
            ret.NumberOfTurns = (int)gameNode["numberOfTurns"];
            ret.State         = (GameState)Enum.Parse(typeof(GameState), (string)gameNode["state"]);
            ret.Players       = ((JArray)gameNode["players"]).Select(Communication.ReadGamePlayer).ToDictionary(o => o.ID, o => o);

            var gameInfo = response["gameInfo"];

            if (gameInfo != null && gameInfo.Type == JTokenType.Object)
            {
                ret.LatestInfo = Communication.ReadLatestInfo(gameInfo);
            }

            return(ret);
        }
コード例 #13
0
        public static string ReadExported(string folder, GameIDType gameID)
        {
            var dir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), folder);

            return(File.ReadAllText(Path.Combine(dir, Directory.GetFiles(dir, gameID + "*.txt").Single())));
        }
コード例 #14
0
ファイル: PlayFFA.cs プロジェクト: Norman1/Multiattack-Bot
 private static void GameFinished(GameIDType gameID)
 {
     ExportGame(gameID);
     BotGameAPI.DeleteGame(gameID);
 }
コード例 #15
0
ファイル: BotGameAPI.cs プロジェクト: Norman1/Multiattack-Bot
        public static void DeleteGame(GameIDType gameID)
        {
            var gidNode = new JObject(new JProperty("gameID", (int)gameID));

            Communication.Call("DeleteBotGame", gidNode);
        }
コード例 #16
0
ファイル: BotGameAPI.cs プロジェクト: Norman1/Multiattack-Bot
        public static Tuple <GameSettings, MapDetails, GameObject> GetBotExportedGame(GameIDType gameID, string exportedGame, PlayerIDType playerID, int?turnNumber)
        {
            var input = new JObject();

            input["exportedGame"] = exportedGame;
            input["playerID"]     = (int)playerID;

            if (turnNumber.HasValue)
            {
                input["turnNumber"] = turnNumber;
            }

            var response = Communication.Call("GetBotExportedGameInfo", input);

            var game     = Communication.ReadGameObject(response, gameID);
            var settings = Communication.ReadSettings(response["settings"]);
            var map      = Communication.ReadMap(response["map"]);

            return(new Tuple <GameSettings, MapDetails, GameObject>(settings, map, game));
        }
コード例 #17
0
ファイル: BotGameAPI.cs プロジェクト: Norman1/Multiattack-Bot
        public static string ExportGame(GameIDType gameID)
        {
            var gidNode = new JObject(new JProperty("gameID", (int)gameID));

            return((string)Communication.Call("ExportBotGame", gidNode)["result"]);
        }