From 8cf389aaf748c77aecda0b3a3773c45053b0f231 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 25 Oct 2024 13:02:38 +0200 Subject: implement all ALGA features --- Pathfinder.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'Pathfinder.cpp') 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); +} + -- cgit v1.2.3