A Python project that generates mazes using classic algorithms and visualizes them in real time using pygame. The project supports animated maze generation, algorithm selection from the terminal, and saving the maze to a data format for later use.
-
Maze generation using:
- Depth-First Search (Recursive Backtracker)
- Prim’s Algorithm
-
Real-time animated visualization using pygame
-
Clearly distinguishable walls, paths, start and exit
-
Moving pointer showing the active head of the generation algorithm
-
Terminal-based algorithm selection menu
-
Maze saved as JSON for reuse in solvers or replay
maze-generator/
│
├── main.py # Entry point
├── maze.json # Saved maze data
├── README.md # Project documentation- Python 3.9 or newer
- pygame
Install dependencies using:
pip install pygameRun the program from the terminal:
python main.pyYou will be prompted for:
- Maze width
- Maze height
- Algorithm selection
Enter maze width: 40
Enter maze height: 40
Select maze generation algorithm:
1. Depth-First Search (Recursive Backtracker)
2. Prim's Algorithm
Enter choice (1 or 2): 1The pygame window will open and animate the maze generation.
- Close the pygame window to end visualization
#WallPathSStartXExit
Internally, the maze is stored as a 2D grid of size:
(2 * width + 1) x (2 * height + 1)This ensures continuous walls and proper cell separation.
- Produces more evenly distributed paths
- More branching and shorter corridors
- Also generates perfect mazes
After generation, the maze is saved as:
maze.jsonThis file can be reused for:
- Maze solving algorithms (BFS, Dijkstra, A*)
- Analysis or export to other formats
- Very large mazes may require reducing cell size for display
- Recursive DFS can hit recursion limits for extremely large mazes
- Rendering extremely large grids may impact performance
This project is open for learning and experimentation.
Use and modify freely.

