Skip to main content

RPG

Project description

PyMazeBuilder

Generate perfect mazes with Python using a growing tree algorithm.


Installation

pip install pymazebuilder

█████████████████████
█░░░░░░░░░█░░░░░░░░██
██░░░░░░░░█░█████░███
█░░░░░░░░░░░█░░██░░░█
█░░░░░░░░░█░█░█████░█
█░░░░░░░░░█░░░█░░░█░█
█░░░░░░░░░█████░█░█░█
███░░░░██░░░░░░░█░░░█
███░███████████████░█
█░░░█░░░░░█░░░░░░░░░█
█░███░███░█░█████████
█░█░░░███░█░█░░░░░░░█
█░█░███░█░█░█░█████░█
█░█░██░░█░█░░░█░░██░█
█░█░██░░█░█████░███░█
█░░░█░░░░░░░█░░░░░█░█
█░███░░░░░░░█░███░█░█
█░██░░█░░░░░█░█░░░█░█
█░███░█░█████░█░███░█
█░░░░░█░░░░░░░█░░░░░█
█████████████████████

Generated data structure

    {
        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

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:

[
    {
        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)

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.

Floor 0
█████████████████████
█░██░░░░░██░░░░░░░░░█
█░███░█░███░░░░░█░█░█
█░░░█░█░░░░░█░░░█░█░█
███▼█░█░█████████░█░█
█░░░█░█░░░█░░░░░█░███
█░███░███░█░███░█░███
█░█░░░░██░█░█░░░█░░░█
█░█░█████░█░█░█░█░░░█
█░█░░░░░█░███░█░█░░░█
█░█░░██░█░███░█░█░░░█
█░█░░░█░█░░░░░█░░░█░█
█░███░█░███░░░░░█░█░█
█░██░░█░░░░░░░█░░░█░█
█░███████████░█░███░█
█░░░█░░░█░░░█░░░█░░░█
███░█░█░█░█░█████░█░█
███░░░█░█░█░░░░░░░█░█
█░█████░█░███░░░░░█░█
█░░░░░░░░░██░░░░░░░░█
█████████████████████
Floor 1
█████████████████████
█░░░░░░░░░█░░░░░░░░██
██░░░░░░░░█░█████░███
█░░░░░░░░░░░█░░██░░░█
█░░▲░░░░░░█░█░█████░█
█░░░░░░░░░█░░░█░░░█░█
█░░░░░░░░░█████░█░█░█
███░░░░██░░░░░░░█░░░█
███░███████████████░█
█░░░█░░░░░█░░░░░░░░░█
█░███░███░█░█████████
█░█░░░███░█░█░░░░░░░█
█░█░███░█░█░█░█████░█
█░█░██░░█░█░░░█░░██░█
█░█░██░░█░█████░███░█
█░░░█░░░░░░░█░░░░░█░█
█░███░░░░░░░█░███░█░█
█░██░░█░░░░░█░█░░░█░█
█░███░█░█████░█░███░█
█░░░░░█░░░░░░░█░░░░░█
█████████████████████

▲ = stairs going up
▼ = stairs going down
█ = wall
░ = floor

Custom generator classes

Custom generators should match the following pattern.

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


Contributors

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

pymazebuilder-1.2.2.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

pymazebuilder-1.2.2-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file pymazebuilder-1.2.2.tar.gz.

File metadata

  • Download URL: pymazebuilder-1.2.2.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pymazebuilder-1.2.2.tar.gz
Algorithm Hash digest
SHA256 730fa8256bfd04f96fd4fabe2e6315a1ed4df01bcc920187c286b549e3d71492
MD5 713f3db645187e7a36b623758eaf1572
BLAKE2b-256 9d0c88af71db4f429bfccf6dcfc0aab15cc62a2425d28ec84157dc7a2e9e6eaa

See more details on using hashes here.

File details

Details for the file pymazebuilder-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pymazebuilder-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1de5d093b1d57f68bbbc2f1ccf62e790bd64eef8f062501792a4d6ca8586d323
MD5 26248f38afacc860d0371475a73f9e2a
BLAKE2b-256 f54e74db6f462e35b5220a00bb02d0cb8d77cf8e6e1d229d7b7cda8c40704dd5

See more details on using hashes here.

Supported by

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