Algorithm Maze (maze, start)
Find the goal in a maze using a queue (breadth first search)
create an empty queue named Q;
enqueue start in Q;
while Q is not empty do
current dequeue from Q;
if current is the goal then
output “Success!”;
Q empty queue; {to end the loop}
else if current is not a wall and current is not marked as visited then
mark current as visited;
enqueue in Q the point to the right of current;
enqueue in Q the point to the left of current;
enqueue in Q the point above current;
enqueue in Q the point below current;
end if
end while
No comments:
Post a Comment