Class: GridWithWeights

grids.GridWithWeights

Hierarchy

Implements

Constructors

constructor

new GridWithWeights(width, height, walls?, weights?): GridWithWeights

Parameters

Name Type Default value
width number undefined
height number undefined
walls GridLocation[] []
weights Map<GridLocation, number> undefined

Returns

GridWithWeights

Overrides

SquareGrid.constructor

Properties

height

Readonly height: number

Inherited from

SquareGrid.height


weights

Private weights: Map<string, number>


width

Readonly width: number

Inherited from

SquareGrid.width

Methods

getCost

getCost(fromId, toId): number

Provides the cost to move directly from location A to location B, assuming there is a direct connection For some graphs, this may just be the cost to enter location B, but it is technically the cost of traversing the connection.

Ensure a direct connection exists before using! Allowed to throw, but may also return a weight for a non-existant connection.

Parameters

Name Type Description
fromId GridLocation Location A
toId GridLocation Location B

Returns

number

Implementation of

WeightedGraph.getCost


inBounds

inBounds(id): boolean

Parameters

Name Type
id GridLocation

Returns

boolean

Inherited from

SquareGrid.inBounds


neighbors

neighbors(id): GridLocation[]

Returns the set of direct connections reachable from a location.

Parameters

Name Type Description
id GridLocation The location to check for connections from

Returns

GridLocation[]

Implementation of

WeightedGraph.neighbors

Inherited from

SquareGrid.neighbors


passable

passable(id): boolean

Parameters

Name Type
id GridLocation

Returns

boolean

Inherited from

SquareGrid.passable