public void update(UpdateContainer container) { var helper = new AIHelper(container); var ourPlanets = helper.OurPlanet().Select(planet => new PlanetEnemies(planet, helper.EnemyPlanetsByDistance(planet))).ToList(); var usedPlanet = new List<Planet>(); var toDelete = new List<int>(); if (helper.DeathStar().Owner != name && helper.DeathStar().Owner != string.Empty) { foreach (var planet in ourPlanets) { Send(planet.Planet, helper.DeathStar(), 1, planet.Planet.ShipCount); } return; } if (helper.DeathStar().Owner == name && helper.DeathStar().DeathStarCharge >= 1) Game.DeathstarDestroyPlanet(helper.DeathStar(), helper.PlanetWithHighestSize()); while (ourPlanets.Count > 0) { ourPlanets.RemoveAll(x=>toDelete.Contains(x.Planet.Id)); foreach (var planet in ourPlanets) { planet.Enemies.RemoveAll(x => usedPlanet.Any(u => u.Id == x.Id)); bool used = planet.Enemies.Count > 0; if (helper.IncomingForce(planet.Planet) <= planet.Planet.ShipCount) { planet.Planet.ShipCount -= helper.IncomingForce(planet.Planet); } foreach (var enemy in planet.Enemies) { if (enemy.Owner != String.Empty) { Send(planet.Planet, enemy, 2, planet.Planet.ShipCount / 2); planet.Planet.ShipCount /= 2; } else if (enemy.Owner == String.Empty && planet.Planet.ShipCount > enemy.ShipCount+1 && helper.NbShipsAttacking(enemy) <= enemy.ShipCount + 1) { int additionalShips = 2; usedPlanet.Add(enemy); Send(planet.Planet, enemy, 2, enemy.ShipCount + additionalShips); planet.Planet.ShipCount -= enemy.ShipCount + additionalShips; used = true; break; } used = false; } if (!used) { toDelete.Add(planet.Planet.Id); } } } Console.Out.WriteLine("Updating"); }
public AIHelper(UpdateContainer container) { Container = container; }
public void update(UpdateContainer container) { //Console.Out.WriteLine("Updating"); if (!_firstDataReceived) { InitPlanets(container.Planets); this._firstDataReceived = true; } else { //mettre a jour this.UpdatePlanets(container.Planets); } enemyMaster = EnemyPlanets.OrderBy(p => p.ShipCount).FirstOrDefault(); closestToEnemyMaster = enemyMaster.GetClosestPlanets(planetsToAttack, false); Game.DeathstarDestroyPlanet(DeathStar, enemyMaster); if (DeathStar.ReadyToAttackNextTurn && DeathStar.Owner != name) { attackStrategy = 3; } switch (attackStrategy) { case 0: Strategy0(); break; case 1: Strategy1(); break; case 2: Strategy2(); break; case 3: Strategy3(); break; default: //Console.Out.WriteLine("Error attackStrategy: " + attackStrategy); break; } attackCount++; }
public void update(UpdateContainer container) { Console.Out.WriteLine("Updating"); var analyser = new Analyser(container, name); if (!_firstDataReceived) { InitPlanets(container.Planets); this._firstDataReceived = true; } else { //mettre a jour this.UpdatePlanets(container.Planets); } enemyMaster = EnemyPlanets.OrderBy(p => p.ShipCount).FirstOrDefault(); int planetsToAttack = 2; var closestToEnemyMaster = enemyMaster.GetClosestPlanets(planetsToAttack, false); switch(attackStrategy) { case 0: foreach (var planet in MyPlanets) { foreach (var closest in closestToEnemyMaster) { Game.AttackPlanet(planet, closest, (int)Math.Floor((double)planet.ShipCount * 0.8 / planetsToAttack)); } } if(!closestToEnemyMaster.Any(p => p.Owner != name)) { attackStrategy = 1; } break; case 1: if (closestToEnemyMaster.Any(p => p.Owner != name)) { attackStrategy = 0; } foreach(var planet in MyPlanets) { Game.AttackPlanet(planet, enemyMaster, (int)Math.Floor((double)planet.ShipCount * 0.8 / planetsToAttack)); } break; default: break; } /* foreach (var planet in analyser.MyPlanets) { foreach (var idle in analyser.NeutralPlanets) { Game.AttackPlanet(planet, idle, (int)Math.Floor((double)planet.ShipCount/analyser.NeutralPlanets.Count)); } } if (analyser.NeutralPlanets.Count == 0) { foreach (var planet in analyser.MyPlanets) { foreach (var enemy in analyser.EnemyPlanets) { Game.AttackPlanet(planet, enemy, planet.ShipCount-1); } } }*/ attackCount++; }
// test public Analyser(UpdateContainer container, string myName) { this.UpdateContainer = container; this.MyName = myName; }