Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the starter code for assignment 1 Java application to make the maze data structure 3-dimensional. Valid moves should now be east, west, north, south,

Modify the starter code for assignment 1 Java application to make the maze data structure 3-dimensional. Valid moves should now be "east", "west", "north", "south", "up" and "down". Use the following definition for the grid. // A maze grid with 3 levels (up and down) private int[][][] grid = {{ {1,1,1,1,0,1,1,1,0,1,1,0}, // Level 0 {0,0,0,1,1,1,0,1,1,1,0,0}, {0,0,1,0,0,0,1,0,0,1,1,0}, {1,0,0,0,0,1,1,0,1,1,0,0}, {0,0,1,1,1,1,1,1,1,0,1,0}, {0,1,1,1,1,1,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,0,0,1,0}, {1,1,1,1,1,0,0,1,1,0,1,0}, {0,0,0,0,0,0,1,1,1,0,1,0}, {1,1,1,1,1,0,0,0,1,0,0,0}, {1,1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,0,0,0,0,0,0,0,0} }, { {0,1,1,1,0,0,1,1,0,1,1,0}, // Level 1 {0,0,0,1,1,0,0,1,0,1,0,0}, {0,0,0,0,0,0,1,0,0,0,1,0}, {1,0,0,0,0,1,1,0,1,0,0,0}, {0,0,0,0,1,1,1,1,1,0,1,0}, {0,1,0,1,1,0,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,0,0,1,0}, {1,0,0,0,1,0,0,1,1,0,1,0}, {0,0,0,0,0,0,1,1,1,0,1,0}, {1,1,0,1,1,0,0,0,0,0,0,0}, {1,0,0,0,0,1,1,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0} }, { {0,1,1,1,0,0,1,1,0,1,1,0}, // Level 2 {0,0,0,1,1,0,0,1,0,1,0,0}, {1,1,1,0,0,0,1,0,0,0,1,0}, {1,0,0,0,0,1,1,0,1,0,0,0}, {0,0,1,1,1,1,1,1,1,0,1,0}, {0,1,1,1,1,0,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,0,0,1,0}, {1,1,1,1,1,0,0,1,1,0,1,0}, {0,0,0,0,0,0,1,1,1,0,1,0}, {0,0,0,0,1,0,0,0,1,0,0,0}, {0,0,0,0,0,0,1,1,0,1,1,1}, {1,1,1,1,0,0,0,0,0,0,0,1} }}; The grid entrance is at the array position [0][0][0] and the exit is at [2][11][11].

Starter Code:

package source;

public class PA2{

// 2D Version private int[][] maze = { {1,1,1,1,0,1,1,1,0,1,1,0}, {0,0,0,1,1,1,0,1,0,1,0,0}, {0,0,1,0,0,0,1,1,0,0,1,0}, {1,0,0,0,0,1,1,0,1,0,0,0}, {0,0,1,1,1,1,1,1,1,0,1,0}, {0,1,1,1,1,0,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,0,0,1,0}, {1,1,1,1,1,0,0,1,1,0,1,0}, {0,0,0,0,0,0,1,1,1,0,1,0}, {1,1,1,1,1,0,0,0,1,0,0,0}, {1,1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,0,0,0,0,0,0,0,1} }; /* 3D Version private int [][][] maze = {{ {1,1,1,1,0,1,1,1,0,1,1,0}, // Level 0 {0,0,0,1,1,1,0,1,1,1,0,0}, {0,0,1,0,0,0,1,0,0,1,1,0}, {1,0,0,0,0,1,1,0,1,1,0,0}, {0,0,1,1,1,1,1,1,1,0,1,0}, {0,1,1,1,1,1,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,0,0,1,0}, {1,1,1,1,1,0,0,1,1,0,1,0}, {0,0,0,0,0,0,1,1,1,0,1,0}, {1,1,1,1,1,0,0,0,1,0,0,0}, {1,1,1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,0,0,0,0,0,0,0,0} },

{ {0,1,1,1,0,0,1,1,0,1,1,0}, // Level 1 {0,0,0,1,1,0,0,1,0,1,0,0}, {0,0,0,0,0,0,1,0,0,0,1,0}, {1,0,0,0,0,1,1,0,1,0,0,0}, {0,0,0,0,1,1,1,1,1,0,1,0}, {0,1,0,1,1,0,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,0,0,1,0}, {1,0,0,0,1,0,0,1,1,0,1,0}, {0,0,0,0,0,0,1,1,1,0,1,0}, {1,1,0,1,1,0,0,0,0,0,0,0}, {1,0,0,0,0,1,1,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0} },

{ {0,1,1,1,0,0,1,1,0,1,1,0}, // Level 2 {0,0,0,1,1,0,0,1,0,1,0,0}, {1,1,1,0,0,0,1,0,0,0,1,0}, {1,0,0,0,0,1,1,0,1,0,0,0}, {0,0,1,1,1,1,1,1,1,0,1,0}, {0,1,1,1,1,0,1,1,0,1,1,0}, {0,0,0,0,0,0,1,1,0,0,1,0}, {1,1,1,1,1,0,0,1,1,0,1,0}, {0,0,0,0,0,0,1,1,1,0,1,0}, {0,0,0,0,1,0,0,0,1,0,0,0}, {0,0,0,0,0,0,1,1,0,1,1,1}, {1,1,1,1,0,0,0,0,0,0,0,1} }}; */

int rowsize, colsize; boolean done = false;

public PA2() { /**************************** * * Add your code here * ***************************/

if (!done) // If no path found, print error message System.out.println("Error - no path to exit!"); System.out.println(); } public boolean traverse(int row,int col) { /**************************** * * Add your code here * ***************************/ return done; } public void printPosition(int row, int col) { if (row == 0 && col == 0) System.out.println("["+row+"]"+"["+col+"]"); else System.out.print("["+row+"]"+"["+col+"]-->"); } public static void main(String[] args) { PA2 pa2 = new PA2(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions