本文整理汇总了Java中com.badlogic.gdx.ai.pfa.Heuristic类的典型用法代码示例。如果您正苦于以下问题:Java Heuristic类的具体用法?Java Heuristic怎么用?Java Heuristic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Heuristic类属于com.badlogic.gdx.ai.pfa包,在下文中一共展示了Heuristic类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import com.badlogic.gdx.ai.pfa.Heuristic; //导入依赖的package包/类
protected boolean search (N startNode, N endNode, Heuristic<N> heuristic) {
initSearch(startNode, endNode, heuristic);
// Iterate through processing each node
do {
// Retrieve the node with smallest estimated total cost from the open list
current = openList.pop();
current.category = CLOSED;
// Terminate if we reached the goal node
if (current.node == endNode) return true;
visitChildren(endNode, heuristic);
} while (openList.size > 0);
// We've run out of nodes without finding the goal, so there's no solution
return false;
}
示例2: initSearch
import com.badlogic.gdx.ai.pfa.Heuristic; //导入依赖的package包/类
protected void initSearch (N startNode, N endNode, Heuristic<N> heuristic) {
if (metrics != null) metrics.reset();
// Increment the search id
if (++searchId < 0) searchId = 1;
// Initialize the open list
openList.clear();
// Initialize the record for the start node and add it to the open list
NodeRecord<N> startRecord = getNodeRecord(startNode);
startRecord.node = startNode;
startRecord.connection = null;
startRecord.costSoFar = 0;
addToOpenList(startRecord, heuristic.estimate(startNode, endNode));
current = null;
}
示例3: PathFinder
import com.badlogic.gdx.ai.pfa.Heuristic; //导入依赖的package包/类
public PathFinder(final CachingIndexedGraph<TileCoordinate> graph) {
this.graph = graph;
pathFinder = new IndexedAStarPathFinder<TileCoordinate>(graph);
heuristic = new Heuristic<TileCoordinate>() {
@Override
public float estimate(final TileCoordinate node, final TileCoordinate endNode) {
return Math.abs(endNode.getX() - node.getX()) + Math.abs(endNode.getY() - node.getY());
}
};
}
示例4: searchConnectionPath
import com.badlogic.gdx.ai.pfa.Heuristic; //导入依赖的package包/类
@Override
public boolean searchConnectionPath (N startNode, N endNode, Heuristic<N> heuristic, GraphPath<Connection<N>> outPath) {
// Perform AStar
boolean found = search(startNode, endNode, heuristic);
if (found) {
// Create a path made of connections
generateConnectionPath(startNode, outPath);
}
return found;
}
示例5: searchNodePath
import com.badlogic.gdx.ai.pfa.Heuristic; //导入依赖的package包/类
@Override
public boolean searchNodePath (N startNode, N endNode, Heuristic<N> heuristic, GraphPath<N> outPath) {
// Perform AStar
boolean found = search(startNode, endNode, heuristic);
if (found) {
// Create a path made of nodes
generateNodePath(startNode, outPath);
}
return found;
}
示例6: AStartPathFinding
import com.badlogic.gdx.ai.pfa.Heuristic; //导入依赖的package包/类
public AStartPathFinding(AStarMap map) {
this.map = map;
this.pathfinder = new IndexedAStarPathFinder<Node>(createGraph(map));
this.connectionPath = new DefaultGraphPath<Connection<Node>>();
this.heuristic = new Heuristic<Node>() {
@Override
public float estimate (Node node, Node endNode) {
// Manhattan distance
return Math.abs(endNode.x - node.x) + Math.abs(endNode.y - node.y);
}
};
}