-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtt.cc
More file actions
73 lines (63 loc) · 1.97 KB
/
tt.cc
File metadata and controls
73 lines (63 loc) · 1.97 KB
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
// Copyright (C) 2016 Tetsui Ohkubo.
#include "./tt.h"
#include <gflags/gflags.h>
DEFINE_int32(tt_size_lg,
23,
"Logarithmic transposition table size. "
"2^tt_size_lg * sizeof(one tt cluster) will be allocated.");
TranspositionTable::TranspositionTable()
: mask_((1 << FLAGS_tt_size_lg) - 1)
, table_(nullptr)
, generation_(0)
, mutex_() {
table_ = new TranspositionTable::Cluster[1 << FLAGS_tt_size_lg];
}
TranspositionTable::~TranspositionTable() {
delete table_;
}
bool TranspositionTable::Probe(PositionHash key,
TranspositionTable::Entry *entry) const {
const Cluster& cluster = table_[key & mask_];
for (int i = 0; i < kClusterSize; ++i) {
// std::lock_guard<std::mutex> lock(mutex_);
if (cluster.entries[i].bound != BOUND_NONE &&
cluster.entries[i].key == key) {
*entry = cluster.entries[i];
return true;
}
}
return false;
}
void TranspositionTable::Store(PositionHash key, Move best_move,
int score, int depth, Bound bound) {
Cluster& cluster = table_[key & mask_];
Entry *entry = nullptr;
for (int i = 0; i < kClusterSize; ++i) {
if (cluster.entries[i].key == key ||
cluster.entries[i].bound == BOUND_NONE) {
entry = &cluster.entries[i];
break;
}
}
if (entry == nullptr) {
entry = &cluster.entries[0];
for (int i = 0; i < kClusterSize; ++i) {
if (cluster.entries[i].depth < entry->depth) {
entry = &cluster.entries[i];
} else if (cluster.entries[i].depth == entry->depth) {
if (cluster.entries[i].generation < entry->generation) {
entry = &cluster.entries[i];
}
}
}
}
assert(entry != nullptr);
assert(bound != BOUND_NONE);
// std::lock_guard<std::mutex> lock(mutex_);
entry->generation = generation_;
entry->key = key;
entry->best_move = best_move;
entry->score = score;
entry->depth = depth;
entry->bound = bound;
}