Skip to content
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

Allow Diagonal #37

Open
akubeejays opened this issue Jul 11, 2013 · 8 comments
Open

Allow Diagonal #37

akubeejays opened this issue Jul 11, 2013 · 8 comments

Comments

@akubeejays
Copy link

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

@qiao
Copy link
Owner

qiao commented Jul 12, 2013

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.

@akubeejays
Copy link
Author

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.

@qiao
Copy link
Owner

qiao commented Jul 12, 2013

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.

@akubeejays
Copy link
Author

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 #37 (comment) . https://github.com/notifications/beacon/3snu1tkl9JD8oSdg7_1940VU1aGahrIc51__Y6coHhZedzHlgb7u0Y_5BclmtXNY.gif

@horaguchi
Copy link

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?

@imor
Copy link
Collaborator

imor commented Nov 4, 2014

Will be fixed once #63 is done.

@imor
Copy link
Collaborator

imor commented Dec 22, 2014

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.

@horaguchi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants