/// <summary> /// Add single region, no double entries /// </summary> /// <param name="region">region</param> public void AddRegion(Region region) { if (!this.regions.Contains(region)) { this.regions.Add(region); } }
/// <summary> /// Add SuperRegion (setup_map super_regions) /// </summary> /// <param name="superRegion">SuperRegion</param> public void AddPath(Region regionFrom, Region regionTo) { paths.Add(new Path(regionFrom, regionTo)); paths.Add(new Path(regionTo, regionFrom)); regionFrom.AddNeighbour(regionTo); regionTo.AddNeighbour(regionFrom); }
public PlaceArmies(int armies, Region region) { Armies = armies; Region = region; }
public void Parse(String line) { String[] parts = line.Split(' '); switch (parts[0].ToLowerInvariant()) { // settings case "go": switch (parts[1].ToLowerInvariant()) { case "place_armies": Console.WriteLine(Go.Place_Armies()); break; case "attack/transfer": Console.WriteLine(Go.Attack_Transfer()); break; default: // EXCEPTION break; } break; // settings case "settings": switch (parts[1].ToLowerInvariant()) { case "starting_armies": BotState.GetInstance().StartingArmies = int.Parse(parts[2]); break; case "your_bot": PLAYER.NameMe = parts[2]; break; case "opponent_bot": PLAYER.NameOther = parts[2]; break; default: // EXCEPTION break; } break; case "update_map": // Reset values Map.GetInstance().ResetTurn(); // Read no situation for (int i = 1; i < parts.Length; i++) { try { Map.GetInstance().Region(int.Parse(parts[i++])).UpdateMap(PLAYER.GetPlayer(parts[i++]), int.Parse(parts[i])); } catch (Exception e) { Console.WriteLine("ERROR: Unable to parse update_map"); Console.WriteLine("Msg: " + e.Message); } } // Calculate map Map.GetInstance().CalcTurn(); break; case "pick_starting_regions": Map.GetInstance().CalculateInitial(); int[] regionsoffered = parts.Skip(2).Select(p => int.Parse(p)).ToArray(); int[] fav = Map.GetFavorites().Intersect(regionsoffered).ToArray(); Console.WriteLine(string.Join(" ", fav.Take(6).Select(x => x.ToString()).ToArray())); break; // setup_map case "setup_map": switch (parts[1].ToLowerInvariant()) { case "super_regions": for (int i = 2; i < parts.Length; i++) { try { int superRegionId = int.Parse(parts[i]); i++; int reward = int.Parse(parts[i]); Map.GetInstance().AddSuperRegion(new SuperRegion(superRegionId, reward)); } catch (Exception e) { Console.WriteLine("ERROR: Unable to parse SuperRegions"); Console.WriteLine("Msg: " + e.Message); } } break; case "regions": for (int i = 2; i < parts.Length; i++) { try { int regionId = int.Parse(parts[i++]); SuperRegion superRegion = Map.GetInstance().GetSuperRegion(int.Parse(parts[i])); // Create new Region Region newRegion = new Region(regionId, superRegion); // Add Region to Map en SuperRegion Map.GetInstance().AddRegion(newRegion); superRegion.AddRegion(newRegion); } catch (Exception e) { Console.WriteLine("ERROR: Unable to parse Regions"); Console.WriteLine("Msg: " + e.Message); } } break; case "neighbors": for (int i = 2; i < parts.Length; i++) { try { Region region = Map.GetInstance().Region(int.Parse(parts[i++])); foreach (String neighbourStr in parts[i].Split(',')) { Region neighbour = Map.GetInstance().Region(int.Parse(neighbourStr)); Map.GetInstance().AddPath(region, neighbour); } } catch (Exception e) { Console.WriteLine("ERROR: Unable to parse Regions"); Console.WriteLine("Msg: " + e.Message); } } break; default: // EXCEPTION break; } break; default: // EXCEPTION break; } }
public AttackTransfer(int armies, Region sourceRegion, Region targetRegion) { this.Armies = armies; this.SourceRegion = sourceRegion; this.TargetRegion = targetRegion; }
public static void AddPlaceArmies(Region region, int armies) { Commands.Add(PLAYER.NameMe + " place_armies " + region.Id.ToString() + " " + armies.ToString()); region.AddArmies(armies); BotState.GetInstance().StartingArmies -= armies; }
private static void AddAttackTransfer(Region SourceRegion, Region TargetRegion, int armies) { Commands.Add(PLAYER.NameMe + " attack/transfer " + SourceRegion.Id.ToString() + " " + TargetRegion.Id.ToString() + " " + armies.ToString()); SourceRegion.AddArmies(-armies); }
/// <summary> /// Connection between 2 regions (for Risk 2 x 82 = 164) /// </summary> /// <param name="regionFrom">Region</param> /// <param name="regionTo">Region</param> public Path(Region regionFrom, Region regionTo) { this.regionFrom = regionFrom; this.regionTo = regionTo; }
/// <summary> /// Add neighbour /// </summary> /// <param name="neighbour">Region</param> public void AddNeighbour(Region neighbour) { neighbours.AddRegion(neighbour); }