Show / Hide Table of Contents

Class GoalMap

Implementation of a goal map system, also known as Dijkstra maps, based on this article

Inheritance
System.Object
GoalMap
Implements
IMapView<System.Nullable<System.Double>>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
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 Source

GoalMap(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 Source

BaseMap

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>
| Improve this Doc View Source

DistanceMeasurement

The distance measurement the GoalMap is using to calculate distance.

Declaration
public Distance DistanceMeasurement { get; }
Property Value
Type Description
Distance
| Improve this Doc View Source

Height

Height of the goal map.

Declaration
public int Height { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Width

Width of the goal map.

Declaration
public int Width { get; }
Property Value
Type Description
System.Int32

Methods

| Improve this Doc View Source

GetDirectionOfMinValue(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
System.Object.ToString()
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

| Improve this Doc View Source

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 Source

Updated

Triggers when the GoalMap is updated.

Declaration
public event Action Updated
Event Type
Type Description
System.Action

Implements

IMapView<T>

Extension Methods

Utility.Yield<T>(T)
IMapViewExtensions.Bounds<T>(IMapView<T>)
IMapViewExtensions.Contains<T>(IMapView<T>, Int32, Int32)
IMapViewExtensions.Contains<T>(IMapView<T>, Coord)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, Int32, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.Positions<T>(IMapView<T>)
IMapViewExtensions.RandomItem<T>(IMapView<T>, IGenerator)
IMapViewExtensions.RandomItem<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, T, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IEnumerable<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, HashSet<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator, T[])
IMapViewExtensions.RandomPosition<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator)
GoalMapExtensions.GetDirectionOfMinValue(IMapView<Nullable<Double>>, Coord, AdjacencyRule)
GoalMapExtensions.GetDirectionOfMinValue(IMapView<Nullable<Double>>, Int32, Int32, AdjacencyRule)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX