Skip to content

Back-tracking random search maze generator implemented in ES6

License

Notifications You must be signed in to change notification settings

allbinmani/maze-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-maze-generator

Generates random mazes using back-tracking search.

Purpose

Generate unique, abstract, mazes of any rectangular size suitable for games.

Features

  • Has a clean ES6 imlementation and simple, abstract API
  • Small package (5KB)
  • Mazes can be compacted as integers, for storage or learning purposes
  • Can be used as a plain script or as a Node/AMD module

Usage

To generate a maze, create an instance of MazeGenerator and call .generate() (as many times as you wish).

The constructor for MazeGenerator needs the width and height of the maze to generate, and has an optional start position argument, which defaults to 0,0 (top left).

import MazeGenerator from 'node-maze-generator';

const WIDTH = 10;
const HEIGHT = 10;
let mg = new MazeGenerator(WIDTH, HEIGHT, [WIDTH-1, 0]);
let maze = mg.generate();

The generate method returns an array of size widthxheight MazeCell class instances.

Random seeding

This package relies on the Math.random random number generator, which can not be specifically seeded. If you need repeatable behaviour, try out the seedrandom package, which worked well during development.

About

Back-tracking random search maze generator implemented in ES6

Resources

License

Stars

Watchers

Forks

Packages

No packages published