Module: maze/wallExtractor

maze/wallExtractor

This module extracts the walls from a matrix maze with each wall as an object.
Source:

Example

// Example usage
wallExtractor.extract(maze);
// Returns:
[{height: 1, width: 1, x: 0, y: 6}, {height: 5, width: 1, x: 1, y: 0}, ...]

// Where the maze looks like:
matrixMaze.printMatrix(maze)
-W----##--
-W-##---#-
-W-##-#---
-W---#-#-#
-W##-#-#--
-----#-##-
W-##-#----
-#--#--###
---##-##--
-#-------#
// The two walls from the extract function shown above have been highlighted
// with W characters

Methods

<static> __addSentinelCells(maze)

Add sentinel nodes to the end of the columns and rows.

All of these added nodes are floor nodes and they are put in to make the loops in this module easier to work with. With these sentinel nodes there is no need to handle the last cell in a row or column in a special way.

Parameters:
Name Type Description
maze Array.<Array.<Object>> A maze matrix.
Properties
Name Type Description
wall boolean
Source:

<static> __getHorizontalWallStrip(maze, y, x) → {Array.<Object>}

Get the horizontal wall starting at (y, x) and as long as possible with increasing x values.
Parameters:
Name Type Description
maze Array.<Array.<Object>> A maze matrix.
Properties
Name Type Description
wall boolean
y number
x number
Source:
Returns:
An array of objects with x and y coordinates.
Type
Array.<Object>

<static> __getVerticalWallStrip(maze, y, x) → {Array.<Object>}

Get the vertical wall starting at (y, x) and as long as possible with increasing y values.
Parameters:
Name Type Description
maze Array.<Array.<Object>> A maze matrix.
Properties
Name Type Description
wall boolean
y number
x number
Source:
Returns:
An array of objects with x and y coordinates.
Type
Array.<Object>

<static> __removeWall(maze, wall)

Parameters:
Name Type Description
maze Array.<Array.<Object>> A maze matrix.
Properties
Name Type Description
wall boolean
wall Array.<Object> An array of wall cells to change to floors.
Properties
Name Type Description
x number
y number
Source:

<static> extract(maze) → {Array.<Object>}

Extract the walls from a matrix maze.
Parameters:
Name Type Description
maze Array.<Array.<Object>> A matrix maze.
Source:
Returns:
A list of wall objects with attributes `x`, `y`, `width` and `height`.
Type
Array.<Object>