private static int PlaceOffensiveArmies(int armiesLeft, GameState state, List <PlaceArmiesMove> placeArmiesMoves) { if (armiesLeft == 0) { return(armiesLeft); } foreach (var targetRegion in StrategicMap.UncontrolledRegionsByValue) { foreach (var offensiveRegion in targetRegion.Neighbors) { if (offensiveRegion.PlayerName == GameState.MyPlayerName) { BattleResult result = BattleAnalysis.AnalyzeBattle(confidence, targetRegion.Armies, offensiveRegion.Armies + armiesLeft); if (result.AttackerExpectedToWinAtAll()) { if (offensiveRegion.Armies > Constants.DeadlockThreshold && armiesLeft > 1) { armiesLeft = PlaceFailSafeArmy(offensiveRegion, 1, armiesLeft, placeArmiesMoves); } placeArmiesMoves.Add(new PlaceArmiesMove(GameState.MyPlayerName, offensiveRegion, armiesLeft)); armiesLeft = 0; } } if (armiesLeft == 0) { break; } } if (armiesLeft == 0) { break; } } if (armiesLeft > 0) { PlaceRemainingArmies(armiesLeft, placeArmiesMoves); armiesLeft = 0; } return(armiesLeft); }