Beispiel #1
0
        /// <summary>
        /// Places the armies.
        /// </summary>
        public IEnumerable <ArmyPlacement> PlaceArmies()
        {
            var placements     = new List <ArmyPlacement>();
            int startingArmies = Configuration.Current.GetStartingArmies();

            /* If we start on 3 super regions with an opponent as neighbour on every region we need to change some tactics:
             *  - Don't attack until round 4
             *  - Place armies on all 3 super regions to avoid loss of one or more super regions
             * */
            if (Configuration.Current.GetRoundNumber() == 1)
            {
                var myTotalSuperRegions =
                    Regions
                    .Find(PlayerType.Me)
                    .GroupBy(region => region.SuperRegion)
                    .ToList(); // Prevent possible multiple enumerations

                int opponentTotalSuperRegions =
                    Regions
                    .Find(PlayerType.Opponent)
                    .GroupBy(region => region.SuperRegion.ID)
                    .Count();

                if (myTotalSuperRegions.Count() == 3 && opponentTotalSuperRegions == 3)
                {
                    Configuration.Current.SetStartRoundNumber(4);
                    placements.Add(new ArmyPlacement
                    {
                        Armies = 2,
                        Region = Regions.Find(PlayerType.Me).First(r => r.SuperRegion == myTotalSuperRegions.First().Key)
                    });

                    placements.Add(new ArmyPlacement
                    {
                        Armies = 2,
                        Region = Regions.Find(PlayerType.Me).First(r => r.SuperRegion == myTotalSuperRegions.Skip(1).First().Key)
                    });

                    placements.Add(new ArmyPlacement
                    {
                        Armies = 1,
                        Region = Regions.Find(PlayerType.Me).First(r => r.SuperRegion == myTotalSuperRegions.Skip(2).First().Key)
                    });

                    UpdateRegions(placements);
                    return(placements);
                }
                else
                {
                    var regions = Regions.Find(PlayerType.Me);
                    if (regions.Count() <= startingArmies)
                    {
                        var armiesPerRegion = startingArmies / regions.Count();

                        foreach (var region in regions)
                        {
                            if (region == regions.Last())
                            {
                                armiesPerRegion = startingArmies - (armiesPerRegion * regions.Count());
                            }

                            placements.Add(new ArmyPlacement
                            {
                                Armies = armiesPerRegion,
                                Region = region
                            });
                        }
                    }
                }

                Configuration.Current.SetStartRoundNumber(2);
            }

            var primaryRegion   = StrategyManager.GetPrimaryRegion(Regions);
            var secundaryRegion = StrategyManager.GetSecundaryRegion(Regions, primaryRegion);

            int primaryRegionArmies   = 0;
            int secundaryRegionArmies = 0;

            if (startingArmies <= 6)
            {
                primaryRegionArmies   = 3;
                secundaryRegionArmies = startingArmies - 3;
            }
            if (startingArmies >= 7 && startingArmies <= 9)
            {
                primaryRegionArmies   = 5;
                secundaryRegionArmies = startingArmies - 5;
            }
            if (startingArmies > 9 && startingArmies <= 18)
            {
                primaryRegionArmies   = 9;
                secundaryRegionArmies = startingArmies - 9;
            }
            if (startingArmies > 18)
            {
                primaryRegionArmies   = startingArmies - 9;
                secundaryRegionArmies = 9;
            }

            var armyplacement = new ArmyPlacement {
                Armies = primaryRegionArmies, Region = primaryRegion
            };

            placements.Add(armyplacement);

            if (secundaryRegion == null)
            {
                secundaryRegion = primaryRegion;
            }

            armyplacement = new ArmyPlacement {
                Armies = secundaryRegionArmies, Region = secundaryRegion
            };
            placements.Add(armyplacement);

            UpdateRegions(placements);
            return(placements);
        }