Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void findPath(Node startNode, Node targetNode)
- throws HeapFullException, HeapEmptyException {
- Heap<Node> openSet = new Heap<>(width * height); // this where we make use of our heaps
- Heap<Node> closedSet = new Heap<>(width * height);
- startNode.gCost = 0;
- startNode.hCost = getDistance(startNode, targetNode);
- openSet.add(startNode);
- while (!openSet.isEmpty()) {
- Node current = openSet.removeFirst();
- ArrayList<Node> neighbours = getNeighbours(current);
- for (Node node : neighbours) {
- node.parent = current;
- }
- for (Node node : neighbours) {
- if (node.equals(targetNode)) {
- return;
- }
- node.gCost = current.gCost + getDistance(current, node);
- node.hCost = getDistance(node, targetNode);
- if (!openSet.contains(node) && openSet.peekTop().getFCost() < node.getFCost()) {
- openSet.add(node);
- }
- }
- closedSet.add(current);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement