JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (oldest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Re: Queues (response to post by anujkrmodi) | Reply
Yep, in this case one should consider all directions, so that's a bug.

Also, while You are enqueuing a state, You should mark the state as visited (in a separate array, or just change the position in the maze into a wall), then "canMove" should check if a state is already visited - if so, return false.
Queues | Reply
Is it okay that we are considering only 3 directions in the Queue algo to solve for path from A to B. What if the path is like(we need to consider all 4 directions):

A----------****----------
**********|**|**********|
**********|***---*******|
**********|******|******|
***********------*******|
************************B

Also, if we take all the 4 directions, it might end up in loop.
P.S: Hope the question is clear :)
RSS