-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtt.cpp
More file actions
62 lines (53 loc) · 1.43 KB
/
tt.cpp
File metadata and controls
62 lines (53 loc) · 1.43 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
#include "tt.h"
constexpr size_t TT_SIZE = 1 << 20;
static TTEntry ttTable[TT_SIZE];
inline size_t ttIndex(uint64_t key)
{
return key & (TT_SIZE - 1);
}
void storeTT(uint64_t key, int depth, int score, TTFlag flag, const uint16_t& bestMove)
{
size_t index = ttIndex(key);
TTEntry& entry = ttTable[index];
if (entry.key == 0 || depth >= entry.depth)
{
entry.key = key;
entry.depth = depth;
entry.score = score;
entry.flag = flag;
entry.bestmove = bestMove;
}
}
bool probeTT(uint64_t key, int depth, int alpha, int beta, int& score, uint16_t& bestMove)
{
size_t index = ttIndex(key);
TTEntry& entry = ttTable[index];
if (entry.key == key)
{
bestMove = entry.bestmove;
if (entry.depth >= depth)
{
switch (entry.flag)
{
case EXACT:
score = entry.score;
return true;
case LOWERBOUND:
if (entry.score >= beta)
{
score = entry.score;
return true;
}
break;
case UPPERBOUND:
if (entry.score <= alpha)
{
score = entry.score;
return true;
}
break;
}
}
}
return false;
}