From faa82f0a6004026c94a6415baf5e138b48dc1629 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 24 Oct 2024 18:32:55 +0200 Subject: implement weird dijkstra --- BreadthFirstPathfinder.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'BreadthFirstPathfinder.cpp') diff --git a/BreadthFirstPathfinder.cpp b/BreadthFirstPathfinder.cpp index ef4492a..c204387 100644 --- a/BreadthFirstPathfinder.cpp +++ b/BreadthFirstPathfinder.cpp @@ -1,6 +1,5 @@ #include "BreadthFirstPathfinder.h" #include "Museum.h" -#include "NullTileBehavior.h" using namespace std; @@ -26,6 +25,7 @@ void BreadthFirstPathfinder::find_between(const XY & start, const XY & end) { vector BreadthFirstPathfinder::find_step(const vector & to_visit) { vector next_step = {}; + PathfindingContext & ctx = this->museum.pathfinding; for (Path trail : to_visit) { const XY & here = trail.front(); @@ -34,30 +34,20 @@ vector BreadthFirstPathfinder::find_step(const vec return {}; } - Tile & tile = this->museum.canvas.get_tile(here); - const XY offsets[] = { + vector offsets = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 }, }; - for (size_t i = 0; i < 4; i++) { - const XY offset = offsets[i]; - Tile * neighbor = tile.get_neighbor(offset); - - // if neighbor doesn't exist (out of bounds) - if (neighbor == nullptr) continue; - - // if neighbor is a blank tile - TileBehavior * behavior = neighbor->behavior.get(); - if (dynamic_cast(behavior) != nullptr) continue;; - - // if neighbor is already visited - if (this->is_visited(here + offset)) continue; - this->set_visited(here + offset); + for (const XY & offset : offsets) { + const XY neighbor = here + offset; + if (ctx.empty_point(neighbor)) continue; + if (this->is_visited(neighbor)) continue; + this->set_visited(neighbor); Path trail_copy = trail; - trail_copy.push_front(here + offset); + trail_copy.push_front(neighbor); next_step.push_back(trail_copy); } } -- cgit v1.2.3