-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
107 lines (87 loc) · 1.98 KB
/
init.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
#include "defs.h"
#include "stdio.h"
#include "stdlib.h"
#define RAND_64 ((U64)rand() | \
(U64)rand() << 15 | \
(U64)rand() << 30 | \
(U64)rand() << 45 | \
((U64)rand() & 0xf) << 60 )
int Sq120ToSq64[BRD_SQ_NUM];
int Sq64ToSq120[64];
U64 SetMask[64];
U64 ClearMask[64];
U64 PieceKeys[13][120];
U64 SideKey;
U64 CastleKeys[16];
int FilesBrd[BRD_SQ_NUM];
int RanksBrd[BRD_SQ_NUM];
void InitFilesRanksBrd() {
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) {
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;
}
}
}
void InitHashKeys() {
int index = 0;
int index2 = 0;
for(index = 0; index < 13; ++index) {
for(index2 = 0; index2 < 120; ++index2) {
PieceKeys[index][index2] = RAND_64;
}
}
SideKey = RAND_64;
for(index = 0; index < 16; ++index) {
CastleKeys[index] = RAND_64;
}
}
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];
}
}
void InitSq120To64() {
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 AllInit() {
InitSq120To64();
InitBitMasks();
InitHashKeys();
InitFilesRanksBrd();
InitMvvLva();
}