This project has been created as part of the 42 curriculum by smahraz, smakkass.
A maze generation program with graphical and terminal-based visualization, animation support, and path finding capabilities.

- Description
- Features
- Instructions
- Configuration File
- Maze Generation Algorithms
- Reusable Components
- Advanced Features
- Team and Project Management
- Resources
A-Maze-ing is a maze generation and visualization tool developed in Python. The program generates rectangular mazes using configurable algorithms, displays them through either a graphical user interface (GUI) or a text-based terminal interface (TUI), and supports animated generation as well as path finding from entry to exit.
The project is structured as a modular application with a reusable maze generation library (mazegen) that can be installed independently.
- Rectangular maze generation with configurable dimensions
- Two generation algorithms: DFS and Prim
- Perfect and imperfect maze options
- GUI and TUI display modes
- Step-by-step generation animation
- Path finding from entry to exit
- Configurable entry and exit positions
- Reproducible results via seed configuration
- Maze export to file
- Python 3.10 or higher
- Minilibx (mlx-*.whl)
- Clone the repository:
git clone https://github.com/saidmakkass/A-Maze-ing.git
cd A-Maze-ing- Install dependencies:
make installRun with the default configuration:
make runOr specify a custom configuration file:
python3 a_maze_ing.py <config_file>Example:
python3 a_maze_ing.py default_config.txtThe configuration file uses a simple KEY=VALUE format. Lines starting with # are comments.
# Comment lines start with #
KEY=VALUE
| Key | Required | Description | Default |
|---|---|---|---|
WIDTH |
Yes | Maze width (Greater than 8) | - |
HEIGHT |
Yes | Maze height (Greater than 6) | - |
ENTRY |
Yes | Starting position (format: x,y) |
- |
EXIT |
Yes | Ending position (format: x,y) |
- |
OUTPUT_FILE |
Yes | Path to save the generated maze | - |
PERFECT |
Yes | Perfect maze with single solution (True/False) |
- |
SEED |
No | Random seed for reproducible generation | Random |
ALGORITHM |
No | Generation algorithm (DFS or PRIM) |
DFS |
INTERFACE |
No | Display mode (gui or tui) |
gui |
WIDTH=25
HEIGHT=15
ENTRY=10,10
EXIT=1,1
OUTPUT_FILE=maze.txt
PERFECT=False
SEED=1234567
ALGORITHM=DFS
INTERFACE=gui
Depth-First Search (DFS)
- Creates long, winding passages
- Produces aesthetically pleasing maze patterns
- Simple implementation
Prim's Algorithm
- Creates more uniform, branching patterns
- Produces visually appealing animations during generation
Each algorithm has distinct strengths:
- DFS produces more visually appealing final mazes with long corridors and is simpler to implement. It is recommended for general use.
- Prim generates mazes with more uniform branching and looks impressive when animated.
We implemented both to give users flexibility based on their preferences and use cases.
The mazegen/ module is a standalone, reusable maze generation library with no external dependencies. It can be installed and used independently in any Python project.
pip install mazegen-*.whlfrom mazegen import MazeGenerator
# Create and generate a maze
gen = MazeGenerator(width=20, height=10, algorithm="DFS", perfect=True, seed=42, entry=(0, 0), exit=(19, 9))
maze = gen.generate_maze()
# Find solution path
path = MazeGenerator.generate_path(maze)
print("Solution:", "".join(direction for _, direction in path))MazeGenerator(
width: int, # Maze width (columns)
height: int, # Maze height (rows)
algorithm: str, # "DFS" or "PRIM"
perfect: bool, # True = no loops, False = some extra passages
seed: int, # Random seed for reproducibility
entry: tuple[int, int], # Starting cell (x, y)
exit: tuple[int, int] # Ending cell (x, y)
)| Parameter | Type | Description |
|---|---|---|
width |
int |
Number of columns (must be > 0) |
height |
int |
Number of rows (must be > 0) |
algorithm |
str |
Generation algorithm: "DFS" or "PRIM" |
perfect |
bool |
True for single-solution maze, False for additional openings |
seed |
int |
Random seed for reproducible generation |
entry |
tuple[int, int] |
Entry coordinates (x, y) |
exit |
tuple[int, int] |
Exit coordinates (x, y) |
from mazegen import MazeGenerator
gen = MazeGenerator(width=10, height=8, algorithm="DFS", perfect=True, seed=123, entry=(0, 0), exit=(9, 7))
maze = gen.generate_maze()
# Access the 2D grid of cells
grid = maze.map # list[list[Cell]]
# Access specific cell
cell = grid[y][x]
# Check wall states
print(f"North wall closed: {cell.north.is_closed}")
print(f"East wall closed: {cell.east.is_closed}")
# Access neighbors
north_cell = cell.above_cell # Cell or None
south_cell = cell.below_cell
east_cell = cell.right_cell
west_cell = cell.left_cellfrom mazegen import MazeGenerator
gen = MazeGenerator(width=20, height=15, algorithm="DFS", perfect=True, seed=42, entry=(0, 0), exit=(19, 14))
maze = gen.generate_maze()
# Get solution path (list of (Cell, direction) tuples)
path = MazeGenerator.generate_path(maze)
# Directions: 'N' (north), 'S' (south), 'E' (east), 'W' (west)
for cell, direction in path:
print(f"From ({cell.x}, {cell.y}) go {direction}")
# Get solution as direction string
solution = "".join(direction for _, direction in path)
print(f"Solution: {solution}")from mazegen import MazeGenerator
gen = MazeGenerator(width=10, height=10, algorithm="DFS", perfect=True, seed=123, entry=(0, 0), exit=(9, 9))
# Get maze and steps for animation
maze, steps = gen.generate()
# Each step contains: x, y, wall (direction opened)
for step in steps:
print(f"Step at ({step.x}, {step.y}), opened wall: {step.wall}")| Method | Returns | Description |
|---|---|---|
generate_maze() |
Maze |
Generate maze without recording steps |
generate() |
tuple[Maze, list[Step]] |
Generate maze with animation steps |
generate_steps() |
list[Step] |
Generate and return only the steps |
generate_path(maze) |
list[tuple[Cell, str]] |
Static method - find path from entry to exit |
output() |
str |
Export maze as encoded string with solution |
reseed() |
None |
Assign a new random seed |
A full graphical interface for maze visualization with:
- Real-time maze rendering
- Path visualization
- Interactive controls
A terminal-based interface featuring:
- ANSI color rendering
- Animated maze generation
- Path display toggle
- Color theme cycling
Both interfaces support step-by-step visualization of the maze generation process.
Users can switch between DFS and Prim algorithms via the configuration file to achieve different maze characteristics.
| Member | Role |
|---|---|
| smahraz | TUI development, maze algorithms (DFS), build configuration |
| smakkass | GUI development, parser, path finding, PRIM algorithm |
Initial Approach: Each team member claimed the parts they were most interested in working on. After individual implementation, we collaborated to fix bugs, improve code style, and ensure consistency.
Communication: Frequent communication was maintained throughout the project to coordinate integration and resolve issues promptly.
- Code from each team member integrated smoothly with the other's work
- Clear division of responsibilities allowed parallel development
- Regular communication prevented integration issues
- Code efficiency could be optimized further
- Git for version control and collaboration
- Maze Generation: Prim's Algorithm - Jamis Buck
- Maze Generation Algorithm Overview (YouTube)
- Maze Algorithms Visualization (YouTube)
AI tools were used in this project for:
- Debugging: Locating stubborn logic bugs that were difficult to identify manually
- Learning: Understanding new Python concepts and best practices
AI was not used for generating core algorithm implementations or project architecture.


