1.1.3 • Published 5 years ago

generate-maze-ts v1.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

generate-maze

Maze generator using a JavaScript implementation of Eller's Algorithm, as described here: http://www.neocomputer.org/projects/eller.html

This algorithm creates 'perfect' mazes, which guarantees a single path between any two cells, such as:

+---+---+---+---+---+---+---+
|           |           |   |
+---+   +---+   +   +   +   +
|   |   |       |   |       |
+   +   +   +   +   +   +   +
|       |   |   |   |   |   |
+   +---+   +   +---+---+   +
|   |   |   |   |   |   |   |
+   +   +   +   +   +   +   +
|   |       |   |   |       |
+   +---+   +---+   +---+---+
|   |   |   |       |       |
+   +   +   +   +---+   +   +
|                       |   |
+---+---+---+---+---+---+---+

Note: This library does not create ASCII-art or other text visualizations.
That part is up to you.

This library generates a two-dimensional array of maze cells, each with the following properties:

    {
      x: 4,          // Horizontal position, integer
      y: 7,          // Vertical position, integer
      top: false,    // Top/Up has a wall/blocked if true, boolean 
      left: false,   // Left has a wall/blocked if true, boolean
      bottom: true,  // Bottom/Down has a wall/blocked if true, boolean
      right: true,   // Right has a wall/blocked if true, boolean
      set: 5         // Set # used to generate maze, can be ignored
    }

Installation

npm install generate-maze

Usage

Example assumes you are using a module system such as node, Webpack or Browserify.

var generator = require('generate-maze');

// Width and height == 4
var maze = generator(4);

// Width == 8, height == 4
var maze = generator(8, 4);

// Width == 8, height == 4, maze edges are open
var maze = generator(8, 4, false);

_Note: the maze is an array of rows, so to access individual cells by their x/y positions, you need to specify the row first. For example:

maze[y][x]
1.1.3

5 years ago

1.1.1

5 years ago

1.0.12

5 years ago

1.0.10

5 years ago

1.0.8

5 years ago

1.0.6

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago