Class GoalMap
Implementation of a goal map system, also known as Dijkstra maps, based on this article
Inheritance
Implements
Inherited Members
Namespace: GoRogue.Pathing
Assembly: GoRogue.dll
Syntax
public class GoalMap : IMapView<double?>
Remarks
This class encapsulates the work of building a goal map from your map level. You provide the constructor with a map view representing the map as GoalState values, and GoalMap will compute the goal map for the level. When the underlying circumstances of the level change, the GoalMap instance will need to be updated. Call Update() if obstacles have changed, or UpdatePathsOnly() if the goals have changed but not the obstacles.
This class exposes the resulting goal map to you via indexers -- GoalMap implements IMapView<T>, where null indicates a square is an obstacle, and any other value indicates distance from the nearest goal. Thus, a value of 0 indicates a tile contains a goal.
For items following the GoalMap, they can simply call GetDirectionOfMinValue(Coord)
Constructors
| Improve this Doc View SourceGoalMap(IMapView<GoalState>, Distance)
Constructor. Takes a base map and a distance measurement to use for calculation.
Declaration
public GoalMap(IMapView<GoalState> baseMap, Distance distanceMeasurement)
Parameters
| Type | Name | Description |
|---|---|---|
| IMapView<GoalState> | baseMap | A map view that represents the map as IMapView<T>GoalStates. |
| Distance | distanceMeasurement | The distance measurement (and implicitly the AdjacencyRule) to use for calculation. |
Properties
| Improve this Doc View SourceBaseMap
The map view of the underlying map used to determine where obstacles/goals are.
Declaration
public IMapView<GoalState> BaseMap { get; }
Property Value
| Type | Description |
|---|---|
| IMapView<GoalState> |
DistanceMeasurement
The distance measurement the GoalMap is using to calculate distance.
Declaration
public Distance DistanceMeasurement { get; }
Property Value
| Type | Description |
|---|---|
| Distance |
Height
Height of the goal map.
Declaration
public int Height { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Item[Coord]
Returns the goal-map value for the given position.
Declaration
public double? this[Coord pos] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| Coord | pos | The position to return the goal-map value for. |
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Double> | The goal-map value for the given position. |
Item[Int32]
Returns the goal-map value for the given position.
Declaration
public double? this[int index1D] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index1D | Position to return the goal-map value for, as a 1d-index-style value. |
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Double> | The goal-map value for the given position. |
Item[Int32, Int32]
Returns the goal-map value for the given position.
Declaration
public double? this[int x, int y] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | X-coordinate of the position to return the goal-map value for. |
| System.Int32 | y | Y-coordinate of the position to return the goal-map value for. |
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Double> | The goal-map value for the given position. |
Width
Width of the goal map.
Declaration
public int Width { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
| Improve this Doc View SourceGetDirectionOfMinValue(Coord)
Gets the direction of the neighbor with the minimum goal-map value from the given position.
Declaration
public Direction GetDirectionOfMinValue(Coord position)
Parameters
| Type | Name | Description |
|---|---|---|
| Coord | position | The position to get the minimum value for. |
Returns
| Type | Description |
|---|---|
| Direction | The direction that has the minimum value in the goal-map, or NONE if the neighbors are all obstacles. |
GetDirectionOfMinValue(Int32, Int32)
Gets the direction of the neighbor with the minimum goal-map value from the given position.
Declaration
public Direction GetDirectionOfMinValue(int positionX, int positionY)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | positionX | The x-value of the position to get the minimum value for. |
| System.Int32 | positionY | The y-value of the position to get the minimum value for. |
Returns
| Type | Description |
|---|---|
| Direction | The direction that has the minimum value in the goal-map, or NONE if the neighbors are all obstacles. |
ToString()
Returns the goal-map values represented as a 2D grid-style string.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A string representing the goal map values. |
Overrides
ToString(Int32)
Returns the goal-map values represented as a 2D-grid-style string, with the given field size.
Declaration
public string ToString(int fieldSize)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | fieldSize | Number of characters allocated to each value in the string. |
Returns
| Type | Description |
|---|---|
| System.String | A string representing the goal-map values. |
ToString(Int32, String)
Returns the goal-map values represented as a 2D-grid-style string, with the given field size, and any non-null values formatted using the given format string.
Declaration
public string ToString(int fieldSize, string formatString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | fieldSize | Number of characters allocated to each value in the string. |
| System.String | formatString | Format string to use for non-null values. |
Returns
| Type | Description |
|---|---|
| System.String | A string representing the goal-map values. |
ToString(String)
Returns the goal-map values represented as a 2D-grid-style string, where any value that isn't null is formatted as per the specified format string.
Declaration
public string ToString(string formatString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | formatString | Format string to use for non-null values. |
Returns
| Type | Description |
|---|---|
| System.String | A string representing the goal-map values. |
Update()
Re-evaluates the entire goal map. Should be called when obstacles change. If the obstacles have not changed but the goals have, call UpdatePathsOnly() for better efficiency.
Declaration
public bool Update()
Returns
| Type | Description |
|---|---|
| System.Boolean | False if no goals were produced by the evaluator, true otherwise |
UpdatePathsOnly()
Re-evaluates the walkable portion of the goal map. Should be called anytime the goals change but the obstacles haven't. If the obstacles have also changed, call Update() instead.
Declaration
public bool UpdatePathsOnly()
Returns
| Type | Description |
|---|---|
| System.Boolean | False if no goals were produced by the evaluator, true otherwise |
Events
| Improve this Doc View SourceUpdated
Triggers when the GoalMap is updated.
Declaration
public event Action Updated
Event Type
| Type | Description |
|---|---|
| System.Action |