This project has been created as part of the 42 curriculum by lmezzaba, lurossi.
A-Maze-ing is a maze generation project developed in Python.
The goal of the project is to generate valid mazes from a configuration file, export them using a hexadecimal wall representation, display them visually, and provide a reusable maze generation package.
The project supports:
- Perfect mazes.
- Imperfect mazes.
- Reproducible generation using a seed.
- ASCII rendering.
- Shortest path computation.
- Export to hexadecimal format.
- Reusable maze generation library.
- Python 3.10 or newer
python3 a_maze_ing.py config.txtpython3 -m pip install build
python3 -m buildGenerated files:
dist/
├── mazegen-lmezzaba-lrossi-1.0.0.tar.gz
└── mazegen-lmezzaba-lrossi-1.0.0-py3-none-any.whl
pip install dist/*.whlThe configuration file contains one key-value pair per line.
Example:
WIDTH=15
HEIGHT=15
ENTRY=0,0
EXIT=14,14
OUTPUT_FILE=maze.txt
PERFECT=True
SEED=42
| Key | Description |
|---|---|
| WIDTH | Maze width |
| HEIGHT | Maze height |
| ENTRY | Entry coordinates |
| EXIT | Exit coordinates |
| OUTPUT_FILE | Output filename |
| PERFECT | Perfect maze flag |
| Key | Description |
|---|---|
| SEED | Random seed |
The maze is generated using a Recursive Backtracker (Depth First Search).
Algorithm steps:
- Start from the entry cell.
- Mark the current cell as visited.
- Randomly choose an unvisited neighbour.
- Remove the wall between the two cells.
- Continue recursively.
- Backtrack when no unvisited neighbour remains.
- Stop when every reachable cell has been visited.
Recursive Backtracker was chosen because:
- It is simple to implement.
- It guarantees a connected maze.
- It naturally produces perfect mazes.
- It is memory efficient.
- It generates visually pleasing mazes.
For imperfect mazes, additional walls may be removed after generation to create loops.
Each cell is represented by a hexadecimal digit.
Wall encoding:
| Bit | Direction |
|---|---|
| 0 | North |
| 1 | East |
| 2 | South |
| 3 | West |
Example:
A
Binary:
1010
Meaning:
- East wall closed
- West wall closed
After the maze data:
<maze>
entry_x,entry_y
exit_x,exit_y
NESW...
The final line contains the shortest path.
The maze can be displayed using terminal ASCII rendering.
Displayed elements:
- Walls
- Entry
- Exit
- Solution path
- 42 pattern
Available interactions:
- Generate a new maze
- Show solution
- Hide solution
- Change wall colour
The reusable component of the project is the MazeGenerator class.
Example:
from mezagen import MazeGenerator
maze = MazeGenerator("config.txt")
maze.display()
maze.save_maze()
solution = maze.solve()The reusable module provides access to:
- Maze structure
- Entry position
- Exit position
- Generated maze
- Solution path
Responsibilities:
- Maze generation
- Maze solving
- File export
- Package creation
Responsibilities:
- Parsing
- Testing
- Documentation
- Validation
- Configuration parser
- Maze data structure
- Maze generation
- Maze export
- Visual display
- Packaging
During development:
- Additional validation was added.
- Solution path generation was added.
- Reusable package support was improved.
- Visualization features were expanded.
- DFS generation algorithm.
- Reusable architecture.
- Export format generation.
- Type checking with mypy.
- Additional generation algorithms.
- MLX graphical interface.
- Maze generation animations.
- Performance optimizations for large mazes.
- Python 3.10+
- setuptools
- build
- mypy
- flake8
- Git
- GitHub
- Recursive Backtracker
- Depth First Search
- Graph Theory
- Spanning Trees
- Python Documentation
- PEP 8
- PEP 257
- setuptools Documentation
Run all mandatory static analysis checks:
flake8 . && \
python3 -m mypy a_maze_ing.py mazegen \
--warn-return-any \
--warn-unused-ignores \
--ignore-missing-imports \
--disallow-untyped-defs \
--check-untyped-defsAI tools were used for:
- Type hint verification
- Documentation drafting