blob: 4cf5e7666da8ceb7e4ee3ed0564fde502e3ff820 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include <algorithm>
#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);
}
|