本文整理汇总了C#中PriorityQueue.insert方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.insert方法的具体用法?C# PriorityQueue.insert怎么用?C# PriorityQueue.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: findPath
//This is the method that will do A*. It returns a vector of locations to follow
public LinkedList<Vector3> findPath(Vector3 start, Vector3 end)
{
LinkedList<Vector3> result = new LinkedList<Vector3> ();
Node startNode = currentGraph.getNodeByLocation ((int)start.y, (int)start.x);
startNode.rawCost = 0.0f;
queue = new PriorityQueue (startNode);
while (!queue.isEmpty()) {
//The A* magic happens here
Node minNode = queue.pop ();
//if this is our ending node, stop pathfinding and form our full path on the graph
if (minNode == currentGraph.getNodeByLocation ((int) end.y, (int) end.x)) {
//Here we form the path depending
Node currentNode = minNode;
while (currentNode != null) {
result.AddFirst(new Vector3(currentNode.widthPos, currentNode.heightPos));
currentNode = currentNode.parent;
}
resetGraph();
return result;
}
//else, we need to update our priority queue, etc.
else {
float currentRaw = minNode.rawCost;
foreach (Node neighbor in minNode.edges.Values) {
if (queue.isVisited(neighbor)) {
float oldRaw = neighbor.rawCost;
float newRaw = currentRaw + Vector2.Distance(new Vector2(minNode.widthPos, minNode.heightPos), new Vector2(neighbor.widthPos, neighbor.heightPos));
if (newRaw < oldRaw) {
neighbor.rawCost = newRaw;
neighbor.parent = minNode;
}
} else {
neighbor.rawCost = currentRaw + Vector2.Distance(new Vector2(minNode.widthPos, minNode.heightPos), new Vector2(neighbor.widthPos, neighbor.heightPos));
neighbor.parent = minNode;
queue.insert(neighbor);
}
}
}
}
resetGraph ();
return result;
}