本文整理汇总了C#中IMap.GetHeuristic方法的典型用法代码示例。如果您正苦于以下问题:C# IMap.GetHeuristic方法的具体用法?C# IMap.GetHeuristic怎么用?C# IMap.GetHeuristic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMap
的用法示例。
在下文中一共展示了IMap.GetHeuristic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPath
public bool FindPath(IMap map, int start, int target)
{
openList = new SimplePriorityQueue<int>();
openListLookup = new AStarNode?[map.NrNodes];
this.map = map;
this.isGoal = nodeId => nodeId == target;
this.getHeuristic = nodeId => map.GetHeuristic(nodeId, target);
Path = new List<int>();
FindPathAstar(start);
return true;
}
示例2: FindPath
/// <summary>
/// Performs an A* search following the Node Array A* implementation
/// </summary>
public Path FindPath(IMap map, int start, int target)
{
this.isGoal = nodeId => nodeId == target;
this.calculateHeuristic = nodeId => map.GetHeuristic(nodeId, target);
this.map = map;
var heuristic = calculateHeuristic(start);
var startNode = new AStarNode(start, 0, heuristic, CellStatus.Open);
var openQueue = new SimplePriorityQueue<int>();
openQueue.Enqueue(start, startNode.F);
// The open list lookup is indexed by the number of nodes in the graph/map,
// and it is useful to check quickly the status of any node that has been processed
var nodeLookup = new AStarNode?[map.NrNodes];
nodeLookup[start] = startNode;
while (openQueue.Count != 0)
{
var nodeId = openQueue.Dequeue();
var node = nodeLookup[nodeId].Value;
if (isGoal(nodeId))
{
return ReconstructPath(nodeId, nodeLookup);
}
ProcessNeighbours(nodeId, node, nodeLookup, openQueue);
// Close the node. I hope some day the will implement something
// like the records in F# with the "with" keyword
nodeLookup[nodeId] = new AStarNode(node.Parent, node.G, node.H, CellStatus.Closed);
}
// No path found. We could return a null, but since I read the book "Code Complete" I decided
// its best to return an empty path, and I'll return a -1 as PathCost
// TODO: Additionally, all those magic numbers like this -1 should be converted to explicit,
// clearer constants
return new Path(new List<int>(), -1);
}