aboutsummaryrefslogtreecommitdiff
path: root/Pathfinder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Pathfinder.cpp')
-rw-r--r--Pathfinder.cpp31
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);
+}
+