public List <MapObject> checkPath(MapObject target, Location step, List <MapObject> BestWay) { List <MapObject> SafeHoles = GetSafeHoles(); foreach (Wormhole w in SafeHoles.Cast <Wormhole>().ToList()) { if ((step.Distance(target) > step.Distance(w) + w.Partner.Distance(target))) { checkPath(target, w.Partner.Location, BestWay); BestWay.Add(w); return(BestWay); } } BestWay.Add(target); return(BestWay); }
/// <summary> /// Checks a location relativity to an asteroid. True is to modify Col, false is to modify Row. /// </summary> /// <param name="asteroid"></param> /// <param name="pass"></param> /// <returns></returns> public bool ShouldAddToColOrRow(Asteroid asteroid, Location location) { int minDistance = 0; Location up = new Location(0, 0); up.Col = asteroid.GetLocation().Col; up.Row = asteroid.GetLocation().Row + asteroid.Size; Location down = new Location(0, 0); up.Col = asteroid.GetLocation().Col; up.Row = asteroid.GetLocation().Row - asteroid.Size; Location left = new Location(0, 0); up.Col = asteroid.GetLocation().Col - asteroid.Size; up.Row = asteroid.GetLocation().Row; Location right = new Location(0, 0); up.Col = asteroid.GetLocation().Col + asteroid.Size; up.Row = asteroid.GetLocation().Row; minDistance = System.Math.Min(location.Distance(up), location.Distance(down)); minDistance = System.Math.Min(minDistance, location.Distance(right)); minDistance = System.Math.Min(minDistance, location.Distance(left)); if (minDistance == location.Distance(up) || minDistance == location.Distance(down)) { return(true); } return(false); }
public bool WillAsteroidHitMe(Pirate pirate, Asteroid asteroid) { Location nextPirate = this.fieldAnalyzer.PredictLocation(pirate, 1); // = pirate.Location.Add(pirateMov); Location nextAsteroid = this.fieldAnalyzer.PredictLocation(asteroid, 1); // = asteroid.Location.Add(asteroidMov); // GameSettings.Game.Debug("WillAsteroidHitMe - next turn distance:"+nextAsteroid.Distance(nextPirate) + "...asteroid Size:" + asteroid.Size + "...nextAsteroid" + nextAsteroid + ".asteroidLoc"+ asteroid.Location + "...nextPirate" + nextPirate); foreach (Mothership msh in GameSettings.Game.GetMyMotherships()) { if (pirate.Location.Distance(msh.Location) <= 200) { return(true); } } if (nextPirate != null && nextAsteroid != null && nextAsteroid.Distance(nextPirate) <= asteroid.Size) { return(true); } return(false); /*Location pirateMov=null; Location asteroidMov=null; Location nextPirate=null; Location nextAsteroid=null; Location lastPirate=null; Location lastAsteroid=null; * List<PirateGame> pgl = GameSettings.GameList; * * //GameSettings.Game.Debug(GameSettings.GameList.Count + " " + (GameSettings.GameList.Count-2)); * //foreach(Pirate p in (GameSettings.GameList[GameSettings.GameList.Count - 2]).GetMyLivingPirates()) * //{ * // if (pirate.Id==p.Id) * * //} * if (pgl[pgl.Count-2].GetMyLivingPirates().Length > 0 && pgl[pgl.Count-2].GetLivingAsteroids().Length > 0) * { * lastPirate = (pgl[pgl.Count-2]).GetMyLivingPirates()[0].Location; * lastAsteroid = (pgl[pgl.Count-2]).GetLivingAsteroids()[0].Location; * * pirateMov = pirate.Location.Subtract(lastPirate); * asteroidMov = asteroid.Location.Subtract(lastAsteroid); * } * else * { * pirateMov=new Location (0,0); * asteroidMov=new Location (0,0); * } * * GameSettings.Game.Debug("asteroid id "+asteroid.Id+"asteroid.Location"+asteroid.Location+"...asteroidMov"+asteroidMov+"...pirateMov"+pirateMov+"...lastAsteroid"+lastAsteroid+"...lastPirate"+lastPirate); */ }