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

@mitchallen/maze-generator

v0.1.28

Published

maze generator

Downloads

5

Readme

@mitchallen/maze-generator

maze generator


Installation

You must use npm 2.7.0 or higher because of the scoped package name.

$ npm init
$ npm install @mitchallen/maze-generator --save

Usage

    "use strict";

    var mazeFactory = require("@mitchallen/maze-generator");

    let xSize = 5;
    let ySize = 6;

    var maze = mazeFactory.Square({ x: xSize, y: ySize });

Browser Usage:

Example:

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title>Maze Generator Example</title>
        <meta name="description" content="Maze Generator Example">
        <script src="https://unpkg.com/@mitchallen/[email protected]/dist/maze-generator.min.js"></script>
        <script>
          var factory = window.MitchAllen.MazeGenerator;
          console.log(factory);
          var xSize = 10, ySize = 5;
          var sm = factory.Square( { x: xSize, y: ySize } );
          console.log(sm);
          sm.generate();
          sm.printBoard(); 
        </script>
      </head>
      <body>
        <h1>Maze Generator Example</h1>
        <p>See JavaScript developer console for output.</p>
      </body>
    </html>

Methods

For more methods see the parent class: @mitchallen/connection-grid.

gridFactory = factory.create(spec)

The create method is deprecated. Use Square instead.

mazeFactory = factory.Square(spec)

Factory method that returns a square maze generator object.

It takes one spec parameter that must be an object with x and y values specifying the size of the maze.

If x and y size values are less than one (0) they will be normalized to 0.

You can call Square multiple times to create multiple mazes.

var mazeFactory = require("@mitchallen/maze-generator");

var maze1 = mazeFactory.Square( { x: 5, y: 10 } );
var maze2 = mazeFactory.Square( { x: 7, y: 20 } );

maze1.generate();
maze2.generate();

mazeFactory = factory.Hexagon(spec)

Factory method that returns a hexagon maze generator object.

It takes one spec parameter that must be an object with x and y values specifying the size of the maze.

If x and y size values are less than one (0) they will be normalized to 0.

You can call Hexagon multiple times to create multiple mazes.

var mazeFactory = require("@mitchallen/maze-generator");

var maze1 = mazeFactory.Hexagon( { x: 5, y: 10 } );
var maze2 = mazeFactory.Hexagon( { x: 7, y: 20 } );

maze1.generate();
maze2.generate();

mazeFactory = factory.Triangle(spec)

Factory method that returns a triangle maze generator object.

It takes one spec parameter that must be an object with x and y values specifying the size of the maze.

If x and y size values are less than one (0) they will be normalized to 0.

You can call Triangle multiple times to create multiple mazes.

var mazeFactory = require("@mitchallen/maze-generator");

var maze1 = mazeFactory.Triangle( { x: 5, y: 10 } );
var maze2 = mazeFactory.Triangle( { x: 7, y: 20 } );

maze1.generate();
maze2.generate();

mazeFactory = factory.Circle(spec)

Factory method that returns a circle maze generator object.

It takes one spec parameter that must be an object with a rings value specifying the size of the maze.

You can call Circle multiple times to create multiple mazes.

var mazeFactory = require("@mitchallen/maze-generator");

var maze1 = mazeFactory.Circle( { rings: 5 } );
var maze2 = mazeFactory.Circle( { rings: 6 } );

maze1.generate();
maze2.generate();

maze.generate(spec = null);

Generates a maze by filling a connection grid with connection info.

maze.generate();

maze.generate(spec.mask = array)

Generates a maze with masked off cells.

let spec = {
    mask: [
        { c: 2, r: 3 },
        { c: 2, r: 4 }
    ]
};
mazeGenerator.generate(spec);

maze.generate(spec.start = array)

Generates a maze starting at a cell other than 0,0. Useful when you want to mask off 0,0.

let spec = {
    start: { c: 3, r: 3 },
    mask: [
        { c: 0, r: 0 },
        { c: 0, r: 1 },
        { c: 1, r: 0 },
        { c: 1, r: 1 }
    ]
};
mazeGenerator.generate(spec);

maze.printBoard()

Logs to the console the generated maze. You should examine the source for this method to determine other ways to display the generated maze.

maze.generate();
maze.printBoard();

Example:

SQUARE MAZE: 20, 20
 _______________________________________
|_  |    ___  |___   _   _|  ___   _  | |
| | | |___  | |   |_  |_____| |  _|  _| |
|  _| |_  | |___| | |  _____  |_  | |_  |
|_  |  ___|_  | | |  _|  _  |___| | |   |
| | |_|  _____| | |_|  _| | |  ___|___| |
| |_____|    ___|_  | |  _|___|     |  _|
|_____   _|_|  _  | | |    _|  _| |_|_  |
|  _____|  ___| |___| |_| |  _|  _|  ___|
| |   |  _|_   _______|  _| | |_  | |   |
|  _| | |   | |  ___    |  _| |  _| |_| |
|_  |___| |___|  _|  _| | |_  |_  |_  | |
| | |  ___  | | |   |___|_  |_  |_  |_  |
| | |___  | | | | | |  _____|  ___|_____|
|  _|   | | | | | | |_  | |  _  |  _   _|
|_  | |___| | | | |_|  _| | |  _| | |_  |
|  _|___  | |  _|_____|_  | |_____|  _| |
|_  |  ___| |_  |   |   |___   ___  |  _|
|  _|_|  ___| | | |___| |   |_|   | |_  |
| |  ___| |   | | |  _| | |_  | | |___| |
|___|_______|_____|_______|_____|_______|


HEXAGON MAZE: 10, 5
 _   _   _   _   _   
/ \_/ \_/ \_/ \_/ \_ 
\ / \_       _  \_  \
/  _  \_/ \_/  _/ \ /
\_/ \_  \ /  _/  _  \
/  _  \ / \ /  _/ \ /
\_/ \ /  _/ \ /  _/ \
/  _  \_/ \ / \ / \ /
\ /  _/  _/ \ /  _  \
/ \_/ \   \_  \ / \_/
\_   _  \_   _/  _  \
  \_/ \_/ \_/ \_/ \_/
  

TRIANGLE MAZE: 10, 5
  ____________________        
 /        \          /        
/__  __    \        /         
\       \   \   \   \         
 \ __    \   \   \   \        
 /    \   \      /   /        
/      \   \ __ /   /         
\   \      /    \   \         
 \   \ __ /      \   \        
 /            \      /        
/__  __  __  __\ __ /         
                  

CIRCLE MAZE: 5
_________________________________________________
| _ _ | _ |____ __| _ ___ | _____ __| ___ | ___ |
__| |_| |____ |__ __|__ |_|__ | | | __| |___| |__
|_______|   ____|___|___________|_______________|
_       |________________________________________
|_______________________________________________|

Testing

To test, go to the root folder and type (sans $):

$ npm test

Run all tests using nodemon:

$ npm run test-nodemon

Run suites using nodemon:

$ npm run test-square
$ npm run test-hexagon
$ npm run test-triangle
$ npm run test-circle

Repo(s)


Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.


Version History

Version 0.1.21

  • replaced modules/square.js with @mitchallen/maze-generator-square
  • updated browser example

Version 0.1.20

  • Fixed issue integrating new core and grunt with npm test

Version 0.1.19

  • replaced modules/base.js with @mitchallen/maze-generator-core
  • square now uses @mitchallen/connection-grid-square instead of @mitchallen/connection-grid

Version 0.1.18

  • removed old file from dist folder

Version 0.1.17

  • added browser client example
  • updated documentation

Version 0.1.16

  • updated package to use @mitchallen/connection-grid version 0.1.25
  • added browser client support

Version 0.1.15

  • updated package to use @mitchallen/connection-grid version 0.1.19

Version 0.1.14

  • updated package to use @mitchallen/connection-grid version 0.1.18

Version 0.1.13

  • updated package to use @mitchallen/connection-grid version 0.1.17
  • Moved connectsAny from Circle to @mitchallen/connection-grid

Version 0.1.12

  • Added Circle method
  • updated package to use @mitchallen/connection-grid version 0.1.16

Version 0.1.11

  • Added Triangle method

Version 0.1.10

  • Added Hexagon method

Version 0.1.9

  • Corrected version history

Version 0.1.8

  • updated package to use @mitchallen/connection-grid version 0.1.14
  • now use connection-grid.Square instead of .create (deprecated)
  • Restructured code base
  • Added Square method to replace create method (deprecated)

Version 0.1.7

  • updated package to use @mitchallen/connection-grid version 0.1.8

Version 0.1.6

  • updated package to use @mitchallen/connection-grid version 0.1.7
  • can now generate empty mazes
  • negative x and y sizes will be normalized to zero

Version 0.1.5

  • updated package to use @mitchallen/connection-grid version 0.1.5

Version 0.1.4

  • added start and mask options to generate method

Version 0.1.3

  • updated documentation

Version 0.1.2

  • now uses @mitchallen/connection-grid 0.1.3
  • generate method now fills grid with zeros before generating maze
  • max depth is now calculated automatically and no longer needs to be passed to generate method

Version 0.1.1

  • fixed error in documentation

Version 0.1.0

  • initial release