Main Menu

Deitel Exersices
Downloads
Contact ME


 


Back


Links
CE Main Site
Sharif University
Wikipedia
2Del
PHP
Javascript





    

In the name of GOD


Deitel Exercise : 5.25

     (Maze Traversal) The grid of hashes (#) and dots (.) in Fig. 5.43 is a double-subscripted array representation of a maze. In the double-subscripted array, the hashes (#) represent the walls of the maze and dots represent the squares in the possible path through the maze. Moves can be made only to a location in the array that contains a dot.

     There is a single algorithm for walking through maze that guarantees finding the exit (assuming that there is an exit). If there is not an exit, you will arrive at the starting location again. Place your right hand on the wall to your write and begin walking forward. Never remove your hand from the ball. If the maze turns to the right, you follow the wall to the right. As long as you don’t remove your hand from the wall, eventually you will arrive at the exit of the maze. There may be a shorter path than the one you have taken, but you are guaranteed to get out of the maze if you follow the algorithm.

# # # # # # # # # # # #
# o o o # o o o o o o #
o o # o # o # # # # o #
# # # o # o o o o # o #
# o o o o # # # o # o o
# # # # o # o # o # o #
# o o # o # o # o # o #
# # o # o # o # o # o #
# o o o o o o o o # o #
# # # # # # o # # # o #
# o o o o o o # o o o #
# # # # # # # # # # # #
Fig. 5.43 Double-subscripted array representation of a maze.

     Write recursive function mazeTraverse to walk through the maze. The function should receive as arguments a 12-by-12 character array representing the maze and the location of the maze. As mazeTraverse attempts to locate the exit from the maze, it should place the character X in each square in the path. The function should display the maze after each move so the user can watch as the maze is solved.