nylira-maze
v0.4.0
Published
A library for generating mazes.
Downloads
30
Maintainers
Readme
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 torandom
."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