Class: Grid

Grid(length, width)

new Grid(length, width)

Grid class used for maintaining states on a grid and traversing it
Parameters:
Name Type Description
length Number the number of rows in the grid
width Number the number of columns in the grid
Properties:
Name Type Description
grid Array.<Array.<Node>>
gridLength Number width of grid
gridWidth Number width of grid
Source:

Methods

astar(start, end) → {Array}

Gets the shortest path between two nodes in the grid
Parameters:
Name Type Description
start Node the starting node
end Node the ending node
Source:
Returns:
the shortest path between the two nodes as an array of [x, y] coordinates
Type
Array

astarGridClean()

Cleans the grid to prepare for running A*
Source:

changeNodeValue(x, y, value)

Changes the value of a node in the grid
Parameters:
Name Type Description
x Number the x position of the node whose value will be changed
y Number the y position of the node whose value will be changed
value object the new value
Source:

changeNodeWalkable(x, y, walkable)

Changes the if a node in the grid is walkable
Parameters:
Name Type Description
x Number the x position of the node which will be changed
y Number the y position of the node which will be changed
walkable Boolean whether or not the node should be walkable
Source:

constructor(length, width)

Creates the grid
Parameters:
Name Type Description
length the number of rows in the grid
width the number of columns in the grid
Source:

getNeighbors(node) → {Array.<Node>}

Gets the neighbors of a node
Parameters:
Name Type Description
node Node the node to check
Source:
Returns:
the node's neighbors
Type
Array.<Node>

getNode(x, y) → {Node}

Gets the node at a certain position in the grid
Parameters:
Name Type Description
x Number the x position to check
y Number the y position to check
Source:
Returns:
the node at the position
Type
Node

getNodeValue(x, y) → {object}

Gets the value at a node in the grid
Parameters:
Name Type Description
x Number the x position of the node whose value will be checked
y Number the y position of the node whose value will be checked
Source:
Returns:
the value of the node
Type
object

getWalkableNeighbors(x, y) → {Array.<Node>}

Gets the open neighbors of a node
Parameters:
Name Type Description
x Number the x position of the node to checked
y Number the y position of the node to check
Source:
Returns:
the node's open neighbors
Type
Array.<Node>

ManhattanDistance(object1, object2) → {Number}

Gets the manhattan distance between two nodes
Parameters:
Name Type Description
object1 Node node to check
object2 Node node to check
Source:
Returns:
the Manhattan distance between object1 and object2
Type
Number

moveNodeValue(x1, y1, x2, y2)

Moves a value from one node to another
Parameters:
Name Type Description
x1 the x position of the node whose value will be copied over
y1 the y position of the node whose value will be copied over
x2 the x position of the node who will receive the new value
y2 the y position of the node who will receive the new value
Source: