A Python-based maze generator and solver using a recursive backtracking algorithm. Visualizes maze construction and pathfinding with a GUI window.
- Procedural maze generation with randomized paths
- Recursive backtracking algorithm to create and solve the maze
- Unit-tested core logic (cell creation, wall breaking, solving path)
- Support for deterministic randomness via a user-defined seed
-
Maze Generation:
- Grid of
Cellobjects initialized with all walls. _break_walls_ruses randomized depth-first search to knock down walls and form a solvable maze.
- Grid of
-
Maze Solving:
solve()starts at the top-left corner and recursively finds a path to the bottom-right.draw_moveanddraw_undomethods visualize forward and backtracking steps.
-
Entrance/Exit:
- The top wall of the first cell and the bottom wall of the last cell are removed.
- Python 3.10+
venvfor isolated environment
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
# Install dependencies (if any)
pip install -r requirements.txtsudo apt-get install python3-tk
python3 -m src.mainbash test.shor directly:
python -m unittest discover unittests
maze_solver/
├── src/
│ ├── main.py # Entry point
│ ├── maze.py # Maze logic
│ ├── cell.py # Cell representation
│ └── window.py # Window drawing abstraction
├── unittests/
│ └── tests.py # Unit tests
├── test.sh # Test runner script
├── requirements.txt # Optional: dependencies list
└── README.md
Change CATPPUCCIN color scheme for different maze themes.
Swap in your own rendering layer by adapting the Window interface.
MIT License
Built with love and recursion 🌀
