Question: 7 . 3 3 ( Maze Traversal ) The grid of hashes ( # ) and dots ( . ) in Fig. 7 . 2

7.33(Maze Traversal) The grid of hashes (#) and dots (.) in Fig. 7.27 is a two-dimensional built-
in array representation of a maze. In the two-dimensional built-in array, the hashes represent the
walls of the maze and the dots represent squares in the possible paths through the maze. Moves can
be made only to a location in the built-in array that contains a dot.
There is a simple algorithm for walking through a maze that guarantees finding the exit
(assuming that there is an exit). If there is not an exit, you'll arrive at the starting location again,
Place your right hand on the wall to your right and begin walking forward. Never remove your
hand from the wall. If the maze turns to the right, you follow the wall to the right. As long as you
do not remove your hand from the wall, eventually you'll arrive at the exit of the maze. There may
be a shorter path than the one you've taken, but you are guaranteed to get out of the maze if you
follow the algorithm.
Do not solve this project with recursion. Instead, follow the right-hand rule as described in the text and below.
Program a rat (your maze runner) to have a direction: up, right, down, and left (can be coded 0,1,2,3), as its forward direction. Based on which of the four directions, it should then try to go right relative to its forward direction. E.g. if facing up then step right, if facing right then step down, facing down then left, etc. But in the case of facing up, if you can't go right, then try to go forward. If not, try going left, otherwise step backward (which you can always do). If you successfully take a step in that direction, change the direction for the next iteration. You may backtrack, of course, as you never become blocked. As you step forward, change the. to *; if you backtrack, then change the * to -. Of course, don't go through a wall #. Print the matrix/maze at each step. Stop when the rat finds the exit. There is a lot of similar code (16 cases) but it is not easy to abstract to a function. so you don't have to try. code in C++ please
 7.33(Maze Traversal) The grid of hashes (#) and dots (.) in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!