-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.c
228 lines (98 loc) · 2.04 KB
/
hash.c
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
#include <stdlib.h>
#include <string.h>
#include "bce.h"
int tablehits[3];
move_and_score killers[PV_LENGTH][2];
void compute_randoms()
{
int i,j;
for (i=0;i<=BKING;i++)
for (j=0;j<64;j++)
{
#ifdef HASH_64
randoms[i][j] = ((hashtype) getrandomnumber() << 32) | getrandomnumber();
#else
randoms[i][j] = getrandomnumber();
#endif
}
}
void compute_hash()
{
int x;
board->hash = 0;
for (x=0;x<64;x++)
{
chesspiece p;
if ((p=getpiece__(x)))
{
board->hash ^= randoms[p][x];
}
}
board->hash ^= tomove();
}
void clear_hash()
{
memset(tables, 0, sizeof(tables));
}
void store_hash(int depth, int flag, int score, move m)
{
ttable *tt = tables + hash_index(board->hash);
if (depth < tt->depth)
return;
tt->hash = board->hash;
tt->depth = depth;
tt->score = score;
tt->flag = flag;
tt->m = m;
}
int retrieve_hash(int depth, int *score, move *m)
{
ttable *tt = tables + hash_index(board->hash);
if (tt->hash == board->hash)
{
if (tt->score<LOSE+100)
{
*score = tt->score + (ply - search_info.startply) + tt->depth;
}
else if (tt->score>WIN-100)
{
*score = tt->score - (ply - search_info.startply) - tt->depth;
}
else
{
*score = tt->score;
}
*m = tt->m;
if (tt->depth > depth)
{
tablehits[0] ++;
return tt->flag;
}
else if (tt->depth == depth)
{
tablehits[1] ++;
return tt->flag;
}
else
{
tablehits[2] ++;
return LOWER_DEPTH;
}
}
return NO_HIT;
}
void store_killer(move m, int p, int a, int b)
{
if (a>killers[p][0].score)
{
killers[p][1].m = killers[p][0].score;
killers[p][1].score = killers[p][0].score;
killers[p][0].m = m;
killers[p][0].score = a;
}
else if (a>killers[p][1].score)
{
killers[p][1].m = m;
killers[p][1].score = a;
}
}