Skip to content

Java application which generates mazes based on the size wanted by user. The application uses recursive backtracking algorithm in order to generate mazes.

Notifications You must be signed in to change notification settings

Sergey-Mr/Maze-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creator: Serhii Tupikin

Description

Java application which generates mazes based on the size wanted by user. The application uses recursive backtracking algorithm in order to generate mazes.

Algorithm explanation

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.

Implementation logic

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.

Launch instructions

  1. Clone the repository
git clone https://github.com/Sergey-Mr/Maze-generator.git
  1. Navigate to the root folder:
cd Maze-generator/
  1. Compile the application:
javac src/objects/*.java
javac --module-path lib --add-modules javafx.controls,javafx.fxml src/gui/Driver.java
  1. Run it:
java --module-path lib --add-modules javafx.controls,javafx.fxml src.gui.Driver

UML Class Diagram

UML Class Diagram

Directory strucutre

Maze-generator

├── lib
│ ├── javafx.controls
│ └── javafx.fxml

├── src
│ ├── gui
│ │ └── Driver.java
│ └── objects
│ └── Cell.java
│ └── Maze.java

├── images
│ └── UML-class-diagram.png

└── README.md

Tehcnologies

This project was created with:

  • Java 17.0.11
  • JavaFX SDK 22.0.1
  • Ubuntu 22.04.4 LTS

About

Java application which generates mazes based on the size wanted by user. The application uses recursive backtracking algorithm in order to generate mazes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages