# 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": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "maze,builder,generator,rpg,game,development",
"author": "w4ffl35",
"author_email": "contact@capsizegames.com",
"download_url": "https://files.pythonhosted.org/packages/60/eb/41388c9c20bc805c8a189cbb2b159e88ec0f4a03dfa259fc3b40ddd0f470/pymazebuilder-1.2.0.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.2.0",
"project_urls": {
"Homepage": "https://github.com/w4ffl35/PyMazeBuilder"
},
"split_keywords": [
"maze",
"builder",
"generator",
"rpg",
"game",
"development"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1425fbb040058c2ad01f1cd63ba1154604dfa7b087406eca06ac5abd7b793585",
"md5": "1339a3be167bfab1e5e454ee1514bd57",
"sha256": "53463c36de5f91820db6cb375496447a3ce81e85e446374ecaf6e838e3b1662c"
},
"downloads": -1,
"filename": "pymazebuilder-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1339a3be167bfab1e5e454ee1514bd57",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 15076,
"upload_time": "2024-03-15T04:31:07",
"upload_time_iso_8601": "2024-03-15T04:31:07.323017Z",
"url": "https://files.pythonhosted.org/packages/14/25/fbb040058c2ad01f1cd63ba1154604dfa7b087406eca06ac5abd7b793585/pymazebuilder-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "60eb41388c9c20bc805c8a189cbb2b159e88ec0f4a03dfa259fc3b40ddd0f470",
"md5": "0d642bcd10f2db048ba0a04b7fc1f423",
"sha256": "ae2bc47264ed32da0c2adcc75b8249a71533c7bbed055bac587a935e1418185d"
},
"downloads": -1,
"filename": "pymazebuilder-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "0d642bcd10f2db048ba0a04b7fc1f423",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15045,
"upload_time": "2024-03-15T04:31:08",
"upload_time_iso_8601": "2024-03-15T04:31:08.383541Z",
"url": "https://files.pythonhosted.org/packages/60/eb/41388c9c20bc805c8a189cbb2b159e88ec0f4a03dfa259fc3b40ddd0f470/pymazebuilder-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-15 04:31:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "w4ffl35",
"github_project": "PyMazeBuilder",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pymazebuilder"
}