-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.cpp
82 lines (67 loc) · 1.7 KB
/
output.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "output.h"
#include <iostream>
void Paint(Map &map, const PNode &curNode, const PNode &startNode)
{
std::vector<std::string> pic = RenderMap(map, curNode, startNode);
std::cout << " ";
for (int x = 0; x < map.Width(); ++x)
std::cout << x % 10;
std::cout << std::endl;
std::cout << std::string(map.Width()+2, '#') << std::endl;
int c = 0;
for (std::string &l : pic)
std::cout << '#' << l << "# " << c++ << std::endl;
std::cout << std::string(map.Width()+2, '#') << std::endl;
std::cout << " ";
for (int x = 0; x < map.Width(); ++x)
std::cout << x % 10;
std::cout << std::endl;
}
std::vector<std::string> RenderMap(Map &map, const PNode &node, const PNode &startNode)
{
std::vector<std::string> rv;
for (int y = 0; y < map.Height(); ++y) {
std::string line = "";
for (int x = 0; x < map.Width(); ++x) {
if (map.Passable(x, y))
line += " ";
else
line += "#";
}
rv.push_back(line);
}
PNode n = startNode;
NodeSet q;
do {
for (PNode c : n->Children()) {
q.insert(c);
}
n.reset();
if (!q.empty()) {
n = *q.begin();
q.erase(q.begin());
rv[map.Y(n->Offset())][map.X(n->Offset())] = '.';
}
} while (n);
n = node;
while (n) {
for (PNode c : n->Children()) {
if (rv[map.Y(c->Offset())][map.X(c->Offset())] != 'o') {
if (map.Y(n->Offset()) == map.Y(c->Offset()))
rv[map.Y(c->Offset())][map.X(c->Offset())] = '-';
else
rv[map.Y(c->Offset())][map.X(c->Offset())] = '|';
}
}
if (n->Parent()) {
rv[map.Y(n->Offset())][map.X(n->Offset())] = 'o';
n = n->Parent();
}
else {
rv[map.Y(n->Offset())][map.X(n->Offset())] = 'S';
break;
}
}
rv[map.Y(map.targetOffset_)][map.X(map.targetOffset_)] = 'T';
return rv;
}