blob: 7c7a85ec9aeef3db03380b0daeec2fa389173a72 (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "HalfMove.hpp"
namespace pgnp {
HalfMove::HalfMove() : count(-1), isBlack(false), MainLine(NULL) {}
HalfMove::~HalfMove() {
for (auto *move : variations) {
delete move;
}
}
std::string HalfMove::NestedDump(HalfMove *m, int indent) {
std::stringstream ss;
for (int i = 0; i < indent; i++) {
ss << " ";
}
ss << " "
<< " Move=" << m->move << " Count=" << m->count << " Comment=\""
<< m->comment << "\""
<< " IsBlack=" << m->isBlack << " Variations=" << m->variations.size()
<< std::endl;
for (auto *var : m->variations) {
ss << NestedDump(var, indent + 1);
}
if (m->MainLine != NULL) {
ss << NestedDump(m->MainLine, indent);
}
return (ss.str());
}
std::string HalfMove::Dump() { return (NestedDump(this, 0)); }
int HalfMove::GetLength() {
int length = 0;
HalfMove *m = this;
while (m != NULL) {
length++;
m = m->MainLine;
}
return length;
}
void HalfMove::Copy(HalfMove *copy) {
copy->count = count;
copy->isBlack = isBlack;
copy->move = move;
copy->comment = comment;
// Copy MainLine
if (MainLine != NULL) {
copy->MainLine = new HalfMove();
MainLine->Copy(copy->MainLine);
}
// Copy variation
for (HalfMove *var : variations) {
HalfMove *new_var = new HalfMove();
copy->variations.push_back(new_var);
var->Copy(new_var);
}
}
} // namespace pgnp
|