nylira-maze
A library for generating mazes.
Last updated 5 years ago by nylira .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nylira-maze 
SYNC missed versions from official npm registry.

nylira-maze

A JavaScript library for generating maze data.

_________________________________________________________________________________
|█|█|█|█|█|█|█|█|█|█|__ |   |█|█|█|█|█|█|█|█|   |  __ |   |█|█|█|  ______ |█|█|█|
|█|█|█|█|█|█|█|█|  __ |___|________ |█|█|█|█| |___|█| | |_________|█|█|█| |█|█|█|
|█|█|█|█|█|█|█|█|___|______ |█|█|█|____ |█|█| |█|█|█|___|█|█|█|  __ |█|█| |█|   |
|█|█|█|█|█|█|█|█|█|█|█|█|  _|  ____ |  _|█|█| |█|█|█|   |  _____|  _|  ___|  _| |
|   |█|█|█|█|█|█|█|█|█|█|_____|█|   |__ |█|█| |█|█|█| |___|█|  ___|█|____ | |  _|
| | |█|█|█|█|█|█|█|█|█|█|█|█|█|█| | |█|_______|█|█|  _|█|█|  _|█|█|█|   | | | |█|
| |______ |   |█|█|█|█|█|█|█|█|█| |________ |█|█|█|______ |___________| |___| |█|
| |█|   |___| |█|█|█|█|█|█|█|█|█| |█|█|█|█| |  ________ |__ |█|█|█|█|█|__ |█|__ |
| |█| | |█|█|________________ |█| |█|█|█|█|___|█|█|█|█|_____|█|█|█|█|█|█| |   | |
|_____|______ |█|█|█|█|  _____|█| |█|█|█|█|█|█|█|  ________ |█|█|█|█|█|█| | | | |
|  __ |█|█|█| |█|█|█|█| |  __ |█| |█|█|█|█|█|█|█|____ |█|█|______ |█|█|█|___| | |
|__ | |  _____|█|█|   | | |█|_____|   |█|█|█|█|█|█|█| |█|█|  _____|█|█|█|█|█| | |
|  _|___|  _________| |___|█|  __ | |__________ |   | |█|█| |█|   |█|_________| |
|______ | |█|█|█|█|█| |   |█| |  _| |█|█|█|█|█| | |___|█|█|_____| |█|█|█|█|█|  _|
|  _____| |█|█|█|█|█| | | |█| |_____|█|█|█|█|█| | |█|█|█|█|  _____|█|█|█|█|█|__ |
|  _______|█|█|█|█|█| | |__ |__ |█|█|█|█|█|█|█| | |█|█|█|█| |█|█|█|█|█|█|█|█|█| |
|__ |█|█|█|█|█|█|█|█|___|█| |█|______ |█|█|█|█| | |█|█|█|█|__________ |█|█|█|█| |
|  _|█|█|█|█|█|█|█|█|█|█|█| |█|█|  ___|   |█|█|___|█| |█|█|█|█|█|  ___|█|█|   | |
| |   |  ___|█|█|█|█|█|█|█| |█|█|____ | | |█|█|█|   | |█|█|█|█|█|___________| | |
|___|___|█|█|█|█|█|█|█|█|█|_____________|_________|___|█|█|█|█|█|█|█|█|█|█|█|___|

Installation

npm i nylira-maze --save

Usage

Basic usage:

var maze = require('nylira-maze')

// returns a 2d array of values for a 10x10 maze
maze()

// returns a 2d array of values for a 20x20 maze
maze(20)

// returns a 2d array of values for a 15x23 maze
maze(15, 23)

Parameters

maze(31, 23, 'growing-tree:newest', 0.65, undefined, true)
  • Parameter 1: Width.
  • Parameter 2: Height.
  • Parameter 3: The maze generation algorithm. Options:
    • "growing-tree": The Growing Tree algorithm. Defaults to random.
    • "growing-tree:random": Lots of dead ends, similar to Prim's Algorithm
    • "growing-tree:newest": Long windy passages, similar to "backtracker"
    • "growing-tree:middle": Lots of long straight passages.
    • "growing-tree:oldest": Only long straight passages.
    • "backtracker": The Recursive Backtracker algorithm. Tends towards long and twisted passages.
  • Parameter 4: Sparseness. A sparse maze will have some of its nodes removed. If you type in a value less than 1, e.g. 0.25, the maze will be 25% sparse. If you enter an integer value more than 1, e.g. 5, the maze will remove 5 nodes from each of its dead ends.
  • Parameter 5: The integer seed for the maze. Putting a value here will guaranteee you can recreate the maze over and over again.
  • Parameter 6: You can preview the grid by passing in true as the fifth parameter.

That function call above will generate the following:

_______________________________________________________________
|█|█|█|____________________ |█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|
|█|█|█|█|█|█|█|█|█|█|█|█|█|__ |  _|█|█|█|█|█| |█|█|█|█|█|█|█|█|
|█|█|█|█|█|█|█|█|█|█|█|█|█|█|__ |█|█|█|█|█|  _|█|█|█|█|█|█|█|█|
|█|█|█|____ |█|█|█|█|█|█|█|█|█| |█|█|█|█|  _|█|█|█|█|  ___|█|█|
|█|█|█|█|█|________ |█|█|__ |█| |█|█|█|█| |█|█|█|█|  _|█|█|█|█|
|█|█|█|█|█|█|█|█|█| |█|█|█|__ |____ |  ________  ___|█|█|█|█|█|
|█|█|█|█|█| |█|█|  ______ |  ______  _|█|█|█|█|_____|█|█|█|█|█|
|█|█|█|█|█|__ |   |█|█|█|___|█|█|  ____   |█|█|█|█|█|█|█|█|█|█|
|█|____  ____  _| |█|█|█|█|█|  __ |█|█| |____ |█|█|█|█|█|█|█|█|
|█|█|  _|█|█| |█|_|█|█|█|█|  _|█|   |█| |█|█|  _________|█|█|█|
|█|___|█|█|█| |█|█|█|  __  _|█|█| | |█|__ |█| |█|█|█|█|█|█|█|█|
|█|█|█|█|█|█|_|█|█|█| |█|_|█|█|  _| |█|█| |█|__ |█|█|█|█|█|█|█|
|█|█|█|█|█|█|█|█|█|  _|█|█|█|█| |█| |█|█|____ |__  __________ |
|█|█|█|█|█|█|█|█|█| |█|█|█|█|█| |█| |█|█|█|  _|█|__   |█|█|   |
|█|█|█|█|█|█| |█|  _|█|█|█|  ___|█|   |█|█| |█|█|█| | |█|█| | |
|█|█|█|__  ______ |█|█|█|█| |█|█|█| | |█|█| |█|█|█| | |█|█| | |
|█|█|█|█| |█|█|█| |█|█|█|█| |█|█|  _| |█|█| |█|█|█| | |█|█| |_|
|█|  _____|█|█|█| |█|█|_____|█|  _|█| |█|█| |█|█|  _| |█|█| |█|
|█|_|█|█|  __ |   |█|█|█|█|█|█| |█|█|_____|____ | |█|_|█|█|_|█|
|█|█|█|___|█|___|_|█|█|█|█|█|    __ |█|█|█|█|█| |_|█|█|█|█|█|█|
|█|█|█|█|█|█|█|█|█|█|█|█|█|█|_|_|█|_|█|█|█|█|█|_|█|█|█|█|█|█|█|
|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|
|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|█|

The maze at the top of the README was generated with this function:

maze(40, 20, 'growingtree:newest', 0.47, undefined, true)

Test

Check out a demo.

npm test

License

MIT

Current Tags

  • 0.4.0                                ...           latest (5 years ago)

19 Versions

  • 0.4.0                                ...           5 years ago
  • 0.3.4                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.8                                ...           5 years ago
  • 0.2.7                                ...           5 years ago
  • 0.2.6                                ...           5 years ago
  • 0.2.5                                ...           5 years ago
  • 0.2.4                                ...           5 years ago
  • 0.2.3                                ...           5 years ago
  • 0.2.2                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.6                                ...           5 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           6 years ago
  • 0.1.2                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |