npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sbj42/maze-generator

v2.0.6

Published

An infrastructure for generating mazes

Downloads

35

Readme

maze-generator

A javascript maze generator

This library can be used to generate mazes using various algorithms.

Installation:

npm install --save-dev @sbj42/maze-generator

Don't forget to also choose a maze algorithm and install the plugin for that:

npm install --save-dev @sbj42/maze-generator-backtrack

Usage:

var mazeGen = require('@sbj42/maze-generator');

// generate a 20x20 maze
var maze = mazeGen.generate(20, 20, {
    generator: '@sbj42/maze-generator-backtrack'
});

// get the north-east corner cell of the maze
var cell = maze.cell(0, 0);

API

mazeGen.generate(width, height, options)

The generate() function takes a width and a height, and returns a new maze object. The (optional) options argument can be used for additional settings:

  • options.random: (optional) A random number generator, as a function that returns a number between 0 (inclusive) and 1 (exclusive). The default random number generator is Math.random.
  • options.generator: (optional) A maze-generator plugin, as a package name The default plugin is @sbj42/maze-generator-backtrack (though you'll need to make sure that's installed to use it).
  • options.mask: (optional) A GridMask, indicating the cells the maze can use. Any cell marked false in the mask will not be used in the maze. Some maze algorithms may not support this option. The mask should be a single connected region, if it isn't then the resulting maze may only fill one region. For information about the GridMask API, see the @sbj42/maze-generator-core package.

maze.width() / maze.height()

Return the width and height of the maze.

maze.cell(x, y)

Returns a cell object for the cell at the given position.

cell.north() / cell.east() / cell.south() / cell.west()

These boolean properties indicate whether the cell has a passage in each of the cardinal directions. If the property is true, then there is a passage in that direction. false indicates a wall.

mazeGen.GridMask(width, height, options)

For information about the GridMask API, see the @sbj42/maze-generator-core package.

Generator algorithms

Multiple generator algorithms can be used, each with different characteristics. Here are some examples, with some information about each, as measured generating a bunch of 100x100 mazes:

| Algorithm | Relative Speed | Dead Ends | Branches | Avg. Dead End Length | Avg. Straight Run Length | | ------------------------------- | --------------:| ---------:| --------:| --------------------:| ------------------------:| | @sbj42/maze-generator-backtrack | 100% | 10.0% | 9.9% | 2.1 | 1.7 | | @sbj42/maze-generator-prim | 58% | 35.6% | 29.4% | 1.6 | 2.1 | | @sbj42/maze-generator-kruskal | 50% | 30.6% | 26.5% | 1.7 | 1.9 |