/// <summary> /// Call once at the start of a game to load the map and player tag from the first four stdin lines. /// </summary> public static Map getInit(out ushort playerTag) { HelperLog.AppendLog("Get Init."); // Line 1: Player tag if (!ushort.TryParse(ReadNextLine(), out playerTag)) { throw new ApplicationException("Could not get player tag from stdin during init"); } // Lines 2-4: Map var map = Map.ParseMap(ReadNextLine(), ReadNextLine(), ReadNextLine()); return(map); }
public static Map ParseMap(string mapSizeStr, string productionMapStr, string gameMapStr) { HelperLog.AppendLog("map size: " + mapSizeStr); HelperLog.AppendLog("production map: " + productionMapStr); HelperLog.AppendLog("game map: " + gameMapStr); var mapSize = ParseMapSize(mapSizeStr); var map = new Map(mapSize.Item1, mapSize.Item2); var productionValues = new Queue <string>(productionMapStr.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ushort x, y; for (y = 0; y < map.Height; y++) { for (x = 0; x < map.Width; x++) { ushort production; if (!ushort.TryParse(productionValues.Dequeue(), out production)) { throw new ApplicationException("Could not get some production value from stdin"); } map._sites[x, y].Production = production; if (x == 0 && y == 0) { HelperLog.AppendLog("found production value " + production); HelperLog.AppendLog("set production value " + map._sites[x, y].Production); } } } map.Update(gameMapStr); return(map); }
/// <summary> /// Call every frame to update the map to the next one provided by the environment. /// </summary> public static void getFrame(ref Map map) { HelperLog.AppendLog("Get Frame"); map.Update(ReadNextLine()); }