You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the values in the grid are modified between the function easystar.setGrid(grid); and the functions easystar.findPath(...); easystar.calculate(); a "valid but not shortest" path is found.
Code Example
Using node.js:
var easystarjs = require('easystarjs');
var easystar = new easystarjs.js();
var grid = [[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1],
[1,1,1,1,1]];
console.log(JSON.stringify(grid));
easystar.setGrid(grid);
easystar.setAcceptableTiles(0);
for (let y = 0; y < grid.length; ++y) {
for (let x = 0; x < grid[y].length; ++x) {
grid[y][x] = 0;
}
}
grid[2][2] = 1
console.log(JSON.stringify(grid));
// enabling the following line makes it work correctly:
// easystar.setGrid(grid);
easystar.findPath(2, 3, 1, 2, function (path) {
if (path === null) {
console.log("Path was not found.");
} else {
console.log("Path of length %d was found.", path.length);
console.log(JSON.stringify(path));
}
});
easystar.calculate();
Expected Result
A path of length 3:
[[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]
[[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]
Path of length 3 was found.
[{"x":2,"y":3},{"x":1,"y":3},{"x":1,"y":2}]
Actual Result
A path of length 7 - which is valid but not the shortest path:
[[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]
[[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]
Path of length 7 was found.
[{"x":2,"y":3},{"x":2,"y":4},{"x":1,"y":4},{"x":0,"y":4},{"x":0,"y":3},{"x":0,"y":2},{"x":1,"y":2}]
Additional Information
easystar.js: 0.4.4
node.js: 12.19.0
os: Windows 7 64 Bit
P.S.
Nice library, very easy to use, few dependencies, perfect for my use case - except this little annoyance.
The text was updated successfully, but these errors were encountered:
If the values in the grid are modified between the function
easystar.setGrid(grid);
and the functionseasystar.findPath(...); easystar.calculate();
a "valid but not shortest" path is found.Code Example
Using node.js:
Expected Result
A path of length 3:
Actual Result
A path of length 7 - which is valid but not the shortest path:
Additional Information
easystar.js: 0.4.4
node.js: 12.19.0
os: Windows 7 64 Bit
P.S.
Nice library, very easy to use, few dependencies, perfect for my use case - except this little annoyance.
The text was updated successfully, but these errors were encountered: