Java application which generates mazes based on the size wanted by user. The application uses recursive backtracking algorithm in order to generate mazes.
Consider the space for a maze being a large grid of cells (like a large chess board), each cell starting with four walls. Starting from a random cell, the computer then selects a random neighbouring cell that has not yet been visited. The computer removes the wall between the two cells and marks the new cell as visited, and adds it to the stack to facilitate backtracking. The computer continues this process, with a cell that has no unvisited neighbours being considered a dead-end. When at a dead-end it backtracks through the path until it reaches a cell with an unvisited neighbour, continuing the path generation by visiting this new, unvisited cell (creating a new junction). This process continues until every cell has been visited, causing the computer to backtrack all the way back to the beginning cell. We can be sure every cell is visited.
Instead of implementing maze generation recursively, I decided to use the element of java.util Stack in order to avoid stack overflow. The maze is a 2D array containing Cell obejcts (see UML diagram below). The user is able to select the size of the maze by specifying the number of rows and columns which 2D array will have.
- Clone the repository
git clone https://github.com/Sergey-Mr/Maze-generator.git- Navigate to the root folder:
cd Maze-generator/- Compile the application:
javac src/objects/*.java
javac --module-path lib --add-modules javafx.controls,javafx.fxml src/gui/Driver.java- Run it:
java --module-path lib --add-modules javafx.controls,javafx.fxml src.gui.DriverMaze-generator
│
├── lib
│ ├── javafx.controls
│ └── javafx.fxml
│
├── src
│ ├── gui
│ │ └── Driver.java
│ └── objects
│ └── Cell.java
│ └── Maze.java
│
├── images
│ └── UML-class-diagram.png
│
└── README.md
This project was created with:
- Java 17.0.11
- JavaFX SDK 22.0.1
- Ubuntu 22.04.4 LTS
