Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
essentials.action.Pathing.Engines.AStarEngine Class Reference
Inheritance diagram for essentials.action.Pathing.Engines.AStarEngine:
essentials.action.Pathing.IPathingEngine

Public Member Functions

 AStarEngine (Vector3i start, Vector3i end, IPathCostEngine costEngine)
 
Path GetResult ()
 
Path GetIncrementalPath ()
 
void Iterate ()
 
Path Compute ()
 

Properties

Vector3i Start [get]
 
Vector3i End [get]
 
PathEngineState State [get]
 
- Properties inherited from essentials.action.Pathing.IPathingEngine
Vector3i Start [get]
 
Vector3i End [get]
 
PathEngineState State [get]
 

Constructor & Destructor Documentation

essentials.action.Pathing.Engines.AStarEngine.AStarEngine ( Vector3i  start,
Vector3i  end,
IPathCostEngine  costEngine 
)

Attribute: _start

= new CostNode(_start, _startingHeuristic, 0, null);

52  {
53  _start = start;
54  _end = end;
55  _costEngine = costEngine;
56  _state = PathEngineState.Working;
57 
58  _startingHeuristic = _costEngine.GetHeuristic(_start, _end);
59  _openNodes[_start] = new CostNode(_start, _startingHeuristic, 0, null);
60  }
PathEngineState
Definition: PathEngineState.cs:5
int GetHeuristic(Vector3i src, Vector3i dst)

Member Function Documentation

Path essentials.action.Pathing.Engines.AStarEngine.Compute ( )

Implements essentials.action.Pathing.IPathingEngine.

148  {
149  while(_state == PathEngineState.Working)
150  {
151  Iterate();
152  }
153 
154  if (_state == PathEngineState.Complete)
155  {
156  return GetResult();
157  }
158  return null;
159  }
PathEngineState
Definition: PathEngineState.cs:5
void Iterate()
Definition: AStarEngine.cs:96
Path GetResult()
Definition: AStarEngine.cs:62
Path essentials.action.Pathing.Engines.AStarEngine.GetIncrementalPath ( )

Implements essentials.action.Pathing.IPathingEngine.

73  {
74  var path = new List<Vector3i>();
75  var current = GetCurrentNode();
76  do
77  {
78  path.Add(current.Point);
79  current = current.Parent;
80  } while(current != null);
81  path.Reverse();
82  return new Path(path);
83  }
Path essentials.action.Pathing.Engines.AStarEngine.GetResult ( )

Implements essentials.action.Pathing.IPathingEngine.

63  {
64  if (_state != PathEngineState.Complete)
65  {
66  throw new PathEngineException("Uncomplete pathing");
67  }
68 
69  return GetIncrementalPath();
70  }
PathEngineState
Definition: PathEngineState.cs:5
Path GetIncrementalPath()
Definition: AStarEngine.cs:72
void essentials.action.Pathing.Engines.AStarEngine.Iterate ( )

Attribute: newPoint

.ActualCost)

Attribute: newPoint

= new CostNode(newPoint, heuristicCost, newCost, current);

Implements essentials.action.Pathing.IPathingEngine.

97  {
98  if (_state != PathEngineState.Working)
99  return;
100 
101  if (_openNodes.Count == 0)
102  {
103  _state = PathEngineState.Failed;
104  return;
105  }
106 
107  var current = GetCurrentNode();
108  if (current.Point == _end)
109  {
110  _state = PathEngineState.Complete;
111  return;
112  }
113 
114  if (current.HeuristicCost >= _startingHeuristic * 2 && _iterationCount > 50)
115  {
116  _state = PathEngineState.Failed;
117  return;
118  }
119 
120  _openNodes.Remove(current.Point);
121  _closedPoints.Add(current.Point);
122 
123  foreach(var offset in _neighbors)
124  {
125  var newPoint = current.Point + offset;
126  if (_closedPoints.Contains(newPoint))
127  continue;
128 
129  int moveCost = _costEngine.GetActualCost(current.Point, newPoint);
130  if (moveCost < 0)
131  {
132  _closedPoints.Add(newPoint);
133  continue;
134  }
135 
136  int newCost = current.ActualCost + moveCost;
137  if (!_openNodes.ContainsKey(newPoint) || newCost < _openNodes[newPoint].ActualCost)
138  {
139  int heuristicCost = newCost + _costEngine.GetHeuristic(newPoint, _end);
140  _openNodes[newPoint] = new CostNode(newPoint, heuristicCost, newCost, current);
141  }
142  }
143 
144  _iterationCount++;
145  }
PathEngineState
Definition: PathEngineState.cs:5
int GetHeuristic(Vector3i src, Vector3i dst)
int GetActualCost(Vector3i src, Vector3i dst)

Property Documentation

Vector3i essentials.action.Pathing.Engines.AStarEngine.End
get
Vector3i essentials.action.Pathing.Engines.AStarEngine.Start
get
PathEngineState essentials.action.Pathing.Engines.AStarEngine.State
get

The documentation for this class was generated from the following file: