本文整理汇总了C#中PriorityQueue.Find方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.Find方法的具体用法?C# PriorityQueue.Find怎么用?C# PriorityQueue.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.Find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPath
public static Vector3[] FindPath(int[] start, int[] end)
{
PathManager mgr = GetInstance ();
Vector3[] outPath;
if (mgr.QueryCache (start, end, out outPath)) {
return outPath;
}
int pathSearched = 0;
GridManager grid = GridManager.GetInstance ();
if (!grid.HasSurface (start) || !grid.HasSurface (end)) {
return null;
}
List<Node> closed = new List<Node> ();
PriorityQueue<Node> open = new PriorityQueue<Node> ();
open.comparator = Node.Comparison;
Vector3 goal = grid.GridCenter (end);
Node s = new Node ();
s.edge = null;
s.g_score = 0.0f;
s.h_score = mgr.SqDist (s.p, goal);
s.f_score = s.h_score;
s.p = grid.GridCenter (start);
open.Add (s);
while (!open.Empty ()) {
Node node = open.Top;
open.Remove (open.Top);
// if it ends, end.
if (node.p == goal) {
List<Vector3> path = new List<Vector3> ();
mgr.ReconstructPath (node, path);
Vector3[] outpath = path.ToArray ();
mgr.CachePath (start, end, outpath);
return outpath;
}
closed.Add (node);
List<Vector3> neighbors = mgr.Neighbors(node.p);
foreach (Vector3 n in neighbors) {
if (closed.FindIndex ((a) => a.p == n) >= 0) {
continue;
}
float temp_g = node.g_score + mgr.SqDist(node.p, n);
Node f = open.Find ((a) => a.p == n);
if (f == null) {
f = new Node ();
f.edge = node;
f.g_score = temp_g;
f.h_score = mgr.SqDist(n, goal);
f.f_score = f.g_score + f.h_score;
f.p = n;
open.Add (f);
} else if (temp_g < f.g_score) {
f.edge = node;
f.g_score = temp_g;
f.f_score = f.g_score + f.h_score;
open.Update (f);
}
}
if (pathSearched >= mgr.pathSearchLimit) {
return null;
} else {
pathSearched ++;
}
}
return null;
}