Module: maze/matrixMaze

maze/matrixMaze

Methods

<private, static> __createEmptyMatrix(y, x, def) → {Array.<Array.<Object>>}

Create a matrix filled with `def`.
Parameters:
Name Type Description
y Number Height.
x Number Width.
def Object Default element that the matrix should be filled with.
Source:
Returns:
Type
Array.<Array.<Object>>

<private, static> __createMaze(matrix, start)

This function will generate a maze through a variation of the DPS algorithm, see: https://en.wikipedia.org/wiki/Maze_generation_algorithm#Depth-first_search. This method modified the `matrix` in-place.
Parameters:
Name Type Description
matrix Array.<Array.<Object>> A maze matrix.
start Object Object with x and y attributes.
Source:

<private, static> __removeWall(matrix, y, x)

Attempt to remove the wall at the cell `matrix[y][x]`. Otherwise it does nothing.
Parameters:
Name Type Description
matrix Array.<Array.<Object>> A maze matrix.
y Number Y coordinate.
x Number X coordinate.
Source:
See:
  • module:maze.__createMaze

<static> generate(args) → {Array.<Array.<Object>>}

Generate a maze.
Parameters:
Name Type Argument Default Description
args Object <optional>
{width: 10, height: 10, start: {x: 0, y: 0}, print: false} Arguments object.
Source:
Returns:
A maze matrix of objects with an attribute `wall` that is either true or false.
Type
Array.<Array.<Object>>

<static> getCellNeighbors(matrix, y, x) → {Array.<Object>}

Get a list with the neighbors of a cell.
Parameters:
Name Type Description
matrix Array.<Array.<Object>> A maze matrix.
y Number Y coordinate.
x Number X coordinate.
Source:
Returns:
A list with 2, 3 or 4 objects with the attributes x or y.
Type
Array.<Object>

<static> printMatrix(matrix)

Print an ASCII version of the matrix to the console.
Parameters:
Name Type Description
matrix Array.<Array.<Object>> A maze matrix.
Source:
Example
// An example of such a console output:
  ------#---
  #-#-#-###-
  --###-----
  -#---##-#-
  -#-#---##-
  -#--##---#
  --#---##--
  #--#-#--#-
  --#---#-#-
  #---#---#-