PathFinding.js icon indicating copy to clipboard operation
PathFinding.js copied to clipboard

Allow Diagonal

Open akubeejays opened this issue 11 years ago • 8 comments

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);

akubeejays avatar Jul 11 '13 10:07 akubeejays

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.

qiao avatar Jul 12 '13 05:07 qiao

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.

akubeejays avatar Jul 12 '13 06:07 akubeejays

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.

qiao avatar Jul 12 '13 06:07 qiao

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

akubeejays avatar Jul 12 '13 06:07 akubeejays

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?

horaguchi avatar Jan 17 '14 23:01 horaguchi

Will be fixed once https://github.com/qiao/PathFinding.js/pull/63 is done.

imor avatar Nov 04 '14 15:11 imor

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 avatar Dec 22 '14 14:12 imor

@imor Sorry for the late reply: I tried it and it works correctly :). Thank you very much.

horaguchi avatar Mar 30 '15 10:03 horaguchi