bgrins / javascript-astar

A* Search / Pathfinding Algorithm in Javascript
https://briangrinstead.com/blog/astar-search-algorithm-in-javascript-updated/
MIT License
1.36k stars 323 forks source link

Start Node is not marked as dirty, and thus never visited on subsequent path queries #36

Open BonsaiDen opened 9 years ago

BonsaiDen commented 9 years ago

Adding a graph.markDirty(start); right infront of the while loop in the search function seems to fix this.

bgrins commented 9 years ago

Hi, could you please share a test case where this is failing so we can add test coverage for this?

ammarabdulsalam commented 9 years ago

Hi, I can confirm this issue, I couldn't reproduce it using a small graph. adding @BonsaiDen fix resolves the issue, sample code:

var graph = new Graph([
    [1,1,1,1],
    [1,0,1,0],
    [0,0,1,1]
]);
var start = graph.grid[0][0];
var end = graph.grid[1][2];
var result = astar.search(graph, start, end);
console.log(result);
result = astar.search(graph, end, start);
console.log(result);