-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtt.hpp
149 lines (131 loc) · 2.81 KB
/
tt.hpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef __tt_hpp
#define __tt_hpp
#include <vector>
#include "bitboard.hpp"
#include "move.hpp"
//#include "show.hpp"
namespace BestMoveType
{
enum EBestMoveType
{
exact,
alpha,
beta,
none
};
}
namespace TTProveReturnType
{
enum ETTProveReturnType
{
value,
best_move,
miss,
none
};
}
struct TT_E
{
TT_E():zob(0), best_mv(), eval(0), depth(0), best_mv_type(unsigned char(BestMoveType::none)){}
ui64 zob;
move_packed best_mv;
short eval;
unsigned char depth;
unsigned char best_mv_type;
};
struct TT_Entry
{
move best_mv;
ui64 zob;
int eval;
int depth;
BestMoveType::EBestMoveType best_mv_type;
};
//struct TT_Big_Entry
//{
// ui64 zob;
// move_packed best_mv;
// //unsigned stuff;
// //unsigned char best_mv_type;
// //unsigned char depth;
// char eval[4];
// //char c[4];
//};
struct TT
{
void Clear()
{
data.clear();
data.resize(size);
}
void CreateTable( size_t kb )
{
size_t bytes = kb*1024;
size = bytes/sizeof(TT_E);
Clear();
}
void RecordHash(int depth, int val, BestMoveType::EBestMoveType type, Bitboard& b)
{
//Show<ShowTypes::Console>::Op(val);
//Show<ShowTypes::Console>::Op("rec");
size_t sz = b.moves.size();
ui64 zob;
if(sz!=0)
{
zob = b.zobrists[b.zobrists.size()-2];
}
else
{
zob = b.zobrists[0];
}
TT_E& tt_entry = data[zob%size];
if(sz!=0)
{
tt_entry.best_mv = /*move_packed*/(b.moves.back());
}
tt_entry.best_mv_type = (type);
tt_entry.eval = val;
tt_entry.depth = (depth);
tt_entry.zob = zob;
}
TTProveReturnType::ETTProveReturnType ProbeHash(int depth, int alpha, int beta, Bitboard& b, int& val, move& mv)
{
const ui64& zob = b.zobrists.back();
TT_E& tt_entry = data[zob%size];
if(tt_entry.zob == zob)
{
if((int)(tt_entry.depth) >= depth)
{
switch(tt_entry.best_mv_type)
{
case BestMoveType::beta:
if(tt_entry.eval >= beta)
{
val = (int)(tt_entry.eval);
return TTProveReturnType::value;
}
break;
case BestMoveType::alpha:
if(tt_entry.eval <= alpha)
{
val = (int)(tt_entry.eval);
return TTProveReturnType::value;
}
break;
case BestMoveType::exact:
{
val = (int)(tt_entry.eval);
return TTProveReturnType::value;
}
break;
}
}
mv = MoveFromMovePacked(tt_entry.best_mv);
return TTProveReturnType::best_move;
}
return TTProveReturnType::miss;
}
std::vector<TT_E> data;
size_t size;
};
#endif