/// <summary> /// Takes an object, a list of games, predicts the location of the object in the next turn /// </summary> /// <param name="obj"></param> /// <returns></returns> /*public Location PredictLocationByMovement(SpaceObject obj) * { * List<SpaceObject> spaceObjects = null; * Location currentLocation = obj.Location; * Location previousLocation = null; * * // First, check the type of obj * if (obj is Pirate) * { * spaceObjects.AddRange(GameSettings.GameList[GameSettings.GameList.Count - 2].GetEnemyLivingPirates().ToList()); * } * else if (obj is Asteroid) * { * spaceObjects.AddRange(GameSettings.GameList[GameSettings.GameList.Count - 2].GetLivingAsteroids().ToList()); * } * else return null; * * foreach (SpaceObject movingObj in spaceObjects) // Check on every SpaceObject on the list defined before: * { * if (movingObj.Id == obj.Id) // Is it the original object? * { * previousLocation = movingObj.Location; // Then get it's past Location! put it in "previousLocation" * break; * } * } * * // Now, calculate it's predicted Location * return currentLocation.Add(currentLocation.Subtract(previousLocation)); * * }*/ public Location PredictLocationAfterPush(SpaceObject obj, Location pushTo, Location moveTo) { Location currentLocation = obj.Location; Location endPoint; int distance = 0; // Check the type of the SpaceObject if (obj is Pirate) { distance = GameSettings.Game.PirateMaxSpeed; } else if (obj is Asteroid) { distance = GameSettings.Game.AsteroidSpeed; } else { GameSettings.Game.Debug("The SpaceObject in PredictLocationAfterPush does not match any implemented SpaceObjects"); } // Calculate the endPoint endPoint = currentLocation.Towards(moveTo, distance); endPoint = endPoint.Towards(pushTo, GameSettings.Game.PushDistance); return(endPoint); }
///////// Cal if need defend public List <Location> AttPath(LavaGiant ene) { List <Location> AttackPath = new List <Location>(); Location start = ene.GetLocation(); AttackPath.Add(start); while (!start.InRange(game.GetMyCastle(), game.LavaGiantAttackRange + game.GetMyCastle().Size)) { start = start.Towards(game.GetMyCastle(), game.LavaGiantMaxSpeed); AttackPath.Add(start); } return(AttackPath); }
public int Attack_CheckLava() { foreach (Portal p in Myp) { int i = 0; Location l = p.GetLocation(); while (!l.InRange(game.GetEnemyCastle(), game.GetEnemyCastle().Size + game.LavaGiantAttackRange)) { i += game.LavaGiantSuffocationPerTurn; l = l.Towards(game.GetEnemyCastle(), game.LavaGiantMaxSpeed); } if (game.LavaGiantMaxHealth - i >= game.LavaGiantMaxHealth / 2) { return(game.LavaGiantMaxHealth / 2); } else if (game.LavaGiantMaxHealth - i >= game.LavaGiantMaxHealth / 3) { return(game.LavaGiantMaxHealth / 3); } } return(0); }
public int Attack_Check() { Location portal = AttPortal.GetLocation(); int i = game.TornadoMaxHealth; List <Location> closest = new List <Location>(); foreach (var b in game.GetEnemyPortals()) { closest.Add(b.GetLocation()); } foreach (var b in game.GetEnemyManaFountains()) { closest.Add(b.GetLocation()); } closest = (from element in closest orderby element.Distance(portal) select element).ToList(); if (closest.Count == 0) { return(game.TornadoMaxHealth / 2); } while (!portal.InRange(closest[0], game.TornadoAttackRange)) { i -= game.TornadoSuffocationPerTurn; portal = portal.Towards(closest[0], game.TornadoMaxSpeed); } if (i >= game.TornadoMaxHealth / 2) { return(game.TornadoMaxHealth / 2); } else if (i >= game.TornadoMaxHealth / 3) { return(game.TornadoMaxHealth / 3); } else { return(0); } }
public bool DefTurn(LavaGiant giant, Portal defn) { Location ice = defn.Location; List <Location> Attp = AttPath(giant); int hplava = giant.CurrentHealth; if (game.GetMyIceTrolls().Length == 0) { for (int i = 0; i < Attp.Count; i++) { if (i <= game.IceTrollSummoningDuration - 1) { } else if (!ice.InRange(Attp[i], game.IceTrollAttackRange)) { ice = ice.Towards(Attp[i], game.IceTrollMaxSpeed); } else { hplava = hplava - game.IceTrollAttackMultiplier; } hplava = hplava - giant.SuffocationPerTurn; } if (hplava != 0) { return(true); } else { return(false); } } else { //////////// Backup /// Trolls Info Dictionary <int, Location> troll_loc = new Dictionary <int, Location>(); Dictionary <int, int> troll_hp = new Dictionary <int, int>(); Dictionary <int, bool> troll_act = new Dictionary <int, bool>(); foreach (IceTroll againt in game.GetMyIceTrolls()) { troll_hp.Add(againt.Id, againt.CurrentHealth); troll_loc.Add(againt.Id, againt.GetLocation()); troll_act.Add(againt.Id, false); } /// Lava Info Dictionary <int, Location> lava_loc = new Dictionary <int, Location>(); Dictionary <int, int> lava_hp = new Dictionary <int, int>(); foreach (LavaGiant againt in game.GetMyLavaGiants()) { lava_hp.Add(againt.Id, againt.CurrentHealth); lava_loc.Add(againt.Id, againt.GetLocation()); } /// Tornado Info Dictionary <int, Location> tornado_loc = new Dictionary <int, Location>(); Dictionary <int, int> tornado_hp = new Dictionary <int, int>(); foreach (Tornado againt in game.GetMyTornadoes()) { tornado_hp.Add(againt.Id, againt.CurrentHealth); tornado_loc.Add(againt.Id, againt.GetLocation()); } int counter = 1; /// Buildings Info Dictionary <int, Location> buildings_loc = new Dictionary <int, Location>(); Dictionary <int, int> buildings_hp = new Dictionary <int, int>(); foreach (Building againt in game.GetMyManaFountains()) { buildings_hp.Add(counter, againt.CurrentHealth); buildings_loc.Add(counter, againt.GetLocation()); counter++; } counter = -1; foreach (Building againt in game.GetMyPortals()) { buildings_hp.Add(counter, againt.CurrentHealth); buildings_loc.Add(counter, againt.GetLocation()); counter--; } /// Enemy Lava Info Dictionary <int, Location> lava_enemy_loc = new Dictionary <int, Location>(); Dictionary <int, int> lava_enemy_hp = new Dictionary <int, int>(); foreach (LavaGiant againt in game.GetEnemyLavaGiants()) { lava_enemy_hp.Add(againt.Id, againt.CurrentHealth); lava_enemy_loc.Add(againt.Id, againt.GetLocation()); } /// Enemy Troll Info Dictionary <int, Location> troll_enemy_loc = new Dictionary <int, Location>(); Dictionary <int, int> troll_enemy_hp = new Dictionary <int, int>(); Dictionary <int, bool> troll_enemy_act = new Dictionary <int, bool>(); foreach (IceTroll againt in game.GetEnemyIceTrolls()) { troll_enemy_hp.Add(againt.Id, againt.CurrentHealth); troll_enemy_loc.Add(againt.Id, againt.GetLocation()); troll_enemy_act.Add(againt.Id, false); } /// Enemy Tornado Info Dictionary <int, Location> tornado_enemy_loc = new Dictionary <int, Location>(); Dictionary <int, int> tornado_enemy_hp = new Dictionary <int, int>(); foreach (Tornado againt in game.GetEnemyTornadoes()) { tornado_enemy_hp.Add(againt.Id, againt.CurrentHealth); tornado_enemy_loc.Add(againt.Id, againt.GetLocation()); } counter = 1; /// Enemy Buildings Info Dictionary <int, Location> buildings_enemy_loc = new Dictionary <int, Location>(); Dictionary <int, int> buildings_enemy_hp = new Dictionary <int, int>(); foreach (Building againt in game.GetEnemyManaFountains()) { buildings_enemy_hp.Add(counter, againt.CurrentHealth); buildings_enemy_loc.Add(counter, againt.GetLocation()); counter++; } counter = -1; foreach (Building againt in game.GetEnemyPortals()) { buildings_enemy_hp.Add(counter, againt.CurrentHealth); buildings_enemy_loc.Add(counter, againt.GetLocation()); counter--; } // No BackUp Check for (int j = 0; j < Attp.Count; j++) { ///// HitCheck HitCheck(troll_loc, troll_hp, troll_enemy_loc, troll_enemy_hp, lava_enemy_loc, lava_enemy_hp, lava_loc, lava_hp, troll_act, troll_enemy_act, tornado_enemy_loc, tornado_enemy_hp, tornado_loc, tornado_hp); Dictionary <int, int> troll_enemy_hp_old = new Dictionary <int, int>(troll_enemy_hp); Dictionary <int, Location> troll_enemy_loc_old = new Dictionary <int, Location>(troll_enemy_loc); Dictionary <int, Location> lava_enemy_loc_old = new Dictionary <int, Location>(lava_enemy_loc); Dictionary <int, int> lava_enemy_hp_old = new Dictionary <int, int>(lava_enemy_hp); Dictionary <int, Location> tornado_enemy_loc_old = new Dictionary <int, Location>(tornado_enemy_loc); Dictionary <int, int> tornado_enemy_hp_old = new Dictionary <int, int>(tornado_enemy_hp); ///// MoveEnemy MoveCheck(troll_enemy_loc, troll_enemy_hp, troll_loc, troll_hp, lava_loc, lava_hp, lava_enemy_loc, lava_enemy_hp, troll_enemy_act, game.GetMyCastle(), tornado_enemy_loc, tornado_enemy_hp, buildings_loc, buildings_hp, tornado_loc, tornado_hp); ///// MoveMy MoveCheck(troll_loc, troll_hp, troll_enemy_loc_old, troll_enemy_hp_old, lava_enemy_loc_old, lava_enemy_hp_old, lava_loc, lava_hp, troll_act, game.GetEnemyCastle(), tornado_loc, tornado_hp, buildings_enemy_loc, buildings_enemy_hp, tornado_enemy_loc_old, tornado_enemy_hp_old); ResetTurn(troll_enemy_act); // Prep For Next Turn ResetTurn(troll_act); // Prep For Next Turn } bool nobackup = false; foreach (var item in lava_enemy_loc) { if (item.Value.InRange(game.GetMyCastle(), game.LavaGiantAttackRange + game.GetMyCastle().Size) && lava_enemy_hp[item.Key] > 3) { nobackup = true; } } if (nobackup) { lava_enemy_hp.Clear(); lava_enemy_loc.Clear(); foreach (LavaGiant againt in game.GetEnemyLavaGiants()) { lava_enemy_hp.Add(againt.Id, againt.CurrentHealth); lava_enemy_loc.Add(againt.Id, againt.GetLocation()); } troll_hp.Clear(); troll_loc.Clear(); foreach (IceTroll againt in game.GetMyIceTrolls()) { troll_hp.Add(againt.Id, againt.CurrentHealth); troll_loc.Add(againt.Id, againt.GetLocation()); } troll_enemy_hp.Clear(); troll_enemy_loc.Clear(); foreach (IceTroll againt in game.GetEnemyIceTrolls()) { troll_enemy_hp.Add(againt.Id, againt.CurrentHealth); troll_enemy_loc.Add(againt.Id, againt.GetLocation()); } lava_hp.Clear(); lava_loc.Clear(); foreach (LavaGiant againt in game.GetMyLavaGiants()) { lava_hp.Add(againt.Id, againt.CurrentHealth); lava_loc.Add(againt.Id, againt.GetLocation()); } tornado_enemy_hp.Clear(); tornado_enemy_loc.Clear(); foreach (Tornado againt in game.GetEnemyTornadoes()) { tornado_enemy_hp.Add(againt.Id, againt.CurrentHealth); tornado_enemy_loc.Add(againt.Id, againt.GetLocation()); } tornado_hp.Clear(); tornado_loc.Clear(); foreach (Tornado againt in game.GetMyTornadoes()) { tornado_hp.Add(againt.Id, againt.CurrentHealth); tornado_loc.Add(againt.Id, againt.GetLocation()); } buildings_enemy_hp.Clear(); buildings_enemy_loc.Clear(); counter = 1; foreach (Building againt in game.GetEnemyManaFountains()) { buildings_enemy_hp.Add(counter, againt.CurrentHealth); buildings_enemy_loc.Add(counter, againt.GetLocation()); counter++; } counter = -1; foreach (Building againt in game.GetEnemyPortals()) { buildings_enemy_hp.Add(counter, againt.CurrentHealth); buildings_enemy_loc.Add(counter, againt.GetLocation()); counter--; } buildings_hp.Clear(); buildings_loc.Clear(); counter = 1; foreach (Building againt in game.GetMyManaFountains()) { buildings_hp.Add(counter, againt.CurrentHealth); buildings_loc.Add(counter, againt.GetLocation()); counter++; } counter = -1; foreach (Building againt in game.GetMyPortals()) { buildings_hp.Add(counter, againt.CurrentHealth); buildings_loc.Add(counter, againt.GetLocation()); counter--; } ResetTurn(troll_enemy_act); ResetTurn(troll_act); for (int j = 0; j < Attp.Count; j++) { if (j == game.IceTrollSummoningDuration - 1) { troll_hp.Add(555, game.IceTrollMaxHealth); troll_loc.Add(555, DefPortal.GetLocation()); troll_act.Add(555, false); } ///// HitCheck HitCheck(troll_loc, troll_hp, troll_enemy_loc, troll_enemy_hp, lava_enemy_loc, lava_enemy_hp, lava_loc, lava_hp, troll_act, troll_enemy_act, tornado_enemy_loc, tornado_enemy_hp, tornado_loc, tornado_hp); Dictionary <int, int> troll_enemy_hp_old = new Dictionary <int, int>(troll_enemy_hp); Dictionary <int, Location> troll_enemy_loc_old = new Dictionary <int, Location>(troll_enemy_loc); Dictionary <int, Location> lava_enemy_loc_old = new Dictionary <int, Location>(lava_enemy_loc); Dictionary <int, int> lava_enemy_hp_old = new Dictionary <int, int>(lava_enemy_hp); Dictionary <int, Location> tornado_enemy_loc_old = new Dictionary <int, Location>(tornado_enemy_loc); Dictionary <int, int> tornado_enemy_hp_old = new Dictionary <int, int>(tornado_enemy_hp); ///// MoveEnemy MoveCheck(troll_enemy_loc, troll_enemy_hp, troll_loc, troll_hp, lava_loc, lava_hp, lava_enemy_loc, lava_enemy_hp, troll_enemy_act, game.GetMyCastle(), tornado_enemy_loc, tornado_enemy_hp, buildings_loc, buildings_hp, tornado_loc, tornado_hp); ///// MoveMy MoveCheck(troll_loc, troll_hp, troll_enemy_loc_old, troll_enemy_hp_old, lava_enemy_loc_old, lava_enemy_hp_old, lava_loc, lava_hp, troll_act, game.GetEnemyCastle(), tornado_loc, tornado_hp, buildings_enemy_loc, buildings_enemy_hp, tornado_enemy_loc_old, tornado_enemy_hp_old); ResetTurn(troll_enemy_act); // Prep For Next Turn ResetTurn(troll_act); // Prep For Next Turn } foreach (var item in lava_enemy_loc) { if (item.Value.InRange(game.GetMyCastle(), game.LavaGiantAttackRange + game.GetMyCastle().Size) && (lava_enemy_hp[item.Key] < 3 || lava_enemy_hp[item.Key] > 5)) { return(true); } } } ///////////////////////////////////////////////////////////////////////// IceTroll defend = Closest_IceTroll_to_Lava(game.GetMyIceTrolls(), giant, game); Location icetr = defend.GetLocation(); int i = 0; int hpice = defend.CurrentHealth; while (!ice.InRange(icetr, 100)) { if (i <= 2) { } else { ice = ice.Towards(icetr, 100); } i++; hpice = hpice - defend.SuffocationPerTurn; if (hpice < 0 && game.GetMyIceTrolls().Length < 4) { return(true); } } return(false); } }