-
Notifications
You must be signed in to change notification settings - Fork 16
/
TTable.cpp
64 lines (52 loc) · 1.55 KB
/
TTable.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
#include "config.h"
#include <vector>
#include "Utils.h"
#include "TTable.h"
TTable* TTable::get_TT(void) {
static TTable s_ttable;
return &s_ttable;
}
TTable::TTable(int size) {
LOCK(m_mutex, lock);
m_buckets.resize(size);
}
void TTable::update(uint64 hash, const float komi, const UCTNode * node) {
LOCK(m_mutex, lock);
unsigned int index = (unsigned int)hash;
index %= m_buckets.size();
/*
update TT
*/
m_buckets[index].m_hash = hash;
m_buckets[index].m_visits = node->get_visits();
m_buckets[index].m_blackwins = node->get_blackwins();
m_buckets[index].m_eval_sum = node->get_blackevals();
m_buckets[index].m_eval_count = node->get_evalcount();
if (m_komi != komi) {
std::fill(begin(m_buckets), end(m_buckets), TTEntry());
m_komi = komi;
}
}
void TTable::sync(uint64 hash, const float komi, UCTNode * node) {
LOCK(m_mutex, lock);
unsigned int index = (unsigned int)hash;
index %= m_buckets.size();
/*
check for hash fail
*/
if (m_buckets[index].m_hash != hash || m_komi != komi) {
return;
}
/*
valid entry in TT should have more info than tree
*/
if (m_buckets[index].m_visits > node->get_visits()) {
/*
entry in TT has more info (new node)
*/
node->set_visits(m_buckets[index].m_visits);
node->set_blackwins(m_buckets[index].m_blackwins);
node->set_blackevals(m_buckets[index].m_eval_sum);
node->set_evalcount(m_buckets[index].m_eval_count);
}
}