public void Attack(TurnManager turnManager) { for (var i = 1; i < 250; i++) { var possibleAttacks = GetAllPossibleAttacks(turnManager); foreach (var possibleAttack in possibleAttacks) { possibleAttack.SuccesRate = GetSuccessRate(possibleAttack); } var myAttack = possibleAttacks.OrderBy(pa => pa.SuccesRate).Last(); var riskRate = 900; if (IsLastEnemyInContinent(turnManager, myAttack.Victim)) { riskRate = 400; } if (myAttack.SuccesRate < riskRate) { return; } turnManager.Attack(myAttack.MyCountry, myAttack.Victim, myAttack.NumberOfTroops); } }
public int Defend(TurnManager turnManager, List<int> attackRolls, Country countryToDefend) { if (attackRolls.Count(x => x > 3) > 1) return 1; return 2; }
public void Attack(TurnManager turnManager) { var country = GetRandomOwnedCountryThatCanAttack(turnManager); var countryToAttack = GetRandomAdjacentCountryToAttack(turnManager, country); turnManager.Attack(country, countryToAttack, country.NumberOfTroops - 1); }
public void Attack(TurnManager turnManager) { //var country = GetRandomOwnedCountryThatCanAttack(); //var countryToAttack = GetRandomAdjacentCountryToAttack(country); var repeat = 0; var timeout = 0; do { var tempList = turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(this); foreach (var country in tempList) { var adjacentCountryList = country.AdjacentCountries.Where(p => p.Owner != this); foreach (var countryToAttack in adjacentCountryList) { if (countryToAttack.NumberOfTroops < country.NumberOfTroops && country.NumberOfTroops > 3) { turnManager.Attack(country, countryToAttack, country.NumberOfTroops - 1); repeat++; } } } timeout++; } while (repeat < 2 && timeout < 200); }
public void Deploy(TurnManager turnManager, int numberOfTroops) { while (numberOfTroops > 0) { turnManager.DeployTroops(GetMostImportantCountry(turnManager), 1); numberOfTroops--; } }
public void Deploy(TurnManager turnManager, int numberOfTroops) { while (numberOfTroops > 0) { turnManager.DeployTroops(GetRandomOwnedCountry(turnManager), 1); numberOfTroops--; } }
private Country GetRandomOwnedCountryThatCanAttack(TurnManager turnManager) { var ownedCountries =turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(this).Where(c => c.NumberOfTroops > 1 && c.AdjacentCountries.Any( ac => ac.Owner != c.Owner)) .ToList(); return ownedCountries[r.Next(0, ownedCountries.Count - 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 int Defend(TurnManager turnManager, List<int> attackRolls, Country countryToDefend) { if (attackRolls.Count == 3) { var dangerlevel = 0; if (attackRolls[0] >= 5) { dangerlevel++; } if (attackRolls[1] >= 5) { dangerlevel++; } if (attackRolls[2] >= 5) { dangerlevel++; } if (dangerlevel >= 2) { return 1; } return 2; } else { var dangerlevel = 0; if (attackRolls[0] >= 5) { dangerlevel++; } // bug here, there can be only 1 attack roll // Remco: added check for attack roll count if (attackRolls.Count>1 && attackRolls[1] >= 5) { dangerlevel++; } if (dangerlevel >= 2) { return 1; } return 2; } }
/// <summary> /// Adds attack info to the analysis, but only if there is a chance for success /// </summary> private void AddAttack(TurnManager turnManager, RiskAnalysis analysis, Country friendly, Country enemy) { var minDefenders = 2; if (friendly.NumberOfTroops > minDefenders+1 && friendly.NumberOfTroops > enemy.NumberOfTroops ) { analysis.Attacks.Add(new Attack(turnManager) { FromCountry = friendly, ToCountry = enemy, Troops = friendly.NumberOfTroops - minDefenders, }); } }
public void Attack(TurnManager turnManager) { var losses = 0; while (losses <= 3) { var analysis = riskAnalyzer.Analyze(turnManager); if (analysis.Attacks.Count == 0) return; analysis.ExecuteAttacks(); losses += analysis.Attacks.Count(x => x.Succeeded == false); } }
public void Move(TurnManager turnManager) { for (var i = 0; i < 250; i++) { var info = turnManager.GetGameInfo(); foreach (var country in info.GetAllCountriesOwnedByPlayer(this)) { var surroundingFriendlyCountries = country.AdjacentCountries.ToList().Where(c => c.Owner == this).Count(); if (surroundingFriendlyCountries == country.AdjacentCountries.Count) { while (country.NumberOfTroops > 1) { MoveTroopsToSurroundingCountries(turnManager, country); } } } } }
/// <summary> /// Performs analysis of the game state. /// It does a full analysis for every phase of a turn. /// This wastes some computational resources, but hopefully leads to a better outcome. /// </summary> public RiskAnalysis Analyze(TurnManager turnManager) { var analysis = new RiskAnalysis(); // the ordering of the analysis steps is important // each step depends on the results of the previous steps. // first, check the state of the board. DoContinentAnalysis(turnManager, analysis); // next, find which countries we want. DoAttackAnalysis(turnManager, analysis); // then check if we need to move troops DoMoveAnalysis(turnManager, analysis); // then place reinforcements on the board. DoDeployAnalysis(turnManager, analysis); // gather important countries. DoImportantCountryAnalysis(turnManager, analysis); return analysis; }
private Country GetRandomOwnedCountry(TurnManager turnManager) { var ownedCountries = turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(this); return ownedCountries[r.Next(0, ownedCountries.Count - 1)]; }
public void Move(TurnManager turnManager) { turnManager.MoveTroops(GetRandomOwnedCountryThatCanAttack(turnManager), GetRandomOwnedCountryThatCanAttack(turnManager), 1); }
private Country GetRandomAdjacentCountryToAttack(TurnManager turnManager, Country country) { var adjacentCountries = turnManager.GetGameInfo().GetAdjacentCountriesWithDifferentOwner(country); return adjacentCountries[r.Next(0, adjacentCountries.Count - 1)]; }
public int Defend(TurnManager turnManager, List<int> attackRolls, Country countryToDefend) { return 2; }
private bool IsLastEnemyInContinent(TurnManager turnManager, Country country) { var victimContinent = country.Continent; var info = turnManager.GetGameInfo(); var myCountriesInContinent = info.GetAllCountriesOwnedByPlayer(this).Count(c => c.Continent == country.Continent); var allCountriesInContinent = info.GetAllCountries().Count(c => c.Continent == country.Continent); return (allCountriesInContinent - myCountriesInContinent) == 1; }
public void Move(TurnManager turnManager) { var analysis = riskAnalyzer.Analyze(turnManager); analysis.ExecuteMoves(); }
private void MoveTroopsToSurroundingCountries(TurnManager turnManager, Country country) { turnManager.MoveTroops(country, GetMostImportantSurroundingCountry(turnManager, country), 1); }
public int Defend(TurnManager turnManager, List<int> attackRolls, Country countryToDefend) { var analysis = riskAnalyzer.Analyze(turnManager); return analysis.GetDefenceRolls(attackRolls, countryToDefend); }
public void Deploy(TurnManager turnManager, int numberOfTroops) { var analysis = riskAnalyzer.Analyze(turnManager); analysis.ExecuteDeployments(numberOfTroops); }
public void Move(TurnManager turnManager) { var countriesToAimAt = gameInformation.GetAllCountriesOwnedByPlayer(this) .Where(x => gameInformation.GetAdjacentCountriesWithSameOwner(x).Any()) .ToArray(); if (countriesToAimAt.Any()) { //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); var moveCounter = 0; while (defensiveRates.Any(x => x.Value < DEFENSIVE_THRESHOLD_FOR_DEPLOYMENT) && moveCounter++ < 250) { var first = defensiveRates.First(); var adjacentCountriesWithSameOwner = gameInformation.GetAdjacentCountriesWithSameOwner(first.Key) .Where( x => defensiveRates.Single(y => y.Key == x).Value > DEFENSIVE_THRESHOLD_FOR_DEPLOYMENT) .ToArray(); if (adjacentCountriesWithSameOwner.Any()) { turnManager.MoveTroops(first.Key, adjacentCountriesWithSameOwner.First(), adjacentCountriesWithSameOwner.First() .NumberOfTroops - 1); } defensiveRates = GetDefensiveRates(countriesWithEnemyNeighbours).OrderBy(x => x.Value); } } }
private double AverageTroopsPerCountry(TurnManager turnManager) { var info = turnManager.GetGameInfo(); var totalCountries = 0.0; var totalTroops = 0.0; info.GetAllCountriesOwnedByPlayer(this).ToList().ForEach( (Country c) => { totalCountries += 1; totalTroops += c.NumberOfTroops; }); return totalTroops / totalCountries; }
public Move(TurnManager turnManager) { this.turnManager = turnManager; }
public Deployment(TurnManager turnManager) { this.turnManager = turnManager; }
public Attack(TurnManager turnManager) { this.turnManager = turnManager; }
/* DONT LOOK AT OUR CODE PLS */ public void Deploy(TurnManager turnManager, int numberOfTroops) { if (numberOfTroops == 2) { var tempList = turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(this); var Australia = tempList.Where(p => p.Continent == EContinent.Australia).ToList(); var SouthAmerica = tempList.Where(p => p.Continent == EContinent.SouthAmerica).ToList(); var Africa = tempList.Where(p => p.Continent == EContinent.Africa).ToList(); var NorthAmerica = tempList.Where(p => p.Continent == EContinent.NorthAmerica).ToList(); var Europe = tempList.Where(p => p.Continent == EContinent.Europe).ToList(); var Asia = tempList.Where(p => p.Continent == EContinent.Asia).ToList(); var AustraliaCount = Australia.Count; if (Australia.Count >= 2) { if (AustraliaCount == 4) { var AustraliaBottleNeck = tempList.Where(p => p.Continent == EContinent.Australia && p.Number == 4).Single(); var i = AustraliaBottleNeck.AdjacentCountries.Where(p => p.Owner != this).ToList(); while (AustraliaBottleNeck.NumberOfTroops < 10 && numberOfTroops > 0 && i.Count > 0) { turnManager.DeployTroops(AustraliaBottleNeck, 1); numberOfTroops--; } } else { var Random = new Random(); var AustraliaBottleNeck = tempList.Where(p => p.Continent == EContinent.Australia); if (AustraliaBottleNeck != null) { var index = Random.Next(Australia.Count); var country = Australia[index]; var i = country.AdjacentCountries.Where(p => p.Owner != this).ToList(); while (country.NumberOfTroops < 10 && numberOfTroops > 0 && i.Count > 0) { turnManager.DeployTroops(country, 1); numberOfTroops--; } } } } if (SouthAmerica.Count >= 2) { var Random = new Random(); var SouthAmericaBottleNeck = tempList.Where(p => p.Continent == EContinent.SouthAmerica); if (SouthAmericaBottleNeck != null) { var index = Random.Next(SouthAmerica.Count); var country = SouthAmerica[index]; var i = country.AdjacentCountries.Where(p => p.Owner != this).ToList(); while (country.NumberOfTroops < 10 && numberOfTroops > 0 && i.Count > 0) { turnManager.DeployTroops(country, 1); numberOfTroops--; } } } if (Africa.Count >= 4) { var Random = new Random(); var AfricaBottleNeck = tempList.Where(p => p.Continent == EContinent.Africa); if (AfricaBottleNeck != null) { var index = Random.Next(Africa.Count); var country = Africa[index]; var i = country.AdjacentCountries.Where(p => p.Owner != this).ToList(); while (country.NumberOfTroops < 10 && numberOfTroops > 0 && i.Count > 0) { turnManager.DeployTroops(country, 1); numberOfTroops--; } } } if (NorthAmerica.Count >= 5) { var Random = new Random(); var AfricaBottleNeck = tempList.Where(p => p.Continent == EContinent.NorthAmerica); if (AfricaBottleNeck != null) { var index = Random.Next(NorthAmerica.Count); var country = NorthAmerica[index]; var i = country.AdjacentCountries.Where(p => p.Owner != this).ToList(); while (country.NumberOfTroops < 10 && numberOfTroops > 0 && i.Count > 0) { turnManager.DeployTroops(country, 1); numberOfTroops--; } } } if (Europe.Count >= 7) { var Random = new Random(); var AfricaBottleNeck = tempList.Where(p => p.Continent == EContinent.Europe); if (AfricaBottleNeck != null) { var index = Random.Next(Europe.Count); var country = Europe[index]; var i = country.AdjacentCountries.Where(p => p.Owner != this).ToList(); while (country.NumberOfTroops < 10 && numberOfTroops > 0 && i.Count > 0) { turnManager.DeployTroops(country, 1); numberOfTroops--; } } } if (Asia.Count >= 8) { var Random = new Random(); var AfricaBottleNeck = tempList.Where(p => p.Continent == EContinent.Asia); if (AfricaBottleNeck != null) { var index = Random.Next(Asia.Count); var country = Asia[index]; var i = country.AdjacentCountries.Where(p => p.Owner != this).ToList(); while (country.NumberOfTroops < 10 && numberOfTroops > 0 && i.Count > 0) { turnManager.DeployTroops(country, 1); numberOfTroops--; } } } while (numberOfTroops > 0) { var target = GetRandomOwnedCountry(turnManager); var i = target.AdjacentCountries.Where(p => p.Owner != this).ToList(); if (i.Count > 0) { if (target.NumberOfTroops < 7) { var z = 0; while (numberOfTroops > 0) { turnManager.DeployTroops(GetRandomOwnedCountry(turnManager), 1); z++; numberOfTroops--; if (z > 30) { break; } } } else { break; } } else { break; } } while (numberOfTroops > 0) { turnManager.DeployTroops(GetRandomOwnedCountry(turnManager), 1); numberOfTroops--; } } else { var myCountries = turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(this); var potential = new List<Country>(); foreach (var country in myCountries) { if (country.AdjacentCountries.Where(p => p.Owner != this).ToList().Count > 0) { potential.Add(country); } } var tempList = potential.OrderBy(p => p.NumberOfTroops).ToList(); foreach (var countryy in tempList) { while (countryy.NumberOfTroops < 10 && numberOfTroops > 0) { turnManager.DeployTroops(countryy, 1); numberOfTroops--; } } if (numberOfTroops > 0) { foreach (var countryy in tempList) { while (numberOfTroops > 0) { turnManager.DeployTroops(countryy, 1); numberOfTroops--; } } } } }
public void Move(TurnManager turnManager) { var movesLeft = 7; var tempList = turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(this); foreach (var country in tempList) { if (country.NumberOfTroops > 1) { var hasHostile = false; var checkForHostileCountries = country.AdjacentCountries.Where(p => p.Owner != this).ToList(); if (checkForHostileCountries.Count > 0) { hasHostile = true; } if (hasHostile == false) { var adjacentCountryListOwned = country.AdjacentCountries.Where(p => p.Owner == this).ToList(); foreach (var countryToMove in adjacentCountryListOwned) { var adjacentCountryListEnemey = countryToMove.AdjacentCountries.Where(p => p.Owner != this).ToList(); var hasHostile2 = false; if (adjacentCountryListEnemey.Count > 0) { hasHostile2 = true; } if (hasHostile2) { if (country.NumberOfTroops - 1 > 0 && movesLeft > 0) { if (movesLeft > (country.NumberOfTroops - 1)) { turnManager.MoveTroops(country, countryToMove, country.NumberOfTroops - 1); movesLeft = movesLeft - (country.NumberOfTroops - 1); } else { turnManager.MoveTroops(country, countryToMove, movesLeft); movesLeft = 0; } } } else { var adjacentCountryListOwned2 = countryToMove.AdjacentCountries.Where(p => p.Owner == this).ToList(); foreach (var countryToMove2 in adjacentCountryListOwned2) { var adjacentCountryListEnemey2 = countryToMove2.AdjacentCountries.Where(p => p.Owner != this).ToList(); var hasHostile3 = false; if (adjacentCountryListEnemey2.Count > 0) { hasHostile3 = true; } if (hasHostile3) { if (country.NumberOfTroops - 1 > 0 && movesLeft > 0) { if (movesLeft > (country.NumberOfTroops - 1)) { turnManager.MoveTroops(country, countryToMove, country.NumberOfTroops - 1); movesLeft = movesLeft - (country.NumberOfTroops - 1); } else { turnManager.MoveTroops(country, countryToMove, movesLeft); movesLeft = 0; } } } else { //hmm } } } } } } } }