mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Merge pull request #191 from apollo-rsps/bugfix/106-fix-astar-pathfinder
Fix the A* path finding implementation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user