From 598734beb7d6fd13dde826ba7f3499ab943e7db7 Mon Sep 17 00:00:00 2001 From: Alexander Zheltov Date: Sun, 18 Aug 2019 12:53:33 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=20VisioPlayer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MiniAiCup.Paperio.VisioPlayer/Program.cs | 30 +++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/MiniAiCup.Paperio.VisioPlayer/Program.cs b/MiniAiCup.Paperio.VisioPlayer/Program.cs index 407b781..94ed9a1 100644 --- a/MiniAiCup.Paperio.VisioPlayer/Program.cs +++ b/MiniAiCup.Paperio.VisioPlayer/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; @@ -15,10 +16,29 @@ static void Main(string[] args) const int myPlayerIndex = 1; const int startTickNumber = 1; const string visioPath = "..\\..\\..\\..\\MiniAiCup.Paperio.Client\\bin\\Debug\\visio.gz"; - string json = Decompress(visioPath); + string json = visioPath.EndsWith(".gz") + ? Decompress(visioPath) + : File.ReadAllText(visioPath); + var jData = (JArray)JObject.Parse(json)["visio_info"]; - var gameStates = jData.Where(x => (string)x["type"] == "tick").Select(x => ParseGameState((JObject)x, myPlayerIndex)); + var prevDirections = new Dictionary(6); + + var gameStates = jData.Where(x => (string)x["type"] == "tick").Select(x => { + var state = ParseGameState((JObject)x, myPlayerIndex); + foreach (var player in state.Players) + { + if (!prevDirections.ContainsKey(player.Id)) + { + prevDirections.Add(player.Id, null); + } + var dir = player.Direction; + player.Direction = prevDirections[player.Id]; + prevDirections[player.Id] = dir; + } + + return state; + }); var decisionGameStates = gameStates.Where(IsDecisionState); Game.Initialize(); @@ -37,9 +57,7 @@ private static bool IsDecisionState(GameState state) return false; } - const int cellSize = 30; - - return (me.Position.X + cellSize/2)%cellSize == 0 && (me.Position.Y + cellSize/2)%cellSize == 0; + return (me.Position.X + GameParams.CellSize/2)%GameParams.CellSize == 0 && (me.Position.Y + GameParams.CellSize/2)%GameParams.CellSize == 0; } public static GameState ParseGameState(JObject jParams, int myPlayerIndex) @@ -61,7 +79,7 @@ private static BonusInfo ParseBonus(JObject jBonus) private static PlayerInfo ParsePlayer(JProperty jIdentityPlayer, int myPlayerIndex) { - string id = jIdentityPlayer.Name == myPlayerIndex.ToString() ? "i" : jIdentityPlayer.Name; + string id = jIdentityPlayer.Name == myPlayerIndex.ToString() ? Constants.MyId : jIdentityPlayer.Name; var jPlayer = jIdentityPlayer.Value; return new PlayerInfo { Id = id,