# PyMazeBuilder
Generate perfect mazes with Python using a growing tree algorithm.
---
## Installation
```bash
pip install pymazebuilder
```
---
```bash
█████████████████████
█░░░░░░░░░█░░░░░░░░██
██░░░░░░░░█░█████░███
█░░░░░░░░░░░█░░██░░░█
█░░░░░░░░░█░█░█████░█
█░░░░░░░░░█░░░█░░░█░█
█░░░░░░░░░█████░█░█░█
███░░░░██░░░░░░░█░░░█
███░███████████████░█
█░░░█░░░░░█░░░░░░░░░█
█░███░███░█░█████████
█░█░░░███░█░█░░░░░░░█
█░█░███░█░█░█░█████░█
█░█░██░░█░█░░░█░░██░█
█░█░██░░█░█████░███░█
█░░░█░░░░░░░█░░░░░█░█
█░███░░░░░░░█░███░█░█
█░██░░█░░░░░█░█░░░█░█
█░███░█░█████░█░███░█
█░░░░░█░░░░░░░█░░░░░█
█████████████████████
```
Generated data structure
```python
{
grid: [
[
Cell {
x: 0,
y: 0,
exits: [],
blocked: true,
displayed: false,
visited: false
},
...
]
]
rooms: [
Room {
x: 0,
y: 0,
width: 0,
height: 0
}
]
}
```
---
## Quick use
```python
from pymazebuilder.generators.generator import Generator
from pymazebuilder.generators.maze import MazeGenerator
from pymazebuilder.renderer import Renderer
Renderer(Generator([
{
'generator': MazeGenerator,
'options': {
'width': 10,
'height': 10,
'floors': 1
}
},
]))
```
---
## Randomization
`utils.py` contains a random class which handles all random number generation and can be seeded.
---
### Generator classes
Generator classes can be passed as an optional array of objects to the maze generator.
The shape of this data structure is as follows:
```python
[
{
generator: <generator class>,
options: <options object>
},
...
]
```
`Generator` (`src/pymaze/generator.py`) will iterate over each generator class and instantiate it.
**Example**
The following example shows how to generate a maze with rooms using the provided room generator.
(also see `src/pymaze/main.py`)
```python
from pymazebuilder.generators.generator import Generator
from pymazebuilder.generators.renderer import Renderer
Generator([
{
'generator': MazeGenerator,
'options': {
...
}
},
{
'generator': RoomGenerator,
'options': {
...
}
},
{
'generator': StairsGenerator,
'options': {
...
}
}
])
Renderer(generator)
```
#### Multi-floor maze
Use the `floors` option to generate a multi-floor maze.
Use the `src/generators/stairs.py` generator to connect the floors with stairs.
```bash
Floor 0
█████████████████████
█░██░░░░░██░░░░░░░░░█
█░███░█░███░░░░░█░█░█
█░░░█░█░░░░░█░░░█░█░█
███▼█░█░█████████░█░█
█░░░█░█░░░█░░░░░█░███
█░███░███░█░███░█░███
█░█░░░░██░█░█░░░█░░░█
█░█░█████░█░█░█░█░░░█
█░█░░░░░█░███░█░█░░░█
█░█░░██░█░███░█░█░░░█
█░█░░░█░█░░░░░█░░░█░█
█░███░█░███░░░░░█░█░█
█░██░░█░░░░░░░█░░░█░█
█░███████████░█░███░█
█░░░█░░░█░░░█░░░█░░░█
███░█░█░█░█░█████░█░█
███░░░█░█░█░░░░░░░█░█
█░█████░█░███░░░░░█░█
█░░░░░░░░░██░░░░░░░░█
█████████████████████
Floor 1
█████████████████████
█░░░░░░░░░█░░░░░░░░██
██░░░░░░░░█░█████░███
█░░░░░░░░░░░█░░██░░░█
█░░▲░░░░░░█░█░█████░█
█░░░░░░░░░█░░░█░░░█░█
█░░░░░░░░░█████░█░█░█
███░░░░██░░░░░░░█░░░█
███░███████████████░█
█░░░█░░░░░█░░░░░░░░░█
█░███░███░█░█████████
█░█░░░███░█░█░░░░░░░█
█░█░███░█░█░█░█████░█
█░█░██░░█░█░░░█░░██░█
█░█░██░░█░█████░███░█
█░░░█░░░░░░░█░░░░░█░█
█░███░░░░░░░█░███░█░█
█░██░░█░░░░░█░█░░░█░█
█░███░█░█████░█░███░█
█░░░░░█░░░░░░░█░░░░░█
█████████████████████
▲ = stairs going up
▼ = stairs going down
█ = wall
░ = floor
```
---
#### Custom generator classes
Custom generators should match the following pattern.
```python
class SomeGenerator:
def __init__(data: dict, options: dict):
# do something with the data object
self.data = data
self.data["some_property"] = "some value"
```
See `src/pymaze/room.py` and `src/pymaze/maze.py` for complete examples along with a list of optional arguments that each class takes.
---
## License
[GNU GPL 3](LICENSE)
---
## Contributors
- [@w4ffl35](https://github.com/w4ffl35)
Raw data
{
"_id": null,
"home_page": "https://github.com/w4ffl35/PyMazeBuilder",
"name": "pymazebuilder",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "maze, builder, generator, rpg, game, development",
"author": "w4ffl35",
"author_email": "contact@capsizegames.com",
"download_url": "https://files.pythonhosted.org/packages/a9/a0/d846dddc347598ca05128997a6937895157222a4cf5ae8813b85367594f0/pymazebuilder-1.3.2.tar.gz",
"platform": null,
"description": "# PyMazeBuilder\n\nGenerate perfect mazes with Python using a growing tree algorithm.\n\n---\n\n## Installation\n\n```bash\npip install pymazebuilder\n```\n\n---\n\n```bash\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\n\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2588\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2588\n\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\n\u2588\u2588\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2588\u2591\u2588\u2588\u2591\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2588\u2588\u2591\u2588\n\u2588\u2591\u2588\u2591\u2588\u2588\u2591\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n```\n\nGenerated data structure\n\n```python\n {\n grid: [\n [\n Cell {\n x: 0,\n y: 0,\n exits: [],\n blocked: true,\n displayed: false,\n visited: false\n },\n ...\n ]\n ]\n rooms: [\n Room {\n x: 0,\n y: 0,\n width: 0,\n height: 0\n }\n ]\n }\n```\n\n---\n\n## Quick use\n\n```python\nfrom pymazebuilder.generators.generator import Generator\nfrom pymazebuilder.generators.maze import MazeGenerator\nfrom pymazebuilder.renderer import Renderer\nRenderer(Generator([\n {\n 'generator': MazeGenerator,\n 'options': {\n 'width': 10,\n 'height': 10,\n 'floors': 1\n }\n },\n]))\n```\n\n---\n\n## Randomization\n\n`utils.py` contains a random class which handles all random number generation and can be seeded.\n\n---\n\n### Generator classes\n\nGenerator classes can be passed as an optional array of objects to the maze generator.\n\nThe shape of this data structure is as follows:\n\n```python\n[\n {\n generator: <generator class>,\n options: <options object>\n },\n ...\n]\n```\n\n`Generator` (`src/pymaze/generator.py`) will iterate over each generator class and instantiate it.\n\n**Example**\n\nThe following example shows how to generate a maze with rooms using the provided room generator.\n\n(also see `src/pymaze/main.py`)\n\n```python\nfrom pymazebuilder.generators.generator import Generator\nfrom pymazebuilder.generators.renderer import Renderer\n\nGenerator([\n {\n 'generator': MazeGenerator,\n 'options': {\n ...\n }\n },\n {\n 'generator': RoomGenerator,\n 'options': {\n ...\n }\n },\n {\n 'generator': StairsGenerator,\n 'options': {\n ...\n }\n }\n])\n\nRenderer(generator)\n```\n\n#### Multi-floor maze\n\nUse the `floors` option to generate a multi-floor maze.\n\nUse the `src/generators/stairs.py` generator to connect the floors with stairs.\n\n```bash\nFloor 0\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n\u2588\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2588\n\u2588\u2588\u2588\u25bc\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2588\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\n\u2588\u2591\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2591\u2591\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\n\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\n\u2588\u2588\u2588\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\nFloor 1\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\n\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2588\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2588\n\u2588\u2591\u2591\u25b2\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2588\n\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2588\n\u2588\u2588\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\n\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2588\u2591\u2588\u2588\u2591\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2588\u2588\u2591\u2588\n\u2588\u2591\u2588\u2591\u2588\u2588\u2591\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2588\u2591\u2591\u2591\u2588\u2591\u2588\n\u2588\u2591\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2588\u2588\u2591\u2588\u2591\u2588\u2588\u2588\u2591\u2588\n\u2588\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2588\u2591\u2591\u2591\u2591\u2591\u2588\n\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n\n\u25b2 = stairs going up\n\u25bc = stairs going down\n\u2588 = wall\n\u2591 = floor\n```\n\n---\n\n#### Custom generator classes\n\nCustom generators should match the following pattern.\n\n```python\nclass SomeGenerator:\n def __init__(data: dict, options: dict):\n # do something with the data object\n self.data = data\n self.data[\"some_property\"] = \"some value\"\n```\n\nSee `src/pymaze/room.py` and `src/pymaze/maze.py` for complete examples along with a list of optional arguments that each class takes.\n \n---\n\n## License\n\n[GNU GPL 3](LICENSE)\n\n---\n\n## Contributors\n\n - [@w4ffl35](https://github.com/w4ffl35)\n",
"bugtrack_url": null,
"license": "AGPL-3.0",
"summary": "RPG",
"version": "1.3.2",
"project_urls": {
"Homepage": "https://github.com/w4ffl35/PyMazeBuilder"
},
"split_keywords": [
"maze",
" builder",
" generator",
" rpg",
" game",
" development"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "be2aaddb5845ab0cb0ba20dc0ce64720a68198d600c5eebe55f6fa503b3c31db",
"md5": "827d7443feabf71e4beca3bb549ff58b",
"sha256": "0938adffd5c8362e3690d39eebc1cf9570f14febd2edc8515d0050cd804c47c6"
},
"downloads": -1,
"filename": "pymazebuilder-1.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "827d7443feabf71e4beca3bb549ff58b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 21517,
"upload_time": "2024-10-29T18:26:14",
"upload_time_iso_8601": "2024-10-29T18:26:14.889595Z",
"url": "https://files.pythonhosted.org/packages/be/2a/addb5845ab0cb0ba20dc0ce64720a68198d600c5eebe55f6fa503b3c31db/pymazebuilder-1.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a9a0d846dddc347598ca05128997a6937895157222a4cf5ae8813b85367594f0",
"md5": "962a0b0fe2061a30bd8d3f707bad40b6",
"sha256": "c76ee9702bda7fb5091326d89aa8b1df7d5e50f845f6ee9723bd8a8f13c828e9"
},
"downloads": -1,
"filename": "pymazebuilder-1.3.2.tar.gz",
"has_sig": false,
"md5_digest": "962a0b0fe2061a30bd8d3f707bad40b6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 19931,
"upload_time": "2024-10-29T18:26:16",
"upload_time_iso_8601": "2024-10-29T18:26:16.279761Z",
"url": "https://files.pythonhosted.org/packages/a9/a0/d846dddc347598ca05128997a6937895157222a4cf5ae8813b85367594f0/pymazebuilder-1.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-29 18:26:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "w4ffl35",
"github_project": "PyMazeBuilder",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pymazebuilder"
}