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

Bug with pathfinding solution #26

Open
kevinbror opened this issue Jul 21, 2022 · 0 comments
Open

Bug with pathfinding solution #26

kevinbror opened this issue Jul 21, 2022 · 0 comments

Comments

@kevinbror
Copy link

I think there is a bug with the pathfinding solution where it doesn't get neighbors correctly when the grid isn't square.

const getNeighbors = (visited, x, y) => {

if (y - 1 >= 0 && !visited[y - 1][x].closed) { is up
and ln 85 if (y + 1 < visited[0].length && !visited[y + 1][x].closed) { is down. Since we move up and down ln 85 should check visited.length not visited[0].length else it can run out of bounds with non square (rectangular) grids. Conversely ln 95 should be flipped to check visited[0].length since that is left and right and the nested arrays represent Xs max size.

I'm enjoying the course. Thanks!

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

1 participant