Design or generate a new maze for the MazeSearch program in this chapter, and rerun the program. Explain the processing in terms of your new maze, giving examples of a path that was tried but failed, a path that was never tried, and the ultimate solution.
What will be an ideal response?
or a 0 in each cell of a two-dimensional array. Because the likelihood of generating a maze with a solution is generally low, subsequent mazes could be generated using a while loop until a maze with a solution is generated.
A maze with a solution could be hard-coded with the following statement:
private int [][] grid = {{1,0,1,0,1,1,1,1,1},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{1,1,1,0,1,0,1,0,1},
{0,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{1,0,1,1,1,1,1,0,1}};
After the search arrives at position (5,0), it attempts position (6,0). Encountering a 0 causes this path to fail. It then attempts position (5,1) which succeeds. Subsequently, position (6,1) fails and position (5,2) succeeds.Because the maze is traversed successfully from position (5,2), no attempt is ever made to find a path from position (4,1). The following grid shows the solution path marked with 7s.
7 0 1 0 1 1 7 7 7
7 0 1 0 1 0 7 0 7
7 0 1 0 1 0 7 0 7
7 0 1 0 1 0 7 0 7
7 0 1 0 1 0 7 0 7
7 7 7 0 1 0 7 0 7
0 0 7 0 1 0 7 0 7
1 0 7 0 1 0 7 0 7
1 0 7 0 1 0 7 0 7
1 0 7 0 1 0 7 0 7
1 0 7 7 7 7 7 0 7
You might also like to view...
Bike shares in major cities in which you use a smart phone to rent a bike are examples of ________
Fill in the blank(s) with correct word
In rectangular array items, which expression below retrieve the value at row 3 and column 5?
a) items[3. 4] b) items[3][4] c) items[3, 4] c) None of the above.