#include #include "Pathfinder.h" #include "Museum.h" 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[this->pos_to_idx(point)] = true; } bool Pathfinder::is_visited(const XY & point) { 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); }