Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maze Generator and Solver

Maze generation with recursive backtracking, solved with breadth-first search, animated in Swing. No third-party dependencies.

Breadth-first search spreading through a maze and finding the shortest path

Running

Needs JDK 21 or newer and Maven.

mvn compile
java -cp target/classes io.github.abdrahmanayach.maze.Main

Or open the folder in IntelliJ and run Main.

The two algorithms

Recursive backtracking builds the maze. Starting from a grid with every wall intact, it carves a random depth-first path, backtracking whenever the current cell has no unvisited neighbours. The result is a perfect maze: no loops, no unreachable cells, exactly one route between any two of them.

Breadth-first search solves it. Each cell records the one it was reached from, so the shortest path falls out of walking those links back from the exit. The solver also returns the order cells were dequeued, which is what the panel animates.

Files

File What it does
Maze.java The grid and its walls, plus the generator
Solver.java Breadth-first search, returns the search order and the path
MazePanel.java Draws it, and a Timer reveals the search one cell at a time
Main.java Window and the two buttons

About

Maze generator and solver with animated BFS pathfinding

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages