Ejemplo n.º 1
0
        /// <summary>
        /// Returns a copy of this map and all of its contents, with new instances of each object (Map, SuperRegions, Regions).
        /// </summary>
        /// <returns></returns>
        public Map GetMapCopy()
        {
            Map newMap = new Map();

            foreach (SuperRegion sr in SuperRegions)
            {
                SuperRegion newSuperRegion = new SuperRegion(sr.ID, sr.ArmiesReward);
                newMap.AddSuperRegion(newSuperRegion);
            }

            foreach (Region r in Regions)
            {
                Region newRegion = new Region(r.ID, newMap.GetSuperRegionByID(r.SuperRegion.ID), r.PlayerName, r.Armies);
                newMap.AddRegion(newRegion);
            }

            foreach (Region r in Regions) 
            {
                Region newRegion = newMap.GetRegionByID(r.ID);
                foreach (Region neighbor in r.Neighbors)
                {
                    newRegion.AddNeighbor(newMap.GetRegionByID(neighbor.ID));
                }
            }

            return newMap;
        }
Ejemplo n.º 2
0
        public static List<Move> ParseMoves(Map fullMap, string line)
        {
            var result = new List<Move>();
            var moveInput = InputParser.Split(line);
            for (int i = 1; i < moveInput.Length; i++)
            {
                try
                {
                    Move move;
                    if (moveInput[i + 1].Equals("place_armies"))
                    {
                        Region region = fullMap.GetRegionByID(int.Parse(moveInput[i + 2]));
                        String playerName = moveInput[i];
                        int armies = int.Parse(moveInput[i + 3]);
                        move = new PlaceArmiesMove(playerName, region, armies);
                        i += 3;
                    }
                    else if (moveInput[i + 1].Equals("attack/transfer"))
                    {
                        Region fromRegion = fullMap.GetRegionByID(int.Parse(moveInput[i + 2]));
                        Region toRegion = fullMap.GetRegionByID(int.Parse(moveInput[i + 3]));

                        String playerName = moveInput[i];
                        int armies = int.Parse(moveInput[i + 4]);
                        move = new AttackTransferMove(playerName, fromRegion, toRegion, toRegion, armies, MoveReason.Unknown);
                        i += 4;
                    }
                    else
                    {
                        // Should never happen.
                        continue;
                    }

                    result.Add(move);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Unable to parse moves: " + ex);
                }
            }

            return result;
        }
Ejemplo n.º 3
0
        public static void ParseMapInfo(Map map, string[] mapInput)
        {
            int i, regionId, superRegionId, reward;

            if (mapInput[1].Equals("super_regions"))
            {
                for (i = 2; i < mapInput.Length; i++)
                {
                    try
                    {
                        superRegionId = int.Parse(mapInput[i]);
                        i++;
                        reward = int.Parse(mapInput[i]);
                        map.AddSuperRegion(new SuperRegion(superRegionId, reward));
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Unable to parse SuperRegions: " + ex);
                    }
                }
            }
            else if (mapInput[1].Equals("regions"))
            {
                for (i = 2; i < mapInput.Length; i++)
                {
                    try
                    {
                        regionId = int.Parse(mapInput[i]);
                        i++;
                        superRegionId = int.Parse(mapInput[i]);
                        SuperRegion superRegion = map.GetSuperRegionByID(superRegionId);
                        map.AddRegion(new Region(regionId, superRegion, "neutral", 2));
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Unable to parse Regions: " + ex);
                    }
                }
            }
            else if (mapInput[1].Equals("neighbors"))
            {
                for (i = 2; i < mapInput.Length; i++)
                {
                    try
                    {
                        Region region = map.GetRegionByID(int.Parse(mapInput[i]));
                        i++;
                        String[] neighborIds = mapInput[i].Split(',');
                        for (int j = 0; j < neighborIds.Length; j++)
                        {
                            Region neighbor = map.GetRegionByID(int.Parse(neighborIds[j]));
                            region.AddNeighbor(neighbor);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("Unable to parse Neighbors: " + ex);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses the `pick_starting_regions $timeout $id{12}` line and returns a list of Regions from the FullMap the bot can choose from.
        /// </summary>
        /// <param name="pickStartingRegionsLineParts"></param>
        private static List<Region> GetPickableStartingRegions(Map map, string[] pickStartingRegionsLineParts)
        {
            var pickableStartingRegions = new List<Region>();

            for (int i = 2; i < pickStartingRegionsLineParts.Length; i++)
            {
                int regionId;
                try
                {
                    regionId = int.Parse(pickStartingRegionsLineParts[i]);
                    Region pickableRegion = map.GetRegionByID(regionId);
                    pickableStartingRegions.Add(pickableRegion);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Unable to parse pickable regions: " + ex);
                }
            }

            return pickableStartingRegions;
        }
Ejemplo n.º 5
0
 public GameState()
 {
     OpponentName = "";
     RoundNumber = 0;
     FullMap = new Map();
 }