Giter Club home page Giter Club logo

maze-nd's Introduction

A woodsy maze

maze-nd

A python package for generating n-dimensional mazes via randomized Prim's Algorithm

Initial implementation in 2D from: https://github.com/ArneStenkrona/MazeFun

Getting Started

Prerequisites

Poetry: https://python-poetry.org/docs/#installation

Installation

Clone the repository:

git clone https://github.com/dthuff/maze-nd

and install dependencies:

cd maze-nd/
poetry install

Or, install via pip:

pip install maze-nd

Usage

Generating maze structures

The MazeND class defines a maze data structure represented by a boolean array of arbitrary shape maze.grid.

A 2D maze of 40 rows and 40 columns can be generated with:

from maze_nd.maze_nd import MazeND
maze = MazeND([40, 40])

Note that maze dimensions must be odd to ensure a solid outer border. If even shape args are passed, they will be forced to be odd.

maze = MazeND([40, 40])

>>> maze.grid.shape
(39, 39)

A 3D maze of 40 rows, 40 columns, and 20 slices can be generated with:

maze = MazeND([40, 40, 20])

A 7D maze:

maze = MazeND([20, 20, 20, 10, 10, 20, 5])

Caution: generation time is proportional to np.prod(maze.grid.shape). This can quickly blow up for mazes with more than 4 dimensions.

Visualizing maze structures

The maze generation process can be visualized using examples/draw_maze.py:

poetry run python draw_maze.py 40 40

By default, this will save an image of the maze at examples/maze_image.png

Any number of shape dimensions can be passed. A 3D maze can be generated via:

poetry run python draw_maze.py 20 20 20

For mazes with dimension N > 2, 2D planes of the maze will be drawn separated by a vertical border. For an N-D maze, N-1 planes are shown.

The animation can be turned off using --skip-animation:

poetry run python draw_maze.py 40 40 --skip-animation

Fun color themes can be applied via --theme:

poetry run python draw_maze.py --theme beachy 40 40

Available themes are: default A boring, default maze

beachy, A beachy maze

woodsy, A woodsy maze

christmas, A festive, christmas maze

and kaboom. An explosive, kaboom maze

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.