-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoot.cpp
78 lines (62 loc) · 1.28 KB
/
Root.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
#include <iostream>
#include <algorithm>
#include "Root.h"
Root::Root() {
probability = 0;
}
Root::~Root() {
for (auto &child : children) {
delete child;
}
}
Node* Root::getChild(unsigned short key) {
for (auto &child : children) {
if (child->getTeam() == key) {
return child;
}
}
return nullptr;
}
void Root::addChild(unsigned short key, double probability) {
for (auto &child : children) {
if (child->getTeam() == key) {
return;
}
}
children.push_back(new Node(key, probability));
}
void Root::log() {
std::sort(
children.begin(),
children.end(),
compareNodePointers
);
std::cout.precision(4);
for (auto &child : children) {
std::cout << "Rank 1: "
<< child->getTeam()
<< " @ "
<< child->getProbability() * 100
<< "%" << std::endl;
child->log(1, child->getProbability());
}
}
void Root::logMonteCarlo() {
std::sort(
children.begin(),
children.end(),
compareNodePointers
);
std::cout.precision(4);
for (auto &child : children) {
std::cout << "Rank 1: "
<< child->getTeam()
<< " @ "
<< child->getProbability() * 100 / this->probability
<< "%" << std::endl;
child->log(1, child->getProbability());
}
}
void Root::updateProbability(double probability) {
this->probability += probability;
}