-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pathing randomly fails after first search. Pathfinder doesn't reset closed nodes after search is complete. #52
Comments
Thank you, I was wondering WTF was going on. |
This was very helpful. |
I'm having this problem but I'm using a script tag with a link to the script. is there any way to reset the closed nodes outside the script? |
Since no-one-else seems to have done it over the years, I've created a fork with this fix: https://github.com/tukkek/a-star. The performance improvement from being able to re-use the graph is massive. I estimate it's on the order of 100-times-faster or more on a project with a very-large-graph but I haven't actually bench-marked it. I have also created a pull-request, more out-of-respect for Brian than in any hope of it actually being merged: #81. Thank you for sharing your fix @manthrax! |
Subsequent searches on the same grid/graph will fail, since "closed" nodes are left over from the previous search.
Here is a fixed version of the "astar" method that saves off, and restores the closed nodes flags, before the path is returned.
`
var astar = {
/**
* Perform an A* Search on a graph given a start and end node.
* @param {Graph} graph
* @param {GridNode} start
* @param {GridNode} end
* @param {Object} [options]
* @param {bool} [options.closest] Specifies whether to return the
path to the closest node if the target is unreachable.
* @param {Function} [options.heuristic] Heuristic function (see
* astar.heuristics).
*/
search: function(graph, start, end, options) {
graph.cleanDirty();
options = options || {};
var heuristic = options.heuristic || astar.heuristics.manhattan,
closest = options.closest || false;
};
`
The text was updated successfully, but these errors were encountered: