本文整理汇总了C#中System.Collections.Generic.PriorityQueue.IsMember方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.IsMember方法的具体用法?C# PriorityQueue.IsMember怎么用?C# PriorityQueue.IsMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.IsMember方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AstarRun
public void AstarRun()
{
Console.WriteLine("A* starts!");
NavigateNode start = new NavigateNode(2, 2, NavigateNode.StateEnum.NAVIGABLE);
NavigateNode end = new NavigateNode(goalX, goalY, NavigateNode.StateEnum.NAVIGABLE);
PriorityQueue<NavigateNode> openSet = new PriorityQueue<NavigateNode>();
PriorityQueue<NavigateNode> closeSet = new PriorityQueue<NavigateNode>();
openSet.Add(start);
while (!openSet.Empty) {
// get from open set
NavigateNode current = openSet.Pop();
// add to close set
closeSet.Add(current);
// goal found
if (current.IsSameLocation(end)) {
while (current.Parent != null) {
mMap[current.X, current.Y].State = NavigateNode.StateEnum.PATH;
current = current.Parent;
}
return;
}
else {
List<NavigateNode> neighbors = GetNeighbors(current);
foreach (NavigateNode n in neighbors) {
if (closeSet.IsMember(n)) {
continue;
}
else {
if (!openSet.IsMember(n)) {
n.Parent = current;
n.DirectCost = current.DirectCost + GetDirectCost(current, n);
n.HeuristicCost = GetHeuristicCost(n, end);
n.TotalCost = n.DirectCost + n.HeuristicCost;
// add to open set
openSet.Add(n);
}
else {
double costFromThisPathToM = current.DirectCost + GetDirectCost(current, n);
// we found a better path
if (costFromThisPathToM < n.DirectCost) {
n.Parent = current; // change parent to n
n.DirectCost = costFromThisPathToM; // recalculate direct cost
n.TotalCost = n.HeuristicCost + n.DirectCost; // recalculate total cost
}
}
}
}
}
}
Console.WriteLine("end here?");
}