Exemple #1
0
        public ActionResult Show(int id)
        {
            Dictionary <string, object> model = new Dictionary <string, object>();
            Regions     selectedRegion        = Regions.Find(id);
            List <Info> regionInfo            = selectedInfo.GetInfo();

            model.Add("region", selectedRegion);
            model.Add("info", regionInfo);
            return(View(model));
        }
Exemple #2
0
        public bool CanEnter(string regionName, Progression items)
        {
            var region = Regions.Find(r => r.Name == regionName);

            if (region == null)
            {
                throw new ArgumentException($"World.CanEnter: Invalid region name {regionName}", nameof(regionName));
            }
            return(region.CanEnter(items));
        }
Exemple #3
0
        private void m_RegionListing_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_currentRegion = m_RegionListing.SelectedItem == null ? null : Regions.Find(p => p.RegionName == m_RegionListing.SelectedItem.ToString());

            if (m_RegionListing.SelectedItem == null || m_RegionListing.SelectedItem.ToString() == Trizbort.Region.DefaultRegion)
            {
                btnDeleteRegion.Enabled = false;
            }
            else
            {
                btnDeleteRegion.Enabled = true;
            }
        }
Exemple #4
0
        internal bool CanEnter(string regionName, List <Item> items)
        {
            var region = Regions.Find(r => r.Name == regionName);

            if (region != null)
            {
                return(region.CanEnter(items));
            }
            else
            {
                throw new ArgumentException("World.CanEnter: Invalid region name " + regionName);
            }
        }
Exemple #5
0
 /// <summary>
 /// Gets the primary region.
 /// </summary>
 /// <param name="regions">The regions.</param>
 /// <returns></returns>
 public static Region GetPrimaryRegion(Regions regions)
 {
     return(regions
            .Find(PlayerType.Me)
            .NotEnclosedBy(PlayerType.Me)
            .OrderRegions(OrderStrategy.EnemyNeighboursFirst)
            .ThenOrderRegions(OrderStrategy.VeryLargeRegionsLast)
            .ThenOrderRegions(OrderStrategy.NeutralNeighboursFirst)
            .ThenOrderRegions(OrderStrategy.NeutralNeighboursOnOtherSuperRegionsFirst)
            .ThenOrderRegions(OrderStrategy.SmallSuperRegionsFirst)
            .ThenOrderRegions(OrderStrategy.MostNumberOfArmies)
            .FirstOrDefault());
 }
Exemple #6
0
        public ActionResult Create(string region, string info)
        {
            Dictionary <string, object> model = new Dictionary <string, object>();
            Regions foundRegion = Regions.Find(region);
            Info    newInfo     = new Info(info);

            foundRegion.AddInfo(newInfo);
            List <Info> regionInfo = foundRegion.GetInfo();

            model.Add("info", regionInfo);
            model.Add("region", foundRegion);
            return(View("Show", model));
        }
Exemple #7
0
 public static Region GetSecundaryRegion(Regions regions, Region primaryRegion)
 {
     return(regions
            .Find(PlayerType.Me)
            .NotEnclosedBy(PlayerType.Me)
            .OnOtherSuperRegion(primaryRegion)
            .Where(region => region.NbrOfArmies < 100)
            .OrderRegions(OrderStrategy.EnemyNeighboursFirst)
            .ThenOrderRegions(OrderStrategy.NeutralNeighboursFirst)
            .ThenOrderRegions(OrderStrategy.NeutralNeighboursOnOtherSuperRegionsFirst)
            .ThenOrderRegions(OrderStrategy.SmallSuperRegionsFirst)
            .ThenOrderRegions(OrderStrategy.MostNumberOfArmies)
            .FirstOrDefault());
 }
Exemple #8
0
        /// <summary>
        /// Calculates the strategy when there are enemy regions in the super region
        /// </summary>
        /// <param name="superRegion">The super region.</param>
        /// <returns></returns>
        public bool CalculateForEnemyRegions(SuperRegion superRegion)
        {
            Region targetRegion = null, sourceRegion = null;
            bool   transferDone = false;

            var hostileRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.HostileRegions);

            if (hostileRegions.Any())
            {
                foreach (var hostileRegion in hostileRegions)
                {
                    int enemyArmies = hostileRegion.NbrOfArmies;

                    /* Let's see if we can attack. There is  60% change per attacking army.
                     * We will be extra safe and use a 50% chance.
                     * This means we'll need at least double as much armies as our opponent.
                     * If this isn't the case, we'll send more armies to this region and defend our grounds.
                     *
                     * */
                    var possibleAttackingRegion = Regions
                                                  .Find(PlayerType.Me)
                                                  .Where(region => region.Neighbours.Contains(hostileRegion))
                                                  .Where(
                        region =>
                        (region.NbrOfArmies >= enemyArmies * 2 + 1 ||
                         region.NbrOfArmies > Configuration.Current.GetMaximumTreshold()))
                                                  .OrderByDescending(region => region.NbrOfArmies)
                                                  .FirstOrDefault();

                    //We can attack!
                    if (possibleAttackingRegion != null)
                    {
                        targetRegion = hostileRegion;
                        sourceRegion = possibleAttackingRegion;

                        var nbrOfArmies = enemyArmies * 2;

                        //If we're enclosed by ourself, attack with everything
                        if (sourceRegion.Neighbours.Count(n => n.IsOccupiedBy(PlayerType.Me)) == sourceRegion.Neighbours.Count - 1)
                        {
                            nbrOfArmies = sourceRegion.NbrOfArmies - 1;
                        }

                        transferDone = transferDone || AddCurrentPairToTransferList(sourceRegion, targetRegion, nbrOfArmies);
                    }

                    /* We can't attack, so let's defend.
                     * We'll send armies to the region that can be attacked with the least number of armies
                     * We'll prefer sending from regions that can't be attacked.
                     **/
                    else
                    {
                        targetRegion = hostileRegion
                                       .Neighbours
                                       .Find(PlayerType.Me)
                                       .Where(region => region.SuperRegion == superRegion)
                                       .OrderBy(region => region.NbrOfArmies)
                                       .FirstOrDefault();

                        if (targetRegion != null)
                        {
                            sourceRegion = targetRegion
                                           .Neighbours
                                           .Find(PlayerType.Me)
                                           .OrderByDescending(region => region.NbrOfArmies)
                                           .FirstOrDefault();
                        }
                        else
                        {
                            //We can't defend a region, probably because we don't have armies nearby, so let's conquer some regions instead
                            var targetRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.ConquerCurrentSuperRegion);
                            StrategyManager.ConquerNeutralRegions(targetRegions, Transfers, SourceStrategy.DominateCurrentSuperRegion);
                        }
                    }
                }
            }

            /*
             * There is a hostile region in this super regio but we can not attack it
             * Maybe we dont have enough armies nearby
             * So lets try doing something else, like conquering neutral armies
             */
            else
            {
                var targetRegions = StrategyManager.GetTargetRegions(superRegion, Transfers, TargetStrategy.ConquerCurrentSuperRegion);
                StrategyManager.ConquerNeutralRegions(targetRegions, Transfers, SourceStrategy.DominateCurrentSuperRegion);
            }

            return(transferDone);
        }
Exemple #9
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);
        }