本文整理汇总了C#中PriorityQueue.addNode方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.addNode方法的具体用法?C# PriorityQueue.addNode怎么用?C# PriorityQueue.addNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.addNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeneratePath
/// <summary>
/// get path plan
/// </summary>
private void GeneratePath(RaycastHit[] hits)
{
SystemLogger.write("Creating a path");
// Create list to hold unformatted moves
int[] unFormattedMoves = new int[3];
// fill open list
for (int i = 0; i < hits.Length; ++i) //RaycastHit hit in hits
{
// Check if correct mesh was hit
if (hits[i].triangleIndex != -1 && hits[i].collider != null && hits[i].collider.CompareTag("Planet"))
{
this.planetVertexNavigation.getMovesTriangle(hits[i].triangleIndex * 3, ref unFormattedMoves);
break;
}
}
// Add nodes to priority queue
PriorityQueue queue = new PriorityQueue();
// Create list of moves
List<int> moves = new List<int>();
for (int i = 0; i < unFormattedMoves.Length; ++i)
{
moves.Add(unFormattedMoves[i]);
// Create new node
AStarNode node = new AStarNode(1, 1, unFormattedMoves[i], moves);
// add node to queue
queue.addNode(node);
moves.Clear();
}
// Visited nodes
HashSet<int> visitedNodes = new HashSet<int>();
// Run A* while moves available
while (queue.Length() > 0) // Is there an IsEmpty property... this may be better.
{
// Grab best node from priority queue
AStarNode node = queue.popNode();
// Get moves for a vertex
List<int> availableMoves = this.planetVertexNavigation.getMovesVertex(node.Index);
// Loop through the nodes available paths
for (int i = 0; i < availableMoves.Count; ++i)
{
// Only use vertex if we haven't already explored this node
if (!visitedNodes.Contains(availableMoves[i]))
{
// Find obstacles
bool pointCollision;
if(this.movementType == VerticeType.GROUND)
{
pointCollision = !this.collisionAtPoint(this.planetVertexNavigation.getVertex(availableMoves[i]).position);
}
else
{
pointCollision = !this.collisionAtPoint(this.planetVertexNavigation.flyingVertices[this.planetVertexNavigation.getVertex(availableMoves[i]).key]);
}
// if obstacle was not found
if(pointCollision)
{
// Calculate distance between vertex and target
float vertexHeuristic = DistanceCalculator.squareEuclidianDistance(this.planetVertexNavigation.getVertex(availableMoves[i]).position, this.target);
// Check if close enough to target
if (vertexHeuristic < this.planetVertexNavigation.avgVertexlength * this.ExtraDistanceMultiplier)
{
SystemLogger.write("Path has been found");
// Yes we are, solved
this.plan = node.Moves;
this.plan.Add(availableMoves[i]);
// break out of loop
return;
}
else
{
// add to visited
visitedNodes.Add(availableMoves[i]);
// Create cropy of moves
List<int> newMoves = new List<int>(node.Moves);
// Add available moves
newMoves.Add(availableMoves[i]);
// Create new nodes with heuristic and step cost
AStarNode newNode = new AStarNode(node.G + this.calculateDistanceFromVertex(availableMoves[i]), vertexHeuristic, availableMoves[i], newMoves);
//.........这里部分代码省略.........