NASA has decided to incorporate a 3-dimensional maze on the space station to give astronauts exercise. The engineers reasoned that in weightlessness astronauts should be able to move up or down, left or right, forward or backward (but NOT diagonally) with equal ease. The maze is a cube 5 by 5 by 5 with walls covering the outside and floors/ceilings separating each of the levels. The maze is represented in a file as follows
x x x x x x x
This is layer 0 - the floor of level #1. It contains
x x x x x x x
the only entrance to the maze (x in an impenetrable area, o is
x x x x x x x
open) located at position (3,2,0) in this case - regarding the
x x o x x x x
first number as the row number, the second as the column number,
x x x x x x x
and the third as the layer number (counting each of these
x x x x x x x
starting at zero).
x x x x x x x
x x x x x x x
This is level #1 (layer 1); it contains many open areas.
x x o o o o x
Typically, levels are far more open than the floors/ceilings
x x o x x x x
which have only a few open areas. The open position directly
x o o o x o x
above the entrance is at (3,2,1), shown in bold. From here
an
x o x x x o x
astronaut can move to (3,1,1), then (4,1,1) and (5,1,1), where
x o o x o o x
he/she can go through the ceiling.
x x x x x x x
x x x x x x x
This is layer 2 (ceiling of level #1 and floor for level #2).
x x x x x o x
As you can see, there are only a few openings to allow
x x x x x x x
passage from level #1 to level #2. From (5,1,1), the open
x x x x x o x
position in the ceiling (5,1,2) can be used to reach level #2.
x x x x x x x
x o x x o x x
x x x x x x x
x x x x x x x
This is level #2 (layer 3). It can be entered at (5,1,3), as
x o o o o o x
well as other places. From here, the astronaut can go to
x o x x x o x
(5,2,3), then (4,2,3) and (3,2,3). If he/she is lucky, there
x x o x o o x
will be an opening to layer 4 above one of these. If not
x x o x o x x
lucky, some backtracking will be required.
x o o x o o x
x x x x x x x
The file contains 11 such layers of 7 x 7 sets of characters: one for each of the levels and one for each floor/ceiling below or above a level. Note that the outer rows and columns of the 7 x 7 array from the walls of the maze. After the 11 layers of information, the file contains three numbers, the coordinates of the entry to the maze (row, column, and level) - for this maze it is 3 2 0.
Write a program that prompts
for the maze file name, reads the file and displays a path through the
maze by showing the coordinates of each move through the maze until the
exit is reached on the 11th layer. The path should be displayed something
like this: 3,2,0 3,2,1 3,1,1 4,1,1 5,1,1
5,1,2 5,1,3 etc. The path should NOT show all the wrong
turns made; it should be the final shortest path. You can practice
with the file maze1.txt