Skip to main content

mazegen

A Python maze generator with two generation algorithms, configurable entry/exit points, obstacle patterns, and a built-in shortest-path solver.

Features

  • Two generation algorithms
    • IB — Iterative Backtracking (fast, produces long winding corridors)
    • wilson — Wilson's algorithm (loop-erased random walk, produces a uniform spanning tree with no generation bias)
  • Reproducible output — pass a seed to get the same maze every time
  • Custom size, entry, and exit — any rectangular grid, entry/exit placed anywhere inside it
  • Obstacle patterns — carve a fixed shape into the center of the maze that generation routes around
  • Shortest-path solver — BFS from entry to exit, returned as a string of moves (N/E/S/W)
  • File export — writes the maze, entry/exit coordinates, and solution path to a plain text file

Requirements

  • Python 3.10+

Usage

from pathlib import Path
from maze import MazeGenerator

maze = MazeGenerator(
    size=(15, 15),
    entry_cell=(0, 0),
    exit_cell=(14, 14),
    algorithm="wilson",   # or "IB"
    seed=42,
)

maze.export(Path("maze.txt"))

print(maze.maze)            # 2D grid of wall bitmasks
print(maze.shortest_path)   # e.g. "EESSWW..."

Constructor options

Parameter Type Description
size tuple[int, int] (width, height) of the grid
entry_cell tuple[int, int] Starting cell coordinates
exit_cell tuple[int, int] Goal cell coordinates
perfect bool Reserved for perfect-maze mode
seed int | None Seed for reproducible generation
algorithm "IB" | "wilson" Which generation algorithm to use
pattern list[tuple[int, int]] Optional shape (relative coordinates) to carve into the center

How a cell is stored

Each Cell tracks its four neighbors (n, e, s, w) and a 4-bit walls value, one bit per direction. A bit set to 1 means that wall is present; clearing a bit removes the wall between two adjacent cells.

Export format

export() writes:

  1. One line per maze row — each cell as a single hex digit (its walls value)
  2. A blank line
  3. The entry coordinates (x,y)
  4. The exit coordinates (x,y)
  5. The shortest path as a string of N/E/S/W moves

Algorithm notes

  • Iterative Backtracking carves the maze in one continuous depth-first walk with backtracking — simple and fast, but biased toward long corridors with fewer short branches.
  • Wilson's algorithm grows the maze by running loop-erased random walks from every unvisited cell until it joins the existing maze. This guarantees an unbiased, uniformly random spanning tree, at the cost of more randomness in generation time.

Notes

  • Validation errors raise ValueError (invalid size/entry/exit) or MazeGeneratorError (invalid pattern) — check these when integrating.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mazegen42-0.0.3.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mazegen42-0.0.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file mazegen42-0.0.3.tar.gz.

File metadata

  • Download URL: mazegen42-0.0.3.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mazegen42-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c269d43c07b6a02756a571d7ab1cbb8fa3df4f462c352b6eccb26978673fa385
MD5 4c4bace72be2eb3266a9d0dd3476df13
BLAKE2b-256 a9f15d2c0a7c96cfb56f0bb58f12d6fe9da47b9a0cfc364d784f67cec4a490aa

See more details on using hashes here.

File details

Details for the file mazegen42-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: mazegen42-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mazegen42-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fce1721128957e6179571f4059634080c6955c5640c9a1fc276121cc041a4261
MD5 c9bf1107e6ded69be6aebb440cfd248a
BLAKE2b-256 6d7c03e48fafc88431680aefb0bd01ddaeede4330ff463f66799f5600cc8e528

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page