Skip to content

chaitami/amazing1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

This project has been created as part of the 42 curriculum by yoech-ch, hel-achh.

A-Maze-ing πŸŒ€

Description

A-Maze-ing is a command-line maze generator and solver written in Python. The program reads a configuration file to define maze dimensions, entry/exit points, and an optional seed for reproducibility. It then generates a perfect maze (a maze with exactly one path between any two points) using a randomized depth-first search algorithm, displays it in the terminal, solves it by finding the shortest path, and exports the result to a file.

Key Features

  • Configurable maze dimensions, entry, exit, and seed via a simple config file
  • Maze generation using Randomized Depth-First Search (recursive backtracker)
  • Shortest path solving using BFS (Breadth-First Search)
  • Terminal display of both the unsolved and solved maze
  • Export maze to an output file
  • Interactive menu for choosing actions

Instructions

Prerequisites

  • Python 3.10+ installed on your system
  • pip package manager

Installation

git clone <repository-url> amazing
cd amazing
make install

This installs all dependencies listed in requirements.txt (flake8, mypy, pytest).

Execution

make run

Or manually:

python3 a_maze_ing.py config.txt

Debug Mode

make debug

Launches the program with Python's built-in debugger (pdb).

Linting

make lint          # mandatory checks (flake8 + mypy with required flags)
make lint-strict   # optional strict mypy checks

Clean

make clean

Removes __pycache__, .mypy_cache, .pytest_cache, and compiled .pyc/.pyo files.


Basic usage

from mazegen import MazeGenerator

gen = MazeGenerator(
    height=15,
    width=20,
    entry=(0, 0),
    exit=(19, 14),
    seed=42,
    perfect=True
)

gen.generate_a_maze(use_pattern=True)

grid = gen.get_grid()
path = gen.find_shortest_path()

print("Shortest path:", "".join(path))

Config File Structure

The configuration is defined in a plain-text file named config.txt at the project root. Each parameter is on its own line in KEY=VALUE format.

Key Required Type Range / Constraints Description
WIDTH βœ… Integer 1 – 100 Width of the maze (in cells)
HEIGHT βœ… Integer 1 – 100 Height of the maze (in cells)
ENTRY βœ… x,y Inside maze bounds (0 <= x < WIDTH, 0 <= y < HEIGHT) Entry point coordinates
EXIT βœ… x,y Inside maze bounds (0 <= x < WIDTH, 0 <= y < HEIGHT) Exit point
PERFECT βœ… Boolean True / False Whether maze is perfect
SEED ❌ Integer Any integer (omit for random generation) Seed for reproducible mazes
OUTPUT_FILE ❌ String Default: maze.txt (saved in output/) Name of the output file

Example config.txt

WIDTH=20
HEIGHT=10
ENTRY=0,0
EXIT=19,9
SEED=42
OUTPUT_FILE=maze.txt

Notes

  • Lines starting with # are treated as comments (recommended but not guaranteed in current version).
  • ENTRY and EXIT must be inside the maze bounds (0 <= x < WIDTH, 0 <= y < HEIGHT).
  • ENTRY and EXIT must not be the same point.
  • If SEED is omitted, the maze is generated randomly each run.

Maze Generation Algorithm

Algorithm: Randomized Depth-First Search (Recursive Backtracker)

The maze is generated using the Randomized DFS / Recursive Backtracker algorithm.

How It Works

  1. Start with a grid where every cell is surrounded by walls.
  2. Choose a starting cell (the entry point) and mark it as visited.
  3. From the current cell, pick a random unvisited neighbor.
  4. Remove the wall between the current cell and the chosen neighbor.
  5. Move to the chosen neighbor and repeat from step 3.
  6. If the current cell has no unvisited neighbors, backtrack to the previous cell.
  7. Repeat until all cells have been visited.

Result

This produces a perfect maze β€” one with:

  • Exactly one path between any two cells
  • No loops and no isolated sections

Why This Algorithm?

Reason Details
Simplicity Easy to understand and implement with a stack or recursion
Perfect mazes Guarantees a unique solution between any two points
Long, winding paths Produces aesthetically pleasing mazes with long corridors
Seed support Combined with random.seed(), mazes are fully reproducible
Educational value Excellent for learning graph traversal and backtracking

Alternative algorithms considered:

  • Kruskal's β€” produces shorter, more branching paths; more complex to implement.
  • Prim's β€” similar output but less intuitive for grid-based mazes.
  • Eller's β€” row-by-row generation, harder to debug and visualize.

Reusable Code

The project is structured in modular packages that can be reused independently:

Module / Package Reusable For
mazegen.py Reusable maze generator module (MazeGenerator)
utils/file_management.py Just For File Write Maza Hexa OutPut
parsing.py Generic KEY=VALUE config file parser
display.py Terminal-based 2D grid rendering

How to Reuse

from mazegen import MazeGenerator

gen = MazeGenerator(width=20, height=10, entry=(0, 0), exit=(19, 9), seed=42)
maze = gen.generate_a_maze()

The Generator class is self-contained and only depends on the Python standard library (random). It can be imported into any Python project without modification.


Team & Project Management

Team Members & Roles

Member Role
yoech-ch Display rendering, config parsing, Makefile, README & documentation
hel-achh Maze generation (DFS), solver (BFS), file export, project architecture

What Worked Well

  • Modular architecture made debugging and testing straightforward
  • Using a seed for reproducibility greatly simplified testing
  • The recursive backtracker was a good fit for the project scope

What Could Be Improved

  • Input validation could be more robust (bounds checking, border validation)
  • Recursive DFS hits Python's recursion limit on very large mazes (100Γ—100)
  • The interactive menu could handle invalid input more gracefully

Tools Used

Tool Purpose
Python 3 Main programming language
Git Version control
VS Code IDE
flake8 Code style linting
mypy Static type checking
pytest Unit testing
Make Build automation

Resources

Documentation & References

AI Usage

Task AI Used Details
Makefile creation βœ… GitHub Copilot assisted with Makefile structure and rules
Bug analysis βœ… GitHub Copilot used to systematically trace code paths and identify edge-case crashes
README writing βœ… GitHub Copilot assisted with structuring and formatting
Core algorithm (DFS/BFS) ❌ Implemented manually based on Wikipedia pseudocode
Config parsing ❌ Written manually
Display rendering ❌ Written manually

AI was used as a productivity tool for documentation, review, and testing β€” not for writing the core maze generation or solving logic.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published