public override string[] calculatePath() { List <string> path = new List <string>(); while (goalPos.Count > 0) { Position target = new Position(-3, -3); string[] pathstep = new string[0]; foreach (Position position in goalPos) { if (target.getX() == -3 && target.getY() == -3) { target = position; pathstep = getPathTo(position); continue; } string[] tmp = getPathTo(position); if (tmp.Length < pathstep.Length) { target = position; pathstep = tmp; } } path.AddRange(pathstep); agent.reset(target); goalPos.Remove(target); } return(path.ToArray()); }
public int getDistanceTo(Position target) { return(Math.Abs((x) - target.getX()) + Math.Abs((y) - target.getY())); }