diff options
author | pacien | 2018-02-03 20:58:28 +0100 |
---|---|---|
committer | pacien | 2018-02-03 20:58:28 +0100 |
commit | 6bbef8efd0748d7ebd71c8e17b90ac7f407e4575 (patch) | |
tree | 430f50a67de2b913a9d859cf24442982a7a599ba /src/main/java/fr | |
parent | e86f5e3c3e197aee8899f643d026dcf4468fbd84 (diff) | |
download | wallj-6bbef8efd0748d7ebd71c8e17b90ac7f407e4575.tar.gz |
Fix path finder incorrect behaviour
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src/main/java/fr')
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/board/PathFinder.java | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/board/PathFinder.java b/src/main/java/fr/umlv/java/wallj/board/PathFinder.java index c530d83..dfd1fa6 100644 --- a/src/main/java/fr/umlv/java/wallj/board/PathFinder.java +++ b/src/main/java/fr/umlv/java/wallj/board/PathFinder.java | |||
@@ -57,7 +57,7 @@ public class PathFinder { | |||
57 | 57 | ||
58 | private static <T> List<T> findPath(Node<T> start, T target, BiFunction<T, T, Double> heuristic) { | 58 | private static <T> List<T> findPath(Node<T> start, T target, BiFunction<T, T, Double> heuristic) { |
59 | Map<Node<T>, NodeSearchData<T>> searchData = new HashMap<>(); | 59 | Map<Node<T>, NodeSearchData<T>> searchData = new HashMap<>(); |
60 | TreeSet<Node<T>> discovered = new TreeSet<>(Comparator.comparingDouble(n -> searchData.get(n).estimatedCost)); | 60 | Queue<Node<T>> discovered = new PriorityQueue<>(Comparator.comparingDouble(n -> searchData.get(n).estimatedCost)); |
61 | Set<Node<T>> visited = new HashSet<>(); | 61 | Set<Node<T>> visited = new HashSet<>(); |
62 | 62 | ||
63 | searchData.put(start, new NodeSearchData<>(null, 0, heuristic.apply(start.val, target))); | 63 | searchData.put(start, new NodeSearchData<>(null, 0, heuristic.apply(start.val, target))); |
@@ -65,7 +65,7 @@ public class PathFinder { | |||
65 | 65 | ||
66 | Node<T> current; | 66 | Node<T> current; |
67 | while (!discovered.isEmpty()) { | 67 | while (!discovered.isEmpty()) { |
68 | current = discovered.pollFirst(); | 68 | current = discovered.poll(); |
69 | if (target.equals(current.val)) return buildPath(searchData, current); | 69 | if (target.equals(current.val)) return buildPath(searchData, current); |
70 | 70 | ||
71 | for (Map.Entry<Node<T>, Integer> neighborEntry : current.neighbors.entrySet()) { | 71 | for (Map.Entry<Node<T>, Integer> neighborEntry : current.neighbors.entrySet()) { |