This project has been created as part of the 42 curriculum by yelgoumr, ayfadli
Terminal maze generator and solver project with interactive visualization.
- Generates mazes with two algorithms:
- Recursive Backtracking
- Hunt-and-Kill
- Solves the generated maze with BFS (shortest path).
- Renders the maze in terminal with theme switching and optional animation.
- Plays background music/effects through
pygame.
- Recursive Backtracking: simple to implement, guarantees perfect mazes (one unique path between any two cells), and is well suited for step‑by‑step visualization.
- Hunt-and-Kill: offers a different maze style and randomness pattern while still producing perfect mazes, which makes side‑by‑side comparison interesting.
- BFS solver: breadth‑first search naturally finds the shortest path in an unweighted grid and is easy to reason about and animate level by level.
a_maze_ing.py: main interactive CLI application.parse.py: config parsing and validation.mazegen/: reusable generation package.Path_finder/maze_solver.py: BFS solver.Maze_Display/display.py: terminal rendering and animation.config.txt: default runtime config.requirements.txt: runtime dependencies.
Detailed package docs are in mazegen/README.md.
The maze generation engine is packaged in mazegen/ so it can be reused in other projects:
- Import the generator class and call it with your own dimensions and configuration.
- Use the returned grid/graph structure as input for different solvers or visualizations.
Example usage from another Python script:
from mazegen.RecBTGenerator import RecBTGenerator
generator = RecBTGenerator(config={
'WIDTH': 20,
'HEIGHT': 20,
'ENTRY': (0, 0),
'EXIT': (19, 19),
'PERFECT': True,
'SEED': 1,
})
maze = generator.generate()This separation allows you to plug the same generation logic into GUIs, web apps, or additional analysis tools without relying on the CLI.
- Python 3.9+
pip- Terminal that supports ANSI colors and Unicode
- Audio support for
pygame.mixer(optional, can be toggled in app)
Runtime:
pygame(listed inrequirements.txt)
Install dependencies from repository root:
python3 -m pip install -r requirements.txtOptional (for lint/type checks used in this repo):
python3 -m pip install mypy flake8Optional editable install of local package:
python3 -m pip install -e .By default the app reads config.txt. You can also pass a custom file path.
Required keys in config file:
WIDTHHEIGHTENTRYEXITOUTPUT_FILEPERFECT
Optional key:
PATTERN(recommended values:42or1337)SEED
Example:
WIDTH=20
HEIGHT=20
ENTRY=0,0
EXIT=19,19
OUTPUT_FILE=maze_output
PERFECT=True
SEED=1
PATTERN=42From repository root:
python3 a_maze_ing.pyUse a custom config file:
python3 a_maze_ing.py path/to/config.txtThe app opens an interactive menu where you can:
- regenerate a maze,
- show/hide solution path,
- rotate themes,
- switch generation algorithm,
- toggle path animation,
- reload config,
- toggle sound.
The CLI expects these assets to exist:
sounds/background_theme.mp3sounds/meow.mp3
If audio causes issues in your environment, disable sound from the in-app menu.
Using makefile targets:
make run
make lint
make cleanEquivalent direct commands:
python3 -m flake8 .
python3 -m mypy . --warn-return-any --warn-unused-ignores --ignore-missing-imports --disallow-untyped-defs --check-untyped-defs-
yelgoumr
- Implemented recursive backtracking generator
- Implemented Hunt-and-Kill generator
- Implemented configuration parser
- Implemented runtime config reload
- Built reusable
mazegenpackage - Handled packaging structure
- Ensured algorithm abstraction
-
ayfadli
- Implemented BFS pathfinder
- Implemented shortest path visualization
- Implemented terminal display system
- Implemented animation system
- Integrated solver with generator history
Initial plan
- Build generator
- Add solver
- Add display
- Add animation
- Add sound
- Refactor into reusable modules
Evolution
- Started as a single-file design
- Refactored into a modular architecture
- Extracted generation logic into a dedicated package
- Added configuration hot-reload feature
- Improved separation of concerns between generation, solving, display, and config
- Modular architecture
- Clear responsibility separation
- Reusable generation engine
- Animation history tracking
- Add unit tests
- Add benchmarking
- Improve CLI UX
- Add more algorithms (Prim, Kruskal)
- Python 3
flake8mypymakepygame- Git
- Terminal ANSI rendering
- Multiple generation algorithms
- Shortest path solving (BFS)
- Interactive CLI menu
- Theme switching
- Animated solving
- Sound toggle
- Runtime config reload
- Perfect maze option
- Seed control for reproducibility
Maze generation
- Recursive Backtracking: https://en.wikipedia.org/wiki/Maze_generation_algorithm
- Hunt-and-Kill: https://weblog.jamisbuck.org/2011/1/24/
BFS
- Documentation: https://en.wikipedia.org/wiki/Breadth-first_search
- Video: https://www.youtube.com/watch?v=KiCBXu4P-2Y
Python packaging
AI tools were used for:
- Algorithm comparison research
- Documentation structure improvement
- Code review suggestions
- Refactoring recommendations
- Error explanation assistance
AI was not used to directly generate full project logic without understanding. All algorithms were implemented manually and validated by testing.
This project demonstrates:
- Strong algorithmic implementation
- Clean architecture principles
- Runtime safety validation
- Modular design
- Real-world packaging practice
It reflects collaborative teamwork and a structured engineering approach aligned with the 42 curriculum philosophy.
Config file not found: run from repository root or pass config path explicitly.Configuration Error: verify required keys and value formats in config file.- No sound / mixer errors: ensure system audio backend is available, or turn sound off.
- Display glitches: use a terminal with ANSI + Unicode support.
Maze generation is built around three core concepts:
-
BaseGenerator
An abstract base class (inmazegen/BaseGenerator.py) that defines common behaviour for all maze-generation algorithms (grid handling, seeding, walk history, imperfect maze post-processing, etc.). -
Concrete generators
KillHuntGenerator(mazegen/kill_hunt_generator.py): implements the hunt-and-kill algorithm.- The recursive-backtracking generator (
mazegen/rec_bt_generator.py): implements the recursive backtracking algorithm.
Both classes inherit from
BaseGenerator. -
MazeGeneratorfacade
Themazegen/MazeGenerator.pymodule exposes aMazeGeneratorclass that acts as a small factory for algorithm-specific generators:from mazegen.MazeGenerator import MazeGenerator import parse as parser # parse_config() populates parser.config parser.parse_config() factory = MazeGenerator() rec_bt_gen = factory.rec_bt_generator(parser.config) kill_hunt_gen = factory.kill_hunt_gen(parser.config) # Each returned object is a BaseGenerator subclass: rec_bt_gen.generate() kill_hunt_gen.generate()
The CLI entrypoint (
a_maze_ing.py) uses this facade to construct generators instead of instantiating algorithm classes directly.
To add a new maze-generation algorithm:
- Implement a new class that inherits from
BaseGenerator. - Implement the required abstract methods (e.g.
generate()). - Optionally expose a convenience constructor in
mazegen/MazeGenerator.MazeGenerator(similar torec_bt_generator()andkill_hunt_gen()).