Mazes and Stacks Andrew Rosen Abstract This lab will teach you about Mazes and Stacks and recursion and playing with Graphics, all the while knowing nothing about graphics or recursion. It also will...

1 answer below »
please use java and find a path start to exit and mark the all visited cells in the path as green otherwise as grey and show the output by IntelliJ.thank you


Mazes and Stacks Andrew Rosen Abstract This lab will teach you about Mazes and Stacks and recursion and playing with Graphics, all the while knowing nothing about graphics or recursion. It also will test your ability to work with unfamiliar code-bases and platforms. 1 Brief Problem Summary I’ve provided you with a few files to generate a maze. Your assignment is to create a basic maze solving algorithm to find it’s way from the top left corner of the maze to the bottom right. If we’re being generous we might say we’re making a very basic AI. To do so, you need to finish implementing solveMaze() method to perform a depth-first search using a stack.1 Don’t freak out if you don’t know anything about graphics. The most complicated thing you will be doing is changing the colors of a few squares. 2 Basic Maze-Solving Algorithm As I described in class, depth-first search is fairly straight-forward. When you have a choice in what direction to travel, make a choice. Follow that corridor and choose a new branch to go down as needed. If you reach a dead end, either because you’re blocked by walls or there’s nowhere new to visit, you backup until you find a new route to explore. The way we do this with an algorithm is a stack. push start position on top of stack while maze exploartion is not done and and stack isn’t empty peek to get our current position if we can go north and haven’t visited there yet push the location to the north on the stack mark the current location as visited else if we can go south... repeat for east and west 1A term that might be worth looking up on wikipedia. 1 else we can’t go anywhere so we are at a dead end mark current as a dead end pop off the stack Lookup depth first search for more details. The way this works for our code is that locations are represented by Cell objects and we can mark them visited by coloring them. 3 A Tour Of The Source Code Please watch the companion video and the lecture for more details. 3.1 Maze Run this class since it has the main method in it. It creates the MazeGridPanel and passes in parameters to set up how large of a maze you want. I’ve found that anything above a 100 × 100 maze is pretty slow. 3.2 MazeGridPanel This holds our actuals maze. Our maze is held in the 2D array of Cell objects, called maze. solveMaze() is your assignment and genDFSMaze() is your extra credit. solveMazeQueue() solves the maze using breadth-first search. visited() will check if the Cell at row or col has been visited by looking at the color (you should read this method.). genNWMaze() is the method I wrote that actually creates the maze. 3.3 Cell The maze is made up of individual pieces of a grid, each represented by a Cell. Each cell has a boolean for each of the four possible walls it can have in any direction, as well as a row and col for easy reference to its location in the maze. We’ll keep track of whether we’ve seen a Cell by coloring it. My code considers white and red cells unvisited (red is used to mark the exit of the maze). A cell colored anything else has been seen or visited in some way, shape, or form. We can change the color of a Cell using the setBackground method, which takes in a Color. We can retrieve the color of a Cell using the getBackground(). 4 Extra Credit: Maze Generation Complete genDFSMaze(), which will build a maze by using depth-first search. You can find the algorithm by clicking on this sentence, which is also a hyperlink. 2 https://en.wikipedia.org/wiki/Maze_generation_algorithm#Recursive_backtracker 5 Grading A partially working solution is worth 50 points. A fully working solution is 100 points. The extra credit problem is worth 5 points. 3 Brief Problem Summary Basic Maze-Solving Algorithm A Tour Of The Source Code Maze MazeGridPanel Cell Extra Credit: Maze Generation Grading
Answered Same DayMar 02, 2021

Answer To: Mazes and Stacks Andrew Rosen Abstract This lab will teach you about Mazes and Stacks and recursion...

Pulkit answered on Mar 03 2021
140 Votes
mazes and stacks/1.PNG
mazes and stacks/Cell.java
mazes and stacks/Cell.java
import java.awt.*;
import javax.swing.*;
public class Cell extends JPane
l{
    boolean northWall = true;
    boolean southWall = true;
    boolean eastWall = true;
    boolean westWall = true;
    int row;
    int col;
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLACK);
        //g.drawString(row +"," + col, 10, 10);
        int y = this.getHeight();
        int x = this.getWidth();
        g.setColor(Color.BLACK);
        if(northWall) {
            g.drawLine(0,0,x, 0);
        }if(southWall) {
            g.drawLine(0,y,x, y);
        }if(eastWall) {
            g.drawLine(x,0,x, y);
        }if(westWall) {
            g.drawLine(0,0,0, y);
        }
    }
    public Cell(int row, int col ) {
        this.setBackground(Color.WHITE);
        this.row = row;
        this.col = col;
        northWall = true;
        southWall = true;
        eastWall = true;
        westWall = true;
    }
}
mazes and stacks/Maze.java
mazes and stacks/Maze.java
import javax.swing.JFrame;
public class Maze extends JFrame {
    public Maze() {
        this.add(new MazeGridPanel(10,10));
        this.setSize(800, 800);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.pack();
        this.setVisible(true);
    }
    public static void main(String[] args) {
        new Maze();
    }
}
mazes and stacks/MazeGridPanel.java
mazes and...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here