Array
fillArray - function
Creates an array on a specified length and filled with a specified value.
Params
- length - number - The length of the array to be filled.
- value - number - What value each index of the array will be filled with.
Returns
- Array.<Object> - Newly created array of values.
initArray - function
Creates an array of the specified length and filled with 0s.
Params
- length - number - The length of the array to be filled.
Returns
- Array.<number> - Newly created array of 0s.
ArrayConstructor - typedef
A function used to construct the value of a given array index.
Params
- index - number - The index of the constructed value.
Returns
constructArray - constant
Creates an array of the specified length where each index is filled with the result of running the constructor function.
Params
- constructor - ArrayConstructor - The function used to construct each value of the array.
- length - number - The length of the array to be filled. Must be a positive number not including zero.
Returns
- Array.<Object> - Newly created array of the constructed values.
containsLocation - function
Does the provided array contain the location provided.
Params
- array - Array.<Object> - The array to be searched.
- location - Location - The location to ge searched for.
Returns
- boolean - True if the location is present in the array.
Assert
AssertionError - class
A special error that indicates an assertion has failed.
Params
- message - string - The message containing more information about a given AssertionError.
Returns
assert - function
If the assertion is truthy then nothing will happen. Otherwise, this function throws an {@link AssertionError} with the provided message if the assertion is falsy.
Params
- assertion - boolean -
- message - string -
Returns
Matrix
MatrixConstructor - typedef
A function used to construct the value of a given matrix location.
Params
- location - Location - The location of the constructed value.
Returns
- Object - The value to be created at this location
constructMatrix - constant
Creates a matrix of the specified dimensions where each location is filled with the result of running the constructor function.
Params
- constructor - MatrixConstructor - The function used to construct each value of the array.
- dimensions - Dimensions - The length of the array to be filled.
Returns
- Array.<Array.<Object>> - Newly created matrix of the constructed values.
MatrixCharacterMap - typedef
A function used to construct the value of a given matrix location based on an input character.
Params
- character - string - Character for the current location
- location - Location - The location of the constructed value.
- - Array.<Array.<Object>> - the entire template matrix
Returns
- Object - The value to be created at this location
constructMatrixFromTemplate - constant
Constructs a matrix from a template string. The template string should represent the matrix. Each line of the template string (separated by newlines) represents a row in the matrix. On each line (or row), a column is indicated by a space between characters.
Params
- mapCharacter - MatrixCharacterMap - function to construct each location based on the character map
- template - string - a two dimensional string representing the matrix to be created
Returns
- Array.<Array.<Object>> - Newly created matrix of the constructed values.
Dimensions - typedef
The width and height of a matrix
Params
- width - number - How many columns are in a matrix
- height - number - How many rows are in a matrix
Returns
maxWidth - function
Find the length of the longest row in the provided matrix.
Params
- matrix - Object -
Returns
minWidth - function
Find the length of the shortest row in the provided matrix.
Params
- matrix - Object -
Returns
Direction - typedef
An object describing a direction. It should contain no more than 2 truthy properties.
Params
Returns
getCrossDirections - function
Creates an array of directions representing the cross-shaped neighbors of a cell. The following diagram describes the neighboring directions represented by X's. | |X| | ------- |X| |X| ------- | |X| |
Params
Returns
- Array.<Direction> - Directions representing up, down, left, and right.
getDiagonalDirections - function
Creates an array of directions representing the X-shaped diagonal neighbors of a cell. The following diagram describes the neighboring directions represented by X's. |X| |X| ------- | | | | ------- |X| |X|
Params
Returns
- Array.<Direction> - Directions representing upper left, upper right, lower left, and lower right.
getAllDirections - function
Creates an array of directions representing the all diagonal and cross-shaped neighbors of a cell. The following diagram describes the neighboring directions represented by X's. |X|X|X| ------- |X| |X| ------- |X|X|X|
Params
Returns
- Array.<Direction> - Directions representing upper left, up, upper right, right, lower right, down, lower left, and left.
getConnectedDirections - constant
Creates an array of the directions connected to this object in a cross-shaped pattern. A connection is determined by the connections object passed into this function. If a connection direction is truthy then it is counted as connected.
Params
- connections - Connections - An object that describes which neighbors this cell is connected to.
Returns
- Array.<Directions> - All directions connected to the cell.
fillMatrix - constant
Creates a matrix of the specified dimensions filled with the provided value at every location.
Params
- dimensions - Dimensions - width and height of this matrix
- value - Object - any value to fill the matrix with
Returns
- Array.<Array.<Object>> - the newly created array
CellComparator - typedef
Params
- cell - Object - the cell's value at the current location
- location - Location - the location being checked
Returns
- boolean - true if this cell/location satisfies the condition
findValue - constant
Search a provided matrix for the first cell that satisfies the provided comparator's condition. Returns that cell's value.
Params
- comparator - CellComparator - callback to check if any given cell or location should be found.
- matrix - Array.<Array.<Object>> - matrix to be searched
Returns
- Object - the found value or undefined if nothing matching the comparator was found.
findLocation - constant
Search a provided matrix for the first cell that satisfies the provided comparator's condition. Return's that cell's location.
Params
- comparator - CellComparator - callback to check if any given cell or location should be found.
- matrix - Array.<Array.<Object>> - matrix to be searched
Returns
- Location - the found value or undefined if nothing matching the comparator was found.
findLocations - constant
Search a provided matrix for the all cell that satisfy the provided comparator's condition. Returns all matching locations.
Params
- comparator - CellComparator - callback to check if any given cell or location should be found.
- matrix - Array.<Array.<Object>> - matrix to be searched
Returns
- Array.<Location> - array containing all matching locations in the provided matrix.
getNeighbors - constant
Get all the neighboring locations of the provided location from the provided matrix that are in bounds.
Params
- - function - getDirections - this function should return a {Connections} object defining how matrix cells are connected.
- - Array.<Array.<Object>> - matrix - the matrix to be checked
- - Location - location - location in the matrix whose neighbors should be returned.
Returns
- Array.<Location> - array of all valid neighboring locations
getRow - constant
Get a row of the provided matrix
Params
- matrix - Array.<Array.<Object>> -
- rowIndex - number - row index to be gotten
Returns
- Array.<Object> - a single row of the matrix
getCol - constant
Get a column of the provided matrix
Params
- matrix - Array.<Array.<Object>> -
- colIndex - number - column index to be gotten
Returns
- Array.<Object> - a single column of the matrix
getDimensions - function
Get the dimensions objet describing the provided matrix.
Params
- matrix - Array.<Array.<Object>> -
Returns
- Dimensions - width and height of the provided matrix
initMatrix - function
Creates a matrix of the specified dimensions with all cells set to a value of 0.
Params
- dimensions - Dimensions -
Returns
- Array.<Array.<number>> - the initialized matrix
isLocationInBounds - constant
Checks if the given matrix includes the given location
Params
- matrix - Array.<Array.<Object>> -
- location - Location -
Returns
- Boolean - true if the given location exists within the matrix.
getLocation - constant
Gets the cell's value at the specified location from the matrix.
Params
- matrix - Array.<Array.<Object>> -
- location - Location -
Returns
- Object - the retrieved object
compareLocations - constant
Check if two locations are equal. Determined by a comparison of row and col values of each location.
Params
- a - Location -
- b - Location -
Returns
- boolean - true if both locations are equal
manhattanDistance - constant
Calculates the Manhattan Distance between two provided locations
Params
- a - Location -
- b - Location -
Returns
- number - the integer value of the calculated distance
CellMapper - typedef
Takes in the value, location, and matrix being mapped and returns a new object.
Params
- value - Object -
- location - Location -
- matrix - Array.<Array.<Object>> -
Returns
- Object -
mapMatrix - constant
Maps over the provided matrix with the provided callback and returns a new matrix.
Params
- callback - CellMapper -
- matrix - Array.<Array.<Object>> -
Returns
- Array.<Array.<Object>> - the newly mapped matrix
MATRIX_ROTATION_DIRECTIONS - constant
Directions to rotate a matrix: CLOCKWISE, COUNTER_CLOCKWISE
Params
Returns
rotateMatrix - constant
Rotate a matrix in the provided direction
Params
- options - Object - control how the matrix is rotated
- options.direction - MATRIX_ROTATION_DIRECTIONS - direction to rotate the matrix
- - Array.<Array.<Object>> - matrix to be rotated
Returns
- Array.<Array.<Object>> - newly rotated matrix
MATRIX_TRANSLATE_DIRECTIONS - constant
Directions to translate a matrix: UP, DOWN, LEFT, RIGHT
Params
Returns
translateMatrix - constant
Translate a matrix in the provided direction
Params
- options - Object - control how the matrix is translated
- options.shouldWrap - boolean - should the edge of the matrix at the end of the translation be placed on the opposite side of the matrix, or should it be removed entirely
- options.constructFn - MatrixConstructor - if wrapping is disabled, this constructor function is used to create the row at the newly exposed edge of the matrix.
- options.direction - MATRIX_TRANSLATE_DIRECTIONS - direction to translate the matrix
- - Array.<Array.<Object>> - matrix to be translated
Returns
- Array.<Array.<Object>> - newly translated matrix
transposeMatrix - constant
Transpose (flip the columns and rows) the provided matrix.
Params
- matrix - Array.<Array.<Object>> -
Returns
- Array.<Array.<Object>> - the transposed matrix
updateMatrix - constant
Set the cell of the matrix at the location to a value.
Params
- location - Location -
- value - Object -
- matrix - Array.<Array.<Object>> -
Returns
- Array.<Array.<Object>> - matrix with the location updated
Pathfinding
createDistanceMap - function
Creates a distance map with the given specifications. A distance map is a matrix. Each call has an integer value. The value is the manhattan distance that cell is from any goal location. AKA a "Djikstra Map" - http://www.roguebasin.com/index.php/Dijkstra_Maps_Visualized
Params
- getNeighbors - getNeighbors - function defining how to retrieve a cell's neighbors
- isLocationValid - CellComparator - is a given cell able to be traversed. Could be used to create walls or other impassable terrain.
- matrix - Array.<Array.<Object>> -
- goals - Array.<Location> - array of target cells
Returns
- Array.<Array.<number>> - - matrix containing the calculated distance map
floodFill - function
Returns an array of all locations connected to the starting open locations. Connections defined by getNeighbors and isLocationValid functions.
Params
- getNeighbors - getNeighbors -
- isLocationValid - CellComparator -
- matrix - Array.<Array.<Object>> -
- open - Array.<Location> - locations to start floodfilling from
- closed - Array.<Location> - usually empty, locations here will not be checked by the floodfill algorithm.
- found - Array.<Location> - usually empty, locations here will be returned by the floodfill function. If this array contains locations that the algorithm will find on its own, these values will be duplicated. This function does not guarantee uniqueness in that case.
Returns
- Array.<Location> - flooded locations
getPath - constant
Find the path from a start location to a target location using the specified matrix and parameters.
Params
- getNeighbors - getNeighbors -
- isLocationValid - CellComparator -
- matrix - Array.<Array.<Objet>> -
- start - Location -
- target - Location -
Returns
- Array.<Location> - array of locations leading from the start location to the target location, including the start and target locations on either end of the array.