-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pawntable.cpp
55 lines (43 loc) · 1.22 KB
/
pawntable.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
#include "pawntable.h"
#include "utils.h"
namespace Napoleon
{
PawnTable::PawnTable()
{
entries = ((64*std::pow(2, 20)) / sizeof(PawnEntry)); // number of bytes * size of HashEntry = number of entries
entries = std::pow(2, Utils::Math::Log2(entries));
lock_entries = entries;
free(table);
free(locks);
table = (PawnEntry*) std::calloc(entries * sizeof(PawnEntry), 1);
locks = new SpinLock[lock_entries];
mask = entries - 1;
}
PawnEntry* PawnTable::at(ZobristKey key) const
{
return table + (key & mask);
}
void PawnTable::Save(ZobristKey key, Score score)
{
SpinLock* mux = locks + (key & mask);
if (Concurrent)
mux->lock();
auto hash = at(key);
hash->key = key;
hash->score = score;
mux->unlock();
}
Score PawnTable::Probe(ZobristKey key)
{
SpinLock* mux = locks + (key & mask);
if (Concurrent)
mux->lock();
auto hash = at(key);
if (hash->key == key)
{
return hash->score;
}
mux->unlock();
return Score(TranspositionTable::Unknown, TranspositionTable::Unknown);
}
}