Merge pull request #191 from apollo-rsps/bugfix/106-fix-astar-pathfinder

Fix the A* path finding implementation
This commit is contained in:
Major
2016-02-10 13:48:06 +00:00
2 changed files with 20 additions and 1 deletions
@@ -9,6 +9,7 @@ import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import org.apollo.game.model.Direction;
import org.apollo.game.model.Position;
import org.apollo.game.model.area.RegionRepository;
@@ -73,7 +74,8 @@ public final class AStarPathfindingAlgorithm extends PathfindingAlgorithm {
}
Position adjacent = new Position(nextX, nextY);
if (traversable(adjacent)) {
Direction direction = Direction.between(adjacent, position);
if (traversable(adjacent, direction)) {
Node node = nodes.computeIfAbsent(adjacent, Node::new);
compare(active, node, open, sorted, heuristic);
}
@@ -0,0 +1,17 @@
package org.apollo.game.model.entity.path;
import org.apollo.game.model.Position;
/**
* A heuristic which uses <i>Euclidean</i> distance to calculate the cost for a movement.
*/
public final class EuclideanHeuristic extends Heuristic {
/**
* @see Position#getDistance(Position)
*/
@Override
public int estimate(Position current, Position target) {
return current.getDistance(target);
}
}