com.badlogic.gdx.ai.pfa.Heuristic Java Examples

The following examples show how to use com.badlogic.gdx.ai.pfa.Heuristic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexedAStarPathFinder.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
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;
	}
 
Example #2
Source File: IndexedAStarPathFinder.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: AStartPathFinding.java    From Pacman_libGdx with MIT License 5 votes vote down vote up
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);
        }
  };
}
 
Example #4
Source File: IndexedAStarPathFinder.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #5
Source File: IndexedAStarPathFinder.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@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;
}