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

Feature Request: "Get as close as possible" option when the path is blocked #10

Closed
sefabaser opened this issue Jul 5, 2020 · 4 comments

Comments

@sefabaser
Copy link

sefabaser commented Jul 5, 2020

Sample Code

let finder = new AStarFinder({
  grid: {
    matrix: [
      [0, 0, 0, 0],
      [0, 1, 1, 0],
      [0, 1, 0, 1],
      [0, 1, 1, 0]
    ]
  },
  heuristic: 'Manhatten',
  diagonalAllowed: false
});

console.log(finder.findPath({ x: 0, y: 0 }, { x: 3, y: 3 }));

Current Behaviour

Because the path is blocked to target there is no path is found.
output: []

Expected Behaviour

Having an option "getAsCloseAsPossible". Which will find to the path to x: 3, y: 1 position.
output: [[1, 0], [2, 0], [3, 0], [3, 1]]

Note:
It is, of course, possible to find an alternative target position manually. But the next available position to the target is the position x: 2, y: 2 which is also not reachable. The complexity of finding the closest available position is lower on finding it in the shortest path algorithm.

@sefabaser
Copy link
Author

Still, this feature is needed, any progress?

@digitsensitive
Copy link
Owner

@sefabaser Thank you for your input. The Feature was implemented in the latest version 1.2.7. Maybe you can check it out and see if it works for you?

@thilidric
Copy link

It does not work.

@sefabaser
Copy link
Author

Unfortunately, it does not work. It is giving wrong results.

Sample 1:

    let finder = new AStarFinder({
      grid: {
        matrix: [
          [0, 0, 0, 0],
          [0, 1, 1, 0],
          [0, 1, 0, 1],
          [0, 1, 1, 0]
        ]
      },
      heuristic: 'Manhatten',
      diagonalAllowed: false,
      allowPathAsCloseAsPossible: true
    });
    console.log(finder.findPath({ x: 0, y: 0 }, { x: 3, y: 3 }));

Output: [ [ 0, 0 ], [ 0, 1 ], [ 0, 2 ] ]
Expected: [[ 0, 0 ], [1, 0], [2, 0], [3, 0], [3, 1]]

Sample 2:

    let finder = new AStarFinder({
      grid: {
        matrix: [
          [0, 0, 0, 0, 0],
          [0, 1, 1, 1, 0],
          [0, 1, 1, 1, 0],
          [0, 1, 0, 1, 1],
          [0, 1, 1, 0, 0]
        ]
      },
      heuristic: 'Manhatten',
      diagonalAllowed: false,
      allowPathAsCloseAsPossible: true
    });
    console.log(finder.findPath({ x: 0, y: 0 }, { x: 3, y: 3 }));

Output: []
Expected: [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [4, 1], [4, 2]]

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

No branches or pull requests

3 participants