-
Notifications
You must be signed in to change notification settings - Fork 1
/
pvtable.c
75 lines (51 loc) · 1.75 KB
/
pvtable.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
#include <stdio.h>
#include "defs.h"
int GetPvLine(const int depth, S_BOARD *pos) {
ASSERT(depth < MAXDEPTH);
int move = ProbePvTable(pos);
int count = 0;
while(move != NOMOVE && count < depth) {
ASSERT(count < MAXDEPTH);
if( MoveExists(pos, move) ) {
MakeMove(pos, move);
pos->PvArray[count++] = move;
} else {
break;
}
move = ProbePvTable(pos);
}
while(pos->ply > 0) {
TakeMove(pos);
}
return count;
}
const int PvSize = 0x100000 * 2;
void ClearPvTable(S_PVTABLE *table) {
S_PVENTRY *pvEntry;
for (pvEntry = table->pTable; pvEntry < table->pTable + table->numEntries; pvEntry++) {
pvEntry->posKey = 0ULL;
pvEntry->move = NOMOVE;
}
}
void InitPvTable(S_PVTABLE *table) {
table->numEntries = PvSize / sizeof(S_PVENTRY);
table->numEntries -= 2;
free(table->pTable);
table->pTable = (S_PVENTRY *) malloc(table->numEntries * sizeof(S_PVENTRY));
ClearPvTable(table);
printf("PvTable init complete with %d entries\n",table->numEntries);
}
void StorePvMove(const S_BOARD *pos, const int move) {
int index = pos->posKey % pos->PvTable->numEntries;
ASSERT(index >= 0 && index <= pos->PvTable->numEntries - 1);
pos->PvTable->pTable[index].move = move;
pos->PvTable->pTable[index].posKey = pos->posKey;
}
int ProbePvTable(const S_BOARD *pos) {
int index = pos->posKey % pos->PvTable->numEntries;
ASSERT(index >= 0 && index <= pos->PvTable->numEntries - 1);
if( pos->PvTable->pTable[index].posKey == pos->posKey ) {
return pos->PvTable->pTable[index].move;
}
return NOMOVE;
}