예제 #1
0
 /// <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);
     }
 }
예제 #2
0
파일: Map.cs 프로젝트: Bolukan/TweakBot
 /// <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);
 }
예제 #3
0
 public PlaceArmies(int armies, Region region)
 {
     Armies = armies;
     Region = region;
 }
예제 #4
0
        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;

            }
        }
예제 #5
0
 public AttackTransfer(int armies, Region sourceRegion, Region targetRegion)
 {
     this.Armies = armies;
     this.SourceRegion = sourceRegion;
     this.TargetRegion = targetRegion;
 }
예제 #6
0
파일: Go.cs 프로젝트: Bolukan/TweakBot
 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;
 }
예제 #7
0
파일: Go.cs 프로젝트: Bolukan/TweakBot
 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);
 }
예제 #8
0
파일: Path.cs 프로젝트: Bolukan/TweakBot
 /// <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;
 }
예제 #9
0
파일: Region.cs 프로젝트: Bolukan/TweakBot
 /// <summary>
 /// Add neighbour
 /// </summary>
 /// <param name="neighbour">Region</param>
 public void AddNeighbour(Region neighbour)
 {
     neighbours.AddRegion(neighbour);
 }