本文整理汇总了C#中Path.AddNode方法的典型用法代码示例。如果您正苦于以下问题:C# Path.AddNode方法的具体用法?C# Path.AddNode怎么用?C# Path.AddNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path
的用法示例。
在下文中一共展示了Path.AddNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getPath
private static Path getPath(Dictionary<Node, Node> moves, Node end)
{
Path path = new Path();
path.AddNode(end);
while (moves.ContainsKey(end))
{
end = moves[end];
path.AddNode(end);
}
path.Reverse();
return path;
}
示例2: FindPath
public Path FindPath( Vector3 startPos, Vector3 endPos )
{
// Check if endPos is valid
if ( gridGenerator.Grid[Mathf.FloorToInt( endPos.x ), Mathf.FloorToInt( endPos.z )] ) {
// End pos is not available; return a path with only startPos
Path p = new Path();
p.AddNode( startPos );
return p;
}
// Find a path
Dictionary<Vector3, Vector3> cameFrom = new Dictionary<Vector3, Vector3>();
List<Vector3> closedSet = new List<Vector3>();
List<Vector3> openSet = new List<Vector3>();
openSet.Add( startPos );
Dictionary<Vector3, float> gScores = new Dictionary<Vector3, float>(); // Cost from start along best-known path
gScores[startPos] = 0;
Dictionary<Vector3, float> fScores = new Dictionary<Vector3, float>(); // Estimated total cost
fScores[startPos] = gScores[startPos] + GuessDistanceHeuristic( startPos, endPos );
while ( openSet.Count > 0 ) {
Vector3 currentNode = GetLowestFScore( openSet, fScores );
if ( CalcDist( currentNode, endPos ) < 1.0f ) {
return ReconstructPath( cameFrom, currentNode );
}
openSet.Remove( currentNode );
closedSet.Add( currentNode );
foreach ( Vector3 neighbor in GetNeigbors( currentNode ) ) {
float tempGScore = gScores[currentNode] + Vector3.Distance( currentNode, neighbor );
if ( closedSet.Contains( neighbor ) ) {
if ( tempGScore >= gScores[neighbor] ) {
continue;
}
}
if ( !openSet.Contains( neighbor ) || tempGScore < gScores[neighbor] ) {
cameFrom[neighbor] = currentNode;
gScores[neighbor] = tempGScore;
fScores[neighbor] = gScores[neighbor] + GuessDistanceHeuristic( neighbor, endPos );
if ( !openSet.Contains( neighbor ) ) {
openSet.Add( neighbor );
}
}
}
}
// If we reached here, we failed to find a path. Return a straight line.
return PlaceholderPath( startPos, endPos );
}
示例3: ReconstructPath
private Path ReconstructPath( Dictionary<Vector3, Vector3> cameFrom, Vector3 currentNode )
{
if ( cameFrom.ContainsKey( currentNode ) ) {
Path p = ReconstructPath( cameFrom, cameFrom[currentNode] );
p.AddNode( currentNode );
return p;
} else {
Path p = new Path();
p.AddNode( currentNode );
return p;
}
}