From 1ef364beb8b60db2070bfe9a4c33c020cb230a27 Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Tue, 9 Feb 2016 23:39:17 +0000 Subject: [PATCH 1/2] Fix missing direction in a* traversable call --- .../game/model/entity/path/AStarPathfindingAlgorithm.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/game/src/main/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java b/game/src/main/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java index b6609b2e..6d69626a 100644 --- a/game/src/main/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java +++ b/game/src/main/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java @@ -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); } From bea2e61b27110ca7112cadfdde39dc5b6333e3cb Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Tue, 9 Feb 2016 23:41:15 +0000 Subject: [PATCH 2/2] Add a heuristic using euclidean distance for cost --- .../model/entity/path/EuclideanHeuristic.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 game/src/main/org/apollo/game/model/entity/path/EuclideanHeuristic.java diff --git a/game/src/main/org/apollo/game/model/entity/path/EuclideanHeuristic.java b/game/src/main/org/apollo/game/model/entity/path/EuclideanHeuristic.java new file mode 100644 index 00000000..d5b2dc7c --- /dev/null +++ b/game/src/main/org/apollo/game/model/entity/path/EuclideanHeuristic.java @@ -0,0 +1,17 @@ +package org.apollo.game.model.entity.path; + +import org.apollo.game.model.Position; + +/** + * A heuristic which uses Euclidean 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); + } +}