PathFinding.js
PathFinding.js copied to clipboard
Allow Diagonal
I tried to allow diagonal but it does not find a solution when "dontcrosscorners" is set to false. is any one else facing the same issue and can anyone help me with a solution ?
var matrix = [ [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 0, 1, 0, 1, 1], [1, 1, 1, 0, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1],
]; var grid = new PF.Grid(7, 5, matrix);
var finder = new PF.AStarFinder({ allowDiagonal: true, dontCrossCorners: false
});
var path = finder.findPath(2, 2, 4, 2, grid);
https://github.com/qiao/PathFinding.js/blob/master/src/core/Grid.js#L170
+-----+-----+-----+
| | A | B |
+-----|-----|-----+
| | C | D |
+-----|-----|-----+
| | | |
+-----+-----+-----+
For the current implementation,
if dontCrossCorners is set to true, then, in order to go from C to B, both A and B must be walkable,
and if dontCrossCorners is set to false, then at least one of A and B must be walkable.
There's no way if neither of A nor B is walkable. I think I should add another strategy into the algorithm to make it possible.
Is there any code changes you can recommend for me to change to allow this until it is made into the final release?
Regards, Ben (Sent from my iPhone)
On 12 Jul 2013, at 13:42, Xueqiao Xu [email protected] wrote:
https://github.com/qiao/PathFinding.js/blob/master/src/core/Grid.js#L170
+-----+-----+-----+ | | A | B | +-----|-----|-----+ | | C | D | +-----|-----|-----+ | | | | +-----+-----+-----+For the current implementation,
if dontCrossCorners is set to true, then, in order to go from C to B, both A and B must be walkable,
and if dontCrossCorners is set to false, then at least one of A and B must be walkable.
There's no way if neither of A nor B is walkable. I think I should add another strategy into the algorithm to make it possible.
— Reply to this email directly or view it on GitHub.
Yes, you can modify the code starting from this line: https://github.com/qiao/PathFinding.js/blob/master/src/core/Grid.js#L170
delete the if-else block and assign d0, d1, d2 and d3 to be all true and that's done.
Perfect J
From: Xueqiao Xu [mailto:[email protected]] Sent: Friday, July 12, 2013 2:17 PM To: qiao/PathFinding.js Cc: akubeejays Subject: Re: [PathFinding.js] Allow Diagonal (#37)
Yes, you can modify the code starting from this line: https://github.com/qiao/PathFinding.js/blob/master/src/core/Grid.js#L170
delete the if-else block and assign d0, d1, d2 and d3 to be all true and that's done.
— Reply to this email directly or view it on GitHub https://github.com/qiao/PathFinding.js/issues/37#issuecomment-20860218 . https://github.com/notifications/beacon/3snu1tkl9JD8oSdg7_1940VU1aGahrIc51__Y6coHhZedzHlgb7u0Y_5BclmtXNY.gif
Yes, you can modify the code starting from this line: https://github.com/qiao/PathFinding.js/blob/master/src/core/Grid.js#L170
delete the if-else block and assign d0, d1, d2 and d3 to be all true and that's done.
I use PathFinding.js with this modification too. I am very happy if I can upgrade version without every modification. Would it be possible to optionize this?
Will be fixed once https://github.com/qiao/PathFinding.js/pull/63 is done.
Hi @horaguchi #63 is mostly done apart from polishing the docs. But the code is not yet released in a new version (I don't have the access to release to npmjs yet :( ) so you'll have to use the code from the repo. Read the user guide for more information.
@imor Sorry for the late reply: I tried it and it works correctly :). Thank you very much.