Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Consider a situation in which you want to model mazes and be able to write a

ID: 3825697 • Letter: 1

Question

1. Consider a situation in which you want to model mazes and be able to write a program that will find a path through a maze. For example, consider the ASCII representation of a maze in Java below. Consider that each spot in the maze is either a wall 0, an open space Cn the starting spot (S), or the exit (E). a. How might you model a maze structure in Java? Specifically, describe how you would model the concept of a location in the maze along with the structure that you would use to organize the locations together into a maze (note that there are multiple ways to do this). b. If you needed to write code to travel through the maze, how would you keep track of the current location and the possible next locations given your answer to part (a)? Are you using an array with indexes? Are you using a linked structure? If you are at a location in the maze, how do you know what location is up, left, right, or down?

Explanation / Answer

1...

I only have idea to easily create maze using two dimensional array just like the matrix implementation and assigning it different values at any position.

int[][] cells = new int[20][20];
int dimensionX = 20;
int dimensionY = 20;
for (int x = 0; x < dimensionX; x++) {
for (int y = 0; y < dimensionY; y++) {
System.out.println(cells[x][y]);
}
       System.out.println(" ")
}

2...

In the same way, by using the nested loop, the maze location can be traversed one by one and the possible next location always be cells[x][y+1].
If the current location will be cells[x][y],
location at up will be cells[x-1][y]
location at left will be cells[x][y-1]
location at right will be cells[x][y+1]
location at down will be cells[x+1][y]