Members
columns
Properties:
Name | Type | Description |
---|---|---|
columns |
int | Maximum number of columns in the maze. |
generated :Object
2D Mapping of Cells
containing previously generated maze data. Keyed by [row][column].
Type:
- Object
ordered :Cell|Array
1D List of cells that keeps the order of the cells in which they were chosen during generation.
Type:
- Cell | Array
orderedSolution :Cell|Array
1D List of cells that keeps the ordered solution of the cells in which they were chosen during generation.
Type:
- Cell | Array
rows
Properties:
Name | Type | Description |
---|---|---|
rows |
int | Maximum number of rows in the maze. |
solution :Object
2D Mapping of Cells
containing the solved maze data. Keyed by [row][column].
Type:
- Object
Methods
generate(startRow, startColumn, endRow, endColumn) → {Object|Object|Array}
Main generator method for generating the maze.
Uses row and column instead of GridIndex
to have easier implementation for consumers.
Parameters:
Name | Type | Description |
---|---|---|
startRow |
int | Starting row index of the maze. |
startColumn |
int | Starting column index of the maze. |
endRow |
int | End row index of the maze. |
endColumn |
int | End column index of the maze. |
Returns:
The generated maze data and the solution data, respectively. Both keyed by [row][column]. The first cell is always the cell chosen by index at (row, column).
- Type
- Object | Object | Array
Example
// Algorithm (Recursive depth-first search with explicit stack):
1. Choose the initial cell, mark it as visited and push it to the stack.
2. While the stack is not empty.
1. Pop a cell from the stack and make it a current cell.
2. If the current cell has any neighbours which have not been visited.
1. Push the current cell to the stack.
2. Choose one of the unvisited neighbours.
3. Remove the wall between the current cell and the chosen cell.
4. Mark the chosen cell as visited and push it to the stack.
getUnvisitedCells(indices) → {Cell|Wall|Array}
Given a mapping of Walls
to Index
:
- First determine whether the index is valid.
- If the index is valid and the cell at that index is unvisited, push it to the unvisited neighbors array.
Parameters:
Name | Type | Description |
---|---|---|
indices |
Map.<Wall, GridIndex> |
Returns:
A tuple-like array of length 2 with the unvisited cell as the first parameter and the respective wall as the second parameter.
Example
Maze.getUnvisitedCells(Cell.getNeighborIndices()) // Gets all unvisited neighbors
reset()
Reset the maze.
validCellIndex(index) → {boolean}
Determines whether a given 2D Index
is out of range in the cells array.
Parameters:
Name | Type | Description |
---|---|---|
index |
GridIndex | The 2D index to check for. |
Returns:
If the given index is in range.
- Type
- boolean