Question: JAVA PROGRAMMING Take a 2D String Array containing a grid and turn it into a maze using the following Psuedocode : create a CellStack (LIFO)

JAVA PROGRAMMING Take a 2D String Array containing a "grid" and turn it into a maze using the following Psuedocode: 

create a CellStack (LIFO) to hold a list of cell locations set TotalCells= number of cells in grid choose the starting cell and call it CurrentCell set VisitedCells = 1 while VisitedCells < TotalCells find all neighbors of CurrentCell with all walls intact if one or more found choose one at random knock down the wall between it and CurrentCell push CurrentCell location on the CellStack make the new cell CurrentCell add 1 to VisitedCells else pop the most recent cell entry off the CellStack make it CurrentCell

//--------------------------------------------------------

Code for blank grid:

int row; int column; int cell; String[][] grid;
public void createGrid(){ for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[i].length; j++) { if (j % 2 == 1) { grid[i][j] = "-"; } else if (i % 2 == 1) { grid[i][j] = "|"; } else { grid[i][j] = "+"; } if (i % 2 == 1 && j % 2 == 1) { grid[i][j] = " "; } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!