Java 类com.badlogic.gdx.ai.pfa.Heuristic 实例源码

项目:Inspiration    文件:IndexedAStarPathFinder.java   
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;
    }
项目:Inspiration    文件:IndexedAStarPathFinder.java   
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;
}
项目:gdx-ai    文件:IndexedAStarPathFinder.java   
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;
    }
项目:gdx-ai    文件:IndexedAStarPathFinder.java   
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;
}
项目:jrpg-engine    文件:PathFinder.java   
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());
        }
    };
}
项目:Inspiration    文件:IndexedAStarPathFinder.java   
@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;
}
项目:Inspiration    文件:IndexedAStarPathFinder.java   
@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;
}
项目:Pacman_libGdx    文件:AStartPathFinding.java   
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);
        }
  };
}
项目:gdx-ai    文件:IndexedAStarPathFinder.java   
@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;
}
项目:gdx-ai    文件:IndexedAStarPathFinder.java   
@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;
}