/** * Computes a path from a location to the nearest source. Contains both start and end points. * * @param loc The location. * @return The path as a LocSet. */ public LocSet getPath(MapLocation loc) { LocSet path = new LocSet(); path.insert(loc); while (!sources.contains(loc)) { loc = loc.subtract(from[loc.x][loc.y]); path.insert(loc); } return path; }
public DStar(LocSet sources, int[] distances, MapLocation dest) { this.sources = sources; this.dest = dest; for (int i = sources.size; --i >= 0; ) { MapLocation source = sources.get(i); int e = distances[i] + heuristic(source, dest); queue.insert(e, source); distance[source.x][source.y] = distances[i]; // estimate[source.x][source.y] = e; // leave as null to cause exceptions if we accidentally try to use it? from[source.x][source.y] = Direction.NONE; } }