diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-25 13:02:38 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-25 13:02:38 +0200 |
commit | 8cf389aaf748c77aecda0b3a3773c45053b0f231 (patch) | |
tree | 91268879710d6ae2868e548d3f44c664a19443d8 /Pathfinder.cpp | |
parent | da669db4f083194bc78358041c5d9929e103ac9f (diff) |
implement all ALGA features
Diffstat (limited to 'Pathfinder.cpp')
-rw-r--r-- | Pathfinder.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/Pathfinder.cpp b/Pathfinder.cpp index deb6040..4cf5e76 100644 --- a/Pathfinder.cpp +++ b/Pathfinder.cpp @@ -8,19 +8,46 @@ using namespace std; Pathfinder::Pathfinder(Museum & m) : museum(m) { } +size_t Pathfinder::pos_to_idx(const XY & point) { + return point.y * this->museum.canvas.data.columns + point.x; +} + void Pathfinder::set_visited(const XY & point) { - this->visisted[point.y * this->museum.canvas.data.columns + point.x] = true; + this->visisted[this->pos_to_idx(point)] = true; } bool Pathfinder::is_visited(const XY & point) { - size_t idx = point.y * this->museum.canvas.data.columns + point.x; + size_t idx = this->pos_to_idx(point); if (idx >= this->visisted.size()) return false; return this->visisted[idx]; } +bool Pathfinder::is_solution(const XY & point) { + size_t idx = this->pos_to_idx(point); + if (idx >= this->solution.size()) return false; + return this->solution[idx]; +} + void Pathfinder::clear() { + this->solution.clear(); + this->solved = false; + CanvasData & canvas = this->museum.canvas.data; this->visisted.resize(canvas.columns * canvas.rows); fill(this->visisted.begin(), this->visisted.end(), false); } +void Pathfinder::set_solved(const Path & solution) { + this->path = solution; + this->solved = true; + + CanvasData & canvas = this->museum.canvas.data; + this->solution.resize(canvas.columns * canvas.rows); + fill(this->solution.begin(), this->solution.end(), false); + for (const XY & point : solution) { + this->solution[this->pos_to_idx(point)] = true; + } + + this->museum.people.update(false); +} + |