private static int GetTroopTarget(GameInformation gameInformation, Country country) { var enemies = gameInformation.GetAdjacentCountriesWithDifferentOwner(country).ToList(); if (enemies.Count == 0) return country.IsContinentGateway() ? 4 : 2; if (enemies.Count == 1) return enemies[0].NumberOfTroops + 3; return enemies.Sum(x => x.NumberOfTroops) + 1; }
public void Deploy(TurnManager turnManager, int numberOfTroops) { gameInformation = turnManager.GetGameInfo(); //exclude all isolated countries (all countries with only enemy neighbours) var countriesToAimAt = gameInformation.GetAllCountriesOwnedByPlayer(this) .Where(x => gameInformation.GetAdjacentCountriesWithSameOwner(x).Any()) .ToArray(); //Determine defensiveRate. //While there are countries with low defensiveRate (number of own troops / number of surrounding troups), make those stronger. var countriesWithEnemyNeighbours = countriesToAimAt.Where(x => gameInformation.GetAdjacentCountriesWithDifferentOwner(x).Count > 0) .ToArray(); var defensiveRates = GetDefensiveRates(countriesWithEnemyNeighbours).OrderBy(x => x.Value); while (defensiveRates.First().Value < DEFENSIVE_THRESHOLD_FOR_DEPLOYMENT && numberOfTroops > 0) { turnManager.DeployTroops(defensiveRates.First().Key, 1); defensiveRates = GetDefensiveRates(countriesWithEnemyNeighbours).OrderByDescending(x => x.Value); numberOfTroops--; } //Get the continent with the biggest presence. //Determine what country has the highest defensiveRate (number of own troops / number of surrounding troups), make those even stronger. //Make sure this ratio is not too big. var biggestContinent = GetBiggestOwnedContinentWithRemainingEnemyCountries(); var allOwnCountriesInBiggestContinent = countriesToAimAt.Where(x => x.Continent == biggestContinent.Key).ToArray(); var countriesWithRates = GetDefensiveRates(allOwnCountriesInBiggestContinent) .Where(x => x.Key.NumberOfTroops < MAX_TROOPS_FOR_DEPLOYMENT) .OrderByDescending(x => x.Value); while (countriesWithRates.Any() && numberOfTroops > 0) { turnManager.DeployTroops(countriesWithRates.First().Key, 1); countriesWithRates = GetDefensiveRates(allOwnCountriesInBiggestContinent) .Where(x => x.Key.NumberOfTroops < MAX_TROOPS_FOR_DEPLOYMENT) .OrderByDescending(x => x.Value); numberOfTroops--; } while (numberOfTroops > 0) { turnManager.DeployTroops(GetRandomOwnedCountry(turnManager), 1); numberOfTroops--; } }
public void Attack(TurnManager turnManager) { gameInformation = turnManager.GetGameInfo(); var countryToAttackWith = GetCountryToAttackWith(); while (countryToAttackWith != null) { turnManager.Attack(countryToAttackWith.Item1, countryToAttackWith.Item2, countryToAttackWith.Item1.NumberOfTroops - 1); countryToAttackWith = GetCountryToAttackWith(); } }
public DeploymentCounter(IPlayer player, GameInformation gameInformation) { this.player = player; this .gameInformation = gameInformation; }
private void DeployRemaining(TurnManager turnManager, RiskAnalysis analysis, int troops, GameInformation gameInfo) { if (troops <= 0) return; // deploy remainder evenly... var deployments = gameInfo.GetAllCountriesOwnedByPlayer(_player) .OrderBy(x => x.NumberOfTroops) .Select(x => new Deployment(turnManager) { ToCountry = x }) .ToList(); while (troops > 0) { foreach (var deployment in deployments.TakeWhile(deployment => --troops >= 0)) { deployment.Troops++; } } analysis.Deployments.AddRange(deployments.Where(x => x.Troops > 0)); }
public DeploymentCounter(IPlayer player, GameInformation gameInformation) { this.player = player; this.gameInformation = gameInformation; }