Algorithms

RNGMaps provides a lot of algorithms with many variants and parameters. This page is an overview of all of them including links to their tutorials and cheatsheets of their JS functions.

Prim’s Maze Algorithm

Classical Maze with cutOffDeadEnds and MergeDeadEnds disabled
Maze with cutOffDeadEnds and MergeDeadEnds enabled

You need at least one „snippets“ Map below your Space Map.

You can add optional parameters; the order will affect the output maze.

$dungeonGenerator.prims()
.cutOffDeadEnds(n)    // optional
.mergeDeadEnds(p)     // optional
.generate()

...
.finalize()

cutOffDeadEnds

cutOffDeadEnds(n)    // n = natural number > 0

This method looks for corridors with dead-ends and shortens them. The argument n stands for the number of repetitions, e.g. having a corridor with a length of 4 and using n=2, the corridor will have a length of 2 afterward.

mergeDeadEnds

mergeDeadEnds(p)    // p = decimal number 0.0 < p <= 1.0

This method looks for dead-ends and will create new tunnels back into the maze, lowering the number of dead ends and making the maze imperfect, allowing multiple solutions for the Player. The argument p stands for the probability that a tunnel is created; 1.0 = always, 0.0 = never.

Random Walk

$dungeonGenerator.randomWalk()
.start("bottom")
.exit("top")
.allowGoingBack(true / false)     // optional
.allowLargeAreas(true / false)    // optional
.allowRevisit(true / false)       // optional
.generate()

...
.finalize()

„start“ and „exit“ are required. Other parameters are optional.

allowGoingBack

Default: true. If disabled, the step-wise Random Walk is not allowed to walk back to its starting point, e.g. when start = „bottom“ the step-wise walker can walk only to the left, right, or top.

allowLargeAreas

Default: true. If disabled, the walker walks in a way that no large Areas are built.

allowRevisit

Default: false. If enabled, the walker can walk on cells that he already visited before.

Rooms and Corridors

Example using the Snippets
Example not using Snippets

This algorithm draws some Rooms at randomly chosen positions and then connects them using a spanning tree.

$dungeonGenerator.roomsAndCorridors()
.minRooms(5)
.maxRooms(5)            // optional
.minRoomWidth(1).maxRoomWidth(3)    // optional
.minRoomHeight(1).maxRoomHeight(2)  // optional
.generate()

...
.finalize()

All parameters are optional.

$noiseMapGenerator.roomsAndCorridors()
.minRooms(4).maxRooms(5)            // optional
.minRoomWidth(1).maxRoomWidth(3)    // optional
.minRoomHeight(1).maxRoomHeight(2)  // optional

.allowOverlapping()                 // optional, either use this line or skip
.thickness(3)                       // optional
.borderWidth(5)                     // optional
.generate()

...
.finalize()

Noise Map

$noiseMapGenerator.noiseMap()
.groundLevel(y)        // optional
.scale(n)              // optional
.array([])             // optional
.enforceSingleArea()   // optional, either use this line or skip it
.thickness(n)          // optional
.spanningTree(mode)    // optional
.generate()

...
.finalize()

All parameters are optional.

Ground Level

On the Space Map, the highest tile that is passable is used as the ground level for mathematical functions of the Generator. When you don’t use impassable ceiling tiles or any other reason, you can set a specific tile from the Space Map. The argument y stands for the y-coordinate of the Tile on the Space Map, starting from 0.

Scale

Sets the Noisemap’s scale. The higher the scale, the more stretched the Map will look like.

Array

By default, the Generator does calculations to roughly equalize the amount for each tile on the Space Map. If you don’t want that, you can pass an array that contains the thresholds for each level. The array must have the size of number of tiles on the Space Map - 1, as the first and last Tile is not included. Usually, you are safer by adding/removing tiles on/from the Space Map than using this function.

Enforce Single Area

This line is optional and has no arguments. When using this line, the Generator builds paths to connect all areas with each other.

Thickness

When using „enforce single area“, you can set the path’s thickness here. Choose from 1, 2, 3, 4, 5. Other values are not yet supported.

Spanning Tree

When using „enforce single area“, the Generator will apply a Spanning Tree to connect all areas. Choose from:

  • „MST“
    to use Kruskal’s Algorithm to build a Minimal Spanning Tree
  • „random“
    to randomly connect all the nodes

Tree Map

This algorithm selects some points at randomly chosen positions and then connects them using a spanning tree. Using a minimal spanning tree, which is the default setting, it will output a perfect maze.

  • Not using Snippets
  • Follow the Noise Map Tutorials
$noiseMapGenerator.treeMap()
.nodes(20)            // optional
.thickness(4)         // optional
.spanningTree(mode)   // optional
.generate()

...
.finalize()

All parameters are optional.

Nodes

Number of Nodes that are drawn and are connected in the next step.

Thickness

Choose from 1, 2, 3, 4, 5. Other values are not yet supported.

Spanning Tree

Choose from:

  • „MST“
    to use Kruskal’s Algorithm to build a Minimal Spanning Tree
  • „random“
    to randomly connect all the nodes