diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-24 18:32:55 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-24 18:32:55 +0200 |
commit | faa82f0a6004026c94a6415baf5e138b48dc1629 (patch) | |
tree | ead573bf9ec72a74569b79724c732c17dd9d0fb3 /BreadthFirstPathfinder.cpp | |
parent | afc66d3013b7d47c6c22d6a99809bc3e7d1ff0dc (diff) |
implement weird dijkstra
Diffstat (limited to 'BreadthFirstPathfinder.cpp')
-rw-r--r-- | BreadthFirstPathfinder.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
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::Path> BreadthFirstPathfinder::find_step(const vector<Path> & to_visit) { vector<Path> next_step = {}; + PathfindingContext & ctx = this->museum.pathfinding; for (Path trail : to_visit) { const XY & here = trail.front(); @@ -34,30 +34,20 @@ vector<BreadthFirstPathfinder::Path> BreadthFirstPathfinder::find_step(const vec return {}; } - Tile & tile = this->museum.canvas.get_tile(here); - const XY offsets[] = { + vector<XY> 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<NullTileBehavior *>(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); } } |