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);
        }
        public static int MaximumArmiesNecessaryToConquer(float confidenceForDefiniteWin, float confidenceForPossibleWin, int defenderArmies, int maxAttackerArmiesAvailable)
        {
            int  armiesNeeded = 0;
            bool defeated;

            do
            {
                armiesNeeded = System.Math.Min(armiesNeeded + 2, maxAttackerArmiesAvailable);
                BattleResult result = AnalyzeBattle(confidenceForDefiniteWin, defenderArmies, armiesNeeded);
                defeated = result.AttackerExpectedToWinForSure();
            } while (!defeated && armiesNeeded < maxAttackerArmiesAvailable);

            // Putting this here so that we don't throw armies away on battles we absolutely cannot win
            if (!defeated)
            {
                BattleResult result = AnalyzeBattle(confidenceForPossibleWin, defenderArmies, maxAttackerArmiesAvailable);
                armiesNeeded = (result.AttackerExpectedToWinAtAll()) ? maxAttackerArmiesAvailable : int.MaxValue;
            }

            return(armiesNeeded);
        }