Class GoalMap
A class for assigning weights to every cell on the Map which can then be used for finding paths or building desire-driven AI
Inheritance
Inherited Members
Namespace: RogueSharp
Assembly: RogueSharp.dll
Syntax
public class GoalMap : IGoalMap
Constructors
| Improve this Doc View SourceGoalMap(IMap)
Constructs a new instance of a GoalMap for the specified Map that will not consider diagonal movements to be valid.
Declaration
public GoalMap(IMap map)
Parameters
Type | Name | Description |
---|---|---|
IMap | map | The Map that this GoalMap will be created for |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown on null map |
GoalMap(IMap, Boolean)
Constructs a new instance of a GoalMap for the specified Map that will consider diagonal movements to be valid if allowDiagonalMovement is set to true.
Declaration
public GoalMap(IMap map, bool allowDiagonalMovement)
Parameters
Type | Name | Description |
---|---|---|
IMap | map | The Map that this GoalMap will be created for |
System.Boolean | allowDiagonalMovement | True if diagonal movements are allowed. False otherwise |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown on null map |
Methods
| Improve this Doc View SourceAddGoal(Int32, Int32, Int32)
Add a Goal at the specified location with the specified weight
Declaration
public void AddGoal(int x, int y, int weight)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Goal starting with 0 as the farthest left |
System.Int32 | y | Y location of the Goal starting with 0 as the top |
System.Int32 | weight | The priority of this goal with respect to other goals with lower numbers being a higher priority |
AddObstacle(Int32, Int32)
Add an Obstacle at the specified location. Any paths found must not go through Obstacles
Declaration
public void AddObstacle(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Obstacle starting with 0 as the farthest left |
System.Int32 | y | Y location of the Obstacle starting with 0 as the top |
AddObstacles(IEnumerable<Point>)
Add multiple obstacles from the specified enumeration of locations
Declaration
public void AddObstacles(IEnumerable<Point> obstacles)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Point> | obstacles | An enumeration of points representing X, Y locations of Obstacles to avoid when path-finding |
ClearGoals()
Remove all goals from this GoalMap
Declaration
public void ClearGoals()
ClearObstacles()
Remove all Obstacles from this GoalMap
Declaration
public void ClearObstacles()
FindPath(Int32, Int32)
Returns a shortest Path representing an ordered List of Points from the specified location to the Goal determined to have the highest priority Distance to the goals and the weight of the goals are both used in determining the priority The path must not pass through any obstacles specified in this GoalMap instance
Declaration
public Path FindPath(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the beginning of the path, starting with 0 as the farthest left |
System.Int32 | y | Y location of the beginning of the path, starting with 0 as the top |
Returns
Type | Description |
---|---|
Path | An ordered List of Points representing a shortest path from the specified location to the Goal determined to have the highest priority |
Exceptions
Type | Condition |
---|---|
PathNotFoundException | Thrown when there is not a path from the Source x,y to any Goal or a Goal is not set |
FindPathAvoidingGoals(Int32, Int32)
Returns a Path representing an ordered list of Points from the specified location away from Goals specified in this GoalMap instance Distance to the goals and the weight of the goals are both used in determining the priority of avoiding the Goals The path must not pass through any Obstacles specified in this GoalMap instance
Declaration
public Path FindPathAvoidingGoals(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the beginning of the path, starting with 0 as the farthest left |
System.Int32 | y | Y location of the beginning of the path, starting with 0 as the top |
Returns
Type | Description |
---|---|
Path | A Path representing ordered List of Points from the specified location away from Goals and avoiding Obstacles |
Exceptions
Type | Condition |
---|---|
PathNotFoundException | Thrown when there are no possible paths |
FindPaths(Int32, Int32)
Returns a ReadOnlyCollection of Paths representing all of the shortest paths from the specified location to the Goal or Goals determined to have the highest priority This method is useful when there are multiple paths that would all work and we want to have some additional logic to pick one of the best paths The FindPath( int x, int y ) method in the GoalMap class uses this method and then chooses the first path.
Declaration
public ReadOnlyCollection<Path> FindPaths(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the beginning of the path, starting with 0 as the farthest left |
System.Int32 | y | Y location of the beginning of the path, starting with 0 as the top |
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<Path> | A ReadOnlyCollection of Paths representing all of the shortest paths from the specified location to the Goal or Goals determined to have the highest priority |
Exceptions
Type | Condition |
---|---|
PathNotFoundException | Thrown when there is not a path from the Source x,y to any Goal or a Goal is not set |
RemoveGoal(Int32, Int32)
Remove a Goal at the specified location
Declaration
public void RemoveGoal(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Goal starting with 0 as the farthest left |
System.Int32 | y | Y location of the Goal starting with 0 as the top |
RemoveObstacle(Int32, Int32)
Remove an Obstacle at the specified location
Declaration
public void RemoveObstacle(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the Obstacle starting with 0 as the farthest left |
System.Int32 | y | Y location of the Obstacle starting with 0 as the top |
ToString()
Returns a string representation of the current GoalMap
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representing the current GoalMap |
Overrides
TryFindPath(Int32, Int32)
Returns a shortest Path representing an ordered List of Points from the specified location to the Goal determined to have the highest priority Distance to the goals and the weight of the goals are both used in determining the priority The path must not pass through any obstacles specified in this GoalMap instance null will be returned if a path cannot be found
Declaration
public Path TryFindPath(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the beginning of the path, starting with 0 as the farthest left |
System.Int32 | y | Y location of the beginning of the path, starting with 0 as the top |
Returns
Type | Description |
---|---|
Path | An ordered List of Points representing a shortest path from the specified location to the Goal determined to have the highest priority. null is returned if a path cannot be found |
TryFindPathAvoidingGoals(Int32, Int32)
Returns a Path representing an ordered list of Points from the specified location away from Goals specified in this GoalMap instance Distance to the goals and the weight of the goals are both used in determining the priority of avoiding the Goals The path must not pass through any Obstacles specified in this GoalMap instance Returns null if a Path is not found
Declaration
public Path TryFindPathAvoidingGoals(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the beginning of the path, starting with 0 as the farthest left |
System.Int32 | y | Y location of the beginning of the path, starting with 0 as the top |
Returns
Type | Description |
---|---|
Path | A Path representing ordered List of Points from the specified location away from Goals and avoiding Obstacles. Returns null if a Path is not found |
TryFindPaths(Int32, Int32)
Returns a ReadOnlyCollection of Paths representing all of the shortest paths from the specified location to the Goal or Goals determined to have the highest priority This method is useful when there are multiple paths that would all work and we want to have some additional logic to pick one of the best paths The FindPath( int x, int y ) method in the GoalMap class uses this method and then chooses the first path.
Declaration
public ReadOnlyCollection<Path> TryFindPaths(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X location of the beginning of the path, starting with 0 as the farthest left |
System.Int32 | y | Y location of the beginning of the path, starting with 0 as the top |
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<Path> | A ReadOnlyCollection of Paths representing all of the shortest paths from the specified location to the Goal or Goals determined to have the highest priority. Returns null if no path is found. |