-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZobristHash.cpp
72 lines (59 loc) · 1.4 KB
/
ZobristHash.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
#include "ZobristHash.h"
ZobristHash::ZobristHash()
{
entries.resize(static_cast<size_t>(1e6));
hashSize = static_cast<size_t>(1e6);
}
ZobristHash::ZobristHash(size_t _hashSize)
{
entries.resize(_hashSize);
hashSize = _hashSize;
}
ZobristHash::entry& ZobristHash::getEntry(const U64& key)
{
//cout << hex << key % hashSize << dec << endl;
return entries[key % hashSize];
}
int ZobristHash::getValue(const U64& key) const
{
return entries[key % hashSize].value;
}
bool ZobristHash::isRepetition(const U64& key, int depth) const
{
// Stored node was found again at greater depth => Repetition
auto& entry = entries[key % hashSize];
return entry.search_depth != -1 && entry.search_depth <= depth;
}
void ZobristHash::clear()
{
for (auto& entry : entries) {
// Invalidate entry:
entry = ZobristHash::entry();
}
}
ZobristHash::entry::entry() : value(-oo), search_depth(-1), flags(0x0), terminal(0), d(0) {}
// Class PVTable
PVTable::PVTable()
{
pventries.resize(static_cast<size_t>(3e6));
hashSize = static_cast<size_t>(3e6);
}
PVTable::PVTable(size_t size)
{
pventries.resize(size);
hashSize = size;
}
void PVTable::addPVMove(const U64& key, const Move& move)
{
auto index = key % hashSize;
pventries[index].bestmove = move;
}
PVTable::PVEntry& PVTable::operator[](const U64& key)
{
return pventries[key % hashSize];
}
void PVTable::clear()
{
for (auto& entry : pventries)
entry.bestmove = Move();
}