aboutsummaryrefslogtreecommitdiff
path: root/DijkstraPathfinder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'DijkstraPathfinder.cpp')
-rw-r--r--DijkstraPathfinder.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/DijkstraPathfinder.cpp b/DijkstraPathfinder.cpp
index 8d86235..8a8e8eb 100644
--- a/DijkstraPathfinder.cpp
+++ b/DijkstraPathfinder.cpp
@@ -23,14 +23,19 @@ void DijkstraPathfinder::find_between(const XY & start, const XY & end) {
this->map_get(start).distance = 0;
this->dijkstra(start);
- // no solution
- if (!this->is_visited(end)) return;
+ if (!this->is_visited(end)) {
+ printf("Dijkstra: no solution found\n");
+ return;
+ }
XY pos = end;
+ int steps = 0;
while (pos != start) {
solution.push_front(pos);
- pos = this->map[pos].parent;
+ pos = this->map_get(pos).parent;
+ steps++;
}
+ printf("Dijkstra: solution found (%d steps, %u time)\n", steps, this->map_get(end).distance);
}
DijkstraPathfinder::Node & DijkstraPathfinder::map_get(const XY & pos) {