-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransposition.cpp
More file actions
53 lines (39 loc) · 1.57 KB
/
Copy pathtransposition.cpp
File metadata and controls
53 lines (39 loc) · 1.57 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
#include "transposition.h"
#include "board.h"
void Transposition::Clear()
{
this->position_key = 0;
this->depth_searched_beyond = 0;
this->score = SCORE_EMPTY;
this->hash_flag = HASH_FLAG_EMPTY;
}
Transposition::Transposition() : position_key(0), depth_searched_beyond(0), score(SCORE_EMPTY), hash_flag(HASH_FLAG_EMPTY)
{
}
Transposition::Transposition(U64 new_position_key, int new_depth_searched_beyond, int new_score, int new_hash_flag) :
position_key(new_position_key), depth_searched_beyond(new_depth_searched_beyond), score(new_score), hash_flag(new_hash_flag)
{
}
int Transposition::ProbeHashScore(const Transposition* tt, size_t tt_size, U64 position_key, int depth_searched_beyond, int alpha, int beta, int side_to_move)
{
//works for power of 2
size_t index = position_key & (tt_size - 1);
const Transposition& entry = tt[index];
if (entry.position_key == position_key && entry.depth_searched_beyond >= depth_searched_beyond)
{
int cached_score = (side_to_move == WHITE ? entry.score : -entry.score);
if (entry.hash_flag == HASH_FLAG_EXACT) return cached_score;
else if (entry.hash_flag == HASH_FLAG_ALPHA && cached_score <= alpha) return alpha;
else if (entry.hash_flag == HASH_FLAG_BETA && cached_score >= beta) return beta;
}
return SCORE_EMPTY;
}
void Transposition::RecordHash(Transposition* tt, size_t tt_size, const Transposition& t, int side_to_move)
{
size_t index = t.position_key & (tt_size - 1);
if (t.depth_searched_beyond >= tt[index].depth_searched_beyond)
{
tt[index] = t;
if (side_to_move == BLACK) tt[index].score = -tt[index].score;
}
}