Skip to main content

A Python library for generating mazes

Project description

SimpleMaze

A Python library for generating mazes.

Installation

pip install simplemaze

Usage

from simplemaze import Maze

# generates a 10x10 maze (width, height)
maze = Maze(10, 10)

# export the maze to an html file for printing
maze.export_to_html('maze.html')

# export the maze to an image file
maze.export_to_image('maze.png')

Algorithms

Recursive Backtracker (Depth-First Search)

from simplemaze import Maze

# generates a 10x10 maze (width, height) using the depth-first search algorithm
maze = Maze(10, 10, method='depth_first')

This algorithm is a simple depth-first search that starts at the top-left corner and randomly chooses a direction to move in. It then recursively calls itself to generate the maze.

This algorithm is very fast, and guarantees a unique solution if the maze has no cycles. However, it does not produce the most aesthetically pleasing mazes. Most of the time, it will create a maze that has a very long, winding solution with short dead ends.

Kruskal's Algorithm

from simplemaze import Maze

# generates a 10x10 maze (width, height) using Kruskal's algorithm
maze = Maze(10, 10, method='kruskal')

This algorithm is a more complex algorithm that guarantees a unique solution if the maze has no cycles. It works by randomly choosing two cells and removing the wall between them if they are not already connected. It then recursively calls itself to generate the maze.

It produces mazes that are much more aesthetically pleasing than the depth-first search algorithm, but are typically not as long as the depth-first search algorithm and easier to solve. However, it is slower than the depth-first search algorithm.

Prim's Algorithm (default)

from simplemaze import Maze

# generates a 10x10 maze (width, height) using Prim's algorithm
maze = Maze(10, 10, method='prim')

This algorithm is similar to Kruskal's algorithm, but it works by starting at a random cell and then growing the maze outward from there. It is faster than Kruskal's algorithm, but it produces mazes that are more challenging to solve with a shorter solution path but longer dead ends.

Wilson's Algorithm

from simplemaze import Maze

# generates a 10x10 maze (width, height) using Wilson's algorithm
maze = Maze(10, 10, method='wilson')

This algorithm is a more complex algorithm that guarantees a unique solution if the maze has no cycles (however, it is possible to generate a maze that has cycles with this algorithm). It works by starting at a random cell and then growing the maze outward from there. It is slower than Prim's algorithm, but it produces mazes that are more aesthetically pleasing and easier to solve.

Exporting to HTML

The HTML export is designed to be printed on standard 8.5x11 inch paper with 0.39 inch margins on all sides. The HTML file will automatically scale the maze to fit the page, so it will be as large as possible without cutting off the walls.

maze.export_to_html('maze.html')

Parameters

  • auto_scale: If true, the maze will be scaled to fit the page. If false, the maze will be scaled to the specified cell size.
  • cell_size: The size of each cell in the maze.
  • page_width: The width of the page in inches.
  • page_height: The height of the page in inches.
  • margin: The margin of the page in inches.
maze.export_to_html('maze.html', auto_scale=False, cell_size=20, page_width=8.5, page_height=11, margin=0.39)

Exporting to Image

The image export takes in a filename and a cell size. It will create a blank image of the specified cell size and draw the maze on it.

maze.export_to_image('maze.png')

Parameters

  • cell_size: The size of each cell in the maze.
  • wall_width: The width of the walls in the maze.
maze.export_to_image('maze.png', cell_size=20, wall_width=1)

Project details


Download files

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

Source Distribution

simplemaze-0.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

simplemaze-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file simplemaze-0.1.1.tar.gz.

File metadata

  • Download URL: simplemaze-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for simplemaze-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b309681efad25033debef5a1a1073d291ceb27cdf8609fc80ecb95fd83795a3b
MD5 9303033e92226c2740529d6ce223bcb8
BLAKE2b-256 d09c15b90a4582dbd5804d2a7c4ac5dfc73f570ed0a4b5640e78254d4af23bc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplemaze-0.1.1.tar.gz:

Publisher: python-publish.yml on david-pettifor-nd/simplemaze

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplemaze-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: simplemaze-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for simplemaze-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dbc5efd9a81f732d219a7564bf89f581204abbbebc58fcb2c382b10777cef19c
MD5 5bc28b1b0635f20412898620f5c5dad2
BLAKE2b-256 a224d7eef58ae187265c8c33fdd65a249aca9d604e86bc2d8d391b8bdcfca8f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplemaze-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on david-pettifor-nd/simplemaze

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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