public void DeathstarDestroyPlanet(Planet deathstar, Planet target) { dynamic json = new ExpandoObject(); json.type = "deathstar_attack"; json.data = new ExpandoObject(); json.data.deathstar = deathstar.Id; json.data.end = target.Id; string msg = Newtonsoft.Json.JsonConvert.SerializeObject(json); SendMessage(msg); }
public void RedirectShip(Ship ship, Planet target) { dynamic json = new ExpandoObject(); json.type = "redirect_ship"; json.data = new ExpandoObject(); json.data.id_ship = ship.Id; json.data.id_target = target.Id; string msg = Newtonsoft.Json.JsonConvert.SerializeObject(json); SendMessage(msg); }
public void AttackPlanet(Planet origin, Planet target, int shipCount) { dynamic json = new ExpandoObject(); json.type = "attack"; json.data = new ExpandoObject(); json.data.start = origin.Id; json.data.end = target.Id; json.data.ship_count = shipCount; string msg = Newtonsoft.Json.JsonConvert.SerializeObject(json); SendMessage(msg); }
public int NbShipsAttacking(Planet destination) { return Container.Ships.Where(x => x.Owner == AI.name && x.TargetId == destination.Id).Sum(x => x.ShipCount); }
public int IncomingForce(Planet home) { int enemy = IncomingCount(s => s.Owner != AI.name, home); int reinforcement = IncomingCount(s => s.Owner == AI.name, home); return enemy - reinforcement; }
public IEnumerable<Planet> EnemyPlanetsByDistance(Planet a) { return EnemyPlanets().OrderBy(x => DistanceBetweenPlanets(a, x)).ThenByDescending(x => x.Size); }
public bool EnemyInRayon(Planet home, double rayon) { return EnemyPlanets().Any(enemy => DistanceBetweenPlanets(home, enemy) > rayon); }
public double DistanceToClosestEnemyPlanet(Planet planet) { var p = EnemyPlanets().Where(x => x.Id != planet.Id).OrderBy(x => DistanceBetweenPlanets(planet, x)).First(); return DistanceBetweenPlanets(planet, p); }
public double DistanceBetweenPlanets(Planet a, Planet b) { var intermediare = Math.Pow((b.PosX - a.PosX), 2) + Math.Pow((b.PosY - a.PosY), 2); return Math.Sqrt(intermediare); }
public Planet ClosestPlanet(Planet home, IEnumerable<Planet> planets) { return planets.Where(x => x.Id != home.Id).OrderBy(x => DistanceBetweenPlanets(home, x)).First(); }
private int IncomingCount(Func<Ship, bool> controller, Planet home) { return Container.Ships.Where(controller).Where(s => s.TargetId == home.Id).Sum(s => s.ShipCount); }
void Send(Planet owner, Planet target, int chunks, int size) { for (int i = 0; i < chunks; i++) { Game.AttackPlanet(owner, target, Convert.ToInt32(Math.Floor((double)size / chunks))); } }
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++; }
public float GetDistance(Planet planet) { return (float)Math.Sqrt(Math.Pow(planet.PosX - PosX, 2) + Math.Pow(planet.PosY - PosY, 2)); }
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 PlanetEnemies(Planet planet, IEnumerable<Planet> enemies) { Planet = planet; Enemies = enemies.ToList(); }