This project has been created as part of the 42 curriculum by horarivo.
A version made entirely by myself, with bonus part (animation)
| Maze generation preview | Path finding animation preview |
|---|---|
![]() |
![]() |
A-Maze-ing 2.0 is an enhanced version of the original A-Maze-ing project, featuring smooth animations and improved visual feedback. This interactive maze generator written in Python aims to produce visual and playable mazes from a configuration file while providing an animated generation process, shortest path solving, and a text export of the result.
- Animated Maze Generation: Watch the maze generate in real-time with smooth animations
- Animated Path Display: Visualize the shortest path with smooth animation effects
- Character Avatar: An interactive avatar displayed in the maze window
- 42 Pattern: Central "42" pattern to reinforce the visual identity of the project
- Color Palette Support: Cycle through different color schemes
The maze is rendered in an MLX window with enhanced visual polish and interactive elements.
- Python 3.10 or higher
mlxmodule compatible with Python 3 (provided asmlx-2.2-py3-none-any.whl, must be placed at the repository root)
A Makefile is provided to automate setup. It creates a virtual environment (.venv), installs the lint/build dependencies, and installs the MLX wheel into it:
make installThis runs, in order:
python3 -m venv .venv
. .venv/bin/activate && pip install --upgrade pip
. .venv/bin/activate && pip install -r requirements.txt
. .venv/bin/activate && pip install mlx-*.whlIf you prefer to do it manually:
- Install Python 3.10+.
- Create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activate- Install the lint/build dependencies:
pip install -r requirements.txt- Install the MLX module from the provided wheel:
pip install mlx-2.2-py3-none-any.whl- Edit
config.txtor create a custom configuration file. - Run the application:
make runor, equivalently:
. .venv/bin/activate && python3 a_maze_ing.py config.txtmake debug: runs the program underpdb.make lint: runsflake8andmypywith the mandatory flags.make lint-strict: runsflake8andmypy --strict.make clean: removes caches (__pycache__,.mypy_cache,.pytest_cache) and the.venvdirectory.
SPACE: regenerate a new mazeP: show/hide the shortest pathC: cycle through color palettesQorESC: quit the application
The configuration file must contain one value per line in KEY=VALUE format. Lines starting with # are comments and ignored.
Expected keys:
WIDTH: maze width in cells (integer >= 5)HEIGHT: maze height in cells (integer >= 5)ENTRY: entry coordinates inx,yformatEXIT: exit coordinates inx,yformatOUTPUT_FILE: output file pathPERFECT:TrueorFalseto enable or disable loopsSEED: optional integer to seed random generation
WIDTH=13
HEIGHT=11
ENTRY=0,0
EXIT=1,1
OUTPUT_FILE=maze.txt
PERFECT=True
SEED=42
The project uses the "Recursive Backtracker" algorithm to generate the maze. This algorithm walks the maze cells, opens passages to unvisited neighbors, and backtracks when no valid neighbor remains.
- It is simple to implement and easy to visualize.
- It produces perfect mazes with a single path between cells.
- It fits naturally with step-by-step animated generation.
- It is suitable for adding visual features such as the "42" pattern and path solving.
Reusable parts of the project include:
mazegen/config.py: configuration file parser that can be reused by other applications.mazegen/generator.py: independent maze generator that produces a grid of walls and passages.mazegen/solver.py: BFS solver for the shortest path in a maze grid.mazegen/renderer.py: rendering and file writing helpers.
These components can be reused in other maze, game, or graphical application projects.
- Central "42" pattern: some cells remain fully walled to draw the pattern.
- Interactive shortest path display.
- Three different color palettes.
PERFECT=Falseoption to generate imperfect mazes with loops.- Export of the result as a text file in the expected format.
a-maze-ing/
├── a_maze_ing.py - main executable
├── config.txt - example configuration
├── maze.txt - generated output file
├── Makefile - install / run / debug / clean / lint targets
├── pyproject.toml - package configuration
├── requirements.txt - development dependencies
└── mazegen/
├── __init__.py - public API of the package
├── app.py - MLX interface, rendering, and event handling
├── config.py - configuration parsing and validation
├── constants.py - constants and color palettes
├── generator.py - maze generation
├── renderer.py - rendering and output writing
└── solver.py - maze solving
horarivo: maze generation algorithm, design, and documentation, path finding algorithm, testing
- Analyze the project requirements and define features.
- Implement the configuration parser.
- Develop the maze generator.
- Add MLX rendering and the BFS solver.
- Integrate the "42" pattern, palettes, and keyboard controls.
- Test and export the output file.
- The modular project structure simplified implementation.
- Separating configuration, generation, rendering, and solving made the code easier to read.
- The "42" pattern adds a notable visual touch.
- Add multiple generation algorithms (Prim, Kruskal, Aldous-Broder).
- Allow dynamic loading of multiple configurations.
- Add more advanced rendering options (zoom, grid overlay, solver animation).
- Python 3.10+
pipandvenvfor dependency management and isolationmlx/ MiniLibX for graphical output- VS Code for development
- Git for version control
- Maze generation algorithm: depth-first search / recursive backtracker
- Breadth-first search (BFS) for shortest path solving
- MLX / MiniLibX documentation for graphical output
- Classic maze-related articles: "Maze generation algorithm" and "Depth-first search maze"
- Animation Implementation: AI assistance was used to implement smooth animations for maze generation and path display, improving the visual feedback and user experience.
- Code Quality: AI helped refactor and optimize the code to support animation features efficiently.
- Documentation: AI was used to enhance comments and docstrings throughout the codebase, making the code more maintainable and easier to understand for other developers.
- Code Review: AI provided suggestions for improving code consistency and best practices.

