public CalculateHScore ( |
||
node | ||
return | uint |
public uint CalculateHScore (GraphNode node) {
uint v1;
uint v2;
switch (heuristic) {
case Heuristic.Euclidean:
v1 = (uint)(((GetHTarget () - node.position).costMagnitude)*heuristicScale);
v2 = hTargetNode != null ? AstarPath.active.euclideanEmbedding.GetHeuristic ( node.NodeIndex, hTargetNode.NodeIndex ) : 0;
return System.Math.Max (v1,v2);
case Heuristic.Manhattan:
Int3 p2 = node.position;
v1 = (uint)((System.Math.Abs (hTarget.x-p2.x) + System.Math.Abs (hTarget.y-p2.y) + System.Math.Abs (hTarget.z-p2.z))*heuristicScale);
v2 = hTargetNode != null ? AstarPath.active.euclideanEmbedding.GetHeuristic ( node.NodeIndex, hTargetNode.NodeIndex ) : 0;
return System.Math.Max (v1,v2);
case Heuristic.DiagonalManhattan:
Int3 p = GetHTarget () - node.position;
p.x = System.Math.Abs (p.x);
p.y = System.Math.Abs (p.y);
p.z = System.Math.Abs (p.z);
int diag = System.Math.Min (p.x,p.z);
int diag2 = System.Math.Max (p.x,p.z);
v1 = (uint)((((14*diag)/10) + (diag2-diag) + p.y) * heuristicScale);
v2 = hTargetNode != null ? AstarPath.active.euclideanEmbedding.GetHeuristic ( node.NodeIndex, hTargetNode.NodeIndex ) : 0;
return System.Math.Max (v1,v2);
}
return 0U;
}
public override void Open(Path path, PathNode pathNode, PathHandler handler) { if (connections == null) { return; } for (int i = 0; i < connections.Length; i++) { GraphNode other = connections[i]; if (path.CanTraverse(other)) { PathNode pathOther = handler.GetPathNode(other); if (pathOther.pathID != handler.PathID) { pathOther.parent = pathNode; pathOther.pathID = handler.PathID; pathOther.cost = connectionCosts[i]; pathOther.H = path.CalculateHScore(other); other.UpdateG(path, pathOther); handler.PushNode(pathOther); } else { //If not we can test if the path from this node to the other one is a better one then the one already used uint tmpCost = connectionCosts[i]; #if ASTAR_NO_TRAVERSAL_COST if (pathNode.G + tmpCost < pathOther.G) #else if (pathNode.G + tmpCost + path.GetTraversalCost(other) < pathOther.G) #endif { pathOther.cost = tmpCost; pathOther.parent = pathNode; other.UpdateRecursiveG(path, pathOther, handler); } #if ASTAR_NO_TRAVERSAL_COST else if (pathOther.G + tmpCost < pathNode.G && other.ContainsConnection(this)) #else else if (pathOther.G + tmpCost + path.GetTraversalCost(this) < pathNode.G && other.ContainsConnection(this)) #endif { //Or if the path from the other node to this one is better pathNode.parent = pathOther; pathNode.cost = tmpCost; UpdateRecursiveG(path, pathNode, handler); } } } } }