public static bool AttackIsSafe(Region fromRegion, int attackingArmies, Region toRegion, int defendingArmies, string myName, float confidence)
        {
            var          nonAttackingArmies = fromRegion.Armies - attackingArmies;
            BattleResult attackResult       = AnalyzeBattle(confidence, defendingArmies, attackingArmies);

            List <Region> unconqueredNeighbors;
            int           expectedArmiesLeftToDefend;

            if (attackResult.AttackerExpectedToWinForSure())
            {
                unconqueredNeighbors       = fromRegion.Neighbors.Where(x => x.Id != toRegion.Id).ToList();
                expectedArmiesLeftToDefend = nonAttackingArmies;
            }
            else if (attackResult.AttackerExpectedToWin())
            {
                unconqueredNeighbors       = fromRegion.Neighbors;
                expectedArmiesLeftToDefend = nonAttackingArmies;
            }
            else
            {
                unconqueredNeighbors       = fromRegion.Neighbors;
                expectedArmiesLeftToDefend = nonAttackingArmies + attackResult.AttackerRemainingArmiesLow;
            }

            var toRegionActualArmies = toRegion.Armies;

            toRegion.Armies = attackResult.DefenderRemainingArmies;
            bool attackIsSafe = (DefensiveArmiesNeeded.For(unconqueredNeighbors, expectedArmiesLeftToDefend, Constants.SafeNumberOfArmiesNeeded) <= Constants.SafeNumberOfArmiesNeeded &&
                                 DefensiveArmiesNeeded.For(toRegion.Neighbors, attackResult.AttackerRemainingArmiesLow, Constants.SafeNumberOfArmiesNeeded) <= Constants.SafeNumberOfArmiesNeeded);

            toRegion.Armies = toRegionActualArmies;

            return(attackIsSafe);
        }
Example #2
0
        public static List <Tuple <Region, int> > RankRegionsByNeed(Map visibleMap, string myName, int armiesAvailable)
        {
            var myRegions = new List <Tuple <Region, int> >();

            foreach (var region in visibleMap.Regions)
            {
                if (region.OwnedByPlayer(myName))
                {
                    int armiesNeeded = DefensiveArmiesNeeded.For(region.Neighbors, region.Armies, armiesAvailable);
                    var myRegion     = new Tuple <Region, int>(region, armiesNeeded);
                    myRegions.Add(myRegion);
                }
            }

            myRegions.Sort((a, b) => b.Item2.CompareTo(a.Item2));
            return(myRegions);
        }