-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.c
More file actions
188 lines (151 loc) · 4.04 KB
/
init.c
File metadata and controls
188 lines (151 loc) · 4.04 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "init.h"
#include "movegen.h"
int sq120tosq64[BRD_SQ_NUM];
int sq64tosq120[64];
uint64_t setMask[64];
uint64_t clearMask[64];
uint64_t pieceKeys[13][120];
uint64_t sideKey;
uint64_t castleKeys[16];
int filesBrd[BRD_SQ_NUM];
int ranksBrd[BRD_SQ_NUM];
uint64_t fileBBMask[8];
uint64_t rankBBMask[8];
uint64_t blackPassedMask[64];
uint64_t whitePassedMask[64];
uint64_t isolatedMask[64];
static void initEvalMasks() {
int sq, tsq, r, f;
for(sq = 0; sq < 8; ++sq) {
fileBBMask[sq] = 0ULL;
rankBBMask[sq] = 0ULL;
}
for(r = RANK_8; r >= RANK_1; r--) {
for (f = FILE_A; f <= FILE_H; f++) {
sq = r * 8 + f;
fileBBMask[f] |= (1ULL << sq);
rankBBMask[r] |= (1ULL << sq);
}
}
for(sq = 0; sq < 64; ++sq) {
isolatedMask[sq] = 0ULL;
whitePassedMask[sq] = 0ULL;
blackPassedMask[sq] = 0ULL;
}
for(sq = 0; sq < 64; ++sq) {
tsq = sq + 8;
while(tsq < 64) {
whitePassedMask[sq] |= (1ULL << tsq);
tsq += 8;
}
tsq = sq - 8;
while(tsq >= 0) {
blackPassedMask[sq] |= (1ULL << tsq);
tsq -= 8;
}
if(filesBrd[SQ120(sq)] > FILE_A) {
isolatedMask[sq] |= fileBBMask[filesBrd[SQ120(sq)] - 1];
tsq = sq + 7;
while(tsq < 64) {
whitePassedMask[sq] |= (1ULL << tsq);
tsq += 8;
}
tsq = sq - 9;
while(tsq >= 0) {
blackPassedMask[sq] |= (1ULL << tsq);
tsq -= 8;
}
}
if(filesBrd[SQ120(sq)] < FILE_H) {
isolatedMask[sq] |= fileBBMask[filesBrd[SQ120(sq)] + 1];
tsq = sq + 9;
while(tsq < 64) {
whitePassedMask[sq] |= (1ULL << tsq);
tsq += 8;
}
tsq = sq - 7;
while(tsq >= 0) {
blackPassedMask[sq] |= (1ULL << tsq);
tsq -= 8;
}
}
}
}
static void initFilesRanksBrd() {
int index = 0;
int file = FILE_A;
int rank = RANK_1;
int sq = A1;
for(index = 0; index < BRD_SQ_NUM; index++) {
filesBrd[index] = OFFBOARD;
ranksBrd[index] = OFFBOARD;
}
for(rank = RANK_1; rank <= RANK_8; rank++) {
for(file = FILE_A; file <= FILE_H; file++) {
sq = FR2SQ(file,rank);
filesBrd[sq] = file;
ranksBrd[sq] = rank;
}
}
}
static uint64_t rand64() {
// http://vigna.di.unimi.it/ftp/papers/xorshift.pdf
static uint64_t seed = 1070372ull;
seed ^= seed >> 12;
seed ^= seed << 25;
seed ^= seed >> 27;
return seed * 2685821657736338717ull;
}
static void initHashKeys() {
int index = 0;
int index2 = 0;
for(index = 0; index < 13; index++) {
for(index2 = 0; index2 < 120; index2++) {
pieceKeys[index][index2] = rand64();
}
}
sideKey = rand64();
for(index = 0; index < 16; index++) {
castleKeys[index] = rand64();
}
}
static void initBitMasks() {
int index = 0;
for(index = 0; index < 64; index++) {
setMask[index] = 0ULL;
clearMask[index] = 0ULL;
}
for(index = 0; index < 64; index++) {
setMask[index] |= (1ULL << index);
clearMask[index] = ~setMask[index];
}
}
static void initSq120toSq64() {
int index = 0;
int file = FILE_A;
int rank = RANK_1;
int sq = A1;
int sq64 = 0;
for(index = 0; index < BRD_SQ_NUM; index++) {
sq120tosq64[index] = 65;
}
for(index = 0; index < 64; index++) {
sq64tosq120[index] = 120;
}
for(rank = RANK_1; rank <= RANK_8; rank++) {
for(file = FILE_A; file <= FILE_H; file++) {
sq = FR2SQ(file,rank);
sq64tosq120[sq64] = sq;
sq120tosq64[sq] = sq64;
sq64++;
}
}
}
void init() {
initSq120toSq64();
initBitMasks();
initHashKeys();
initFilesRanksBrd();
initEvalMasks();
initMvvLva();
}