-
Notifications
You must be signed in to change notification settings - Fork 5
/
Sissy.hpp
155 lines (145 loc) · 5.82 KB
/
Sissy.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
150
151
152
153
154
155
//(c) Michael J Sherwin 2020
//SISSY BOARDS - https://www.chessprogramming.org/SISSY_Bitboards
#include <stdint.h>
namespace Chess_Lookup::SISSY
{
uint64_t qss[64][256][8];
uint64_t bss[64][128][6];
uint64_t bob[64];
uint64_t b7e[64];
uint64_t rob[64];
constexpr auto Size = sizeof(qss) + sizeof(bss) + 3 * sizeof(bob);
void InitializeBSS() {
uint8_t sq, sqr, k, l;
int8_t x, dx, y, dy;
uint64_t b, bb, i, j, ii, jj;
for (sq = 0; sq < 64; sq++) {
y = sq >> 3;
x = sq & 7;
for (i = 0; i < 128; i++) {
for (k = 8, l = 0; k <= 48; k += 8, l++) {
bb = 0;
b = ((uint64_t)i << k) & bob[sq];
for (dx = +1, dy = +1; x + dx < +8 && y + dy < +8; dx++, dy++) {
sqr = (((y + dy) << 3) + x + dx);
bb |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dx = -1, dy = +1; x + dx > -1 && y + dy < +8; dx--, dy++) {
sqr = (((y + dy) << 3) + x + dx);
bb |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dx = +1, dy = -1; x + dx < +8 && y + dy > -1; dx++, dy--) {
sqr = (((y + dy) << 3) + x + dx);
bb |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dx = -1, dy = -1; x + dx > -1 && y + dy > -1; dx--, dy--) {
sqr = (((y + dy) << 3) + x + dx);
bb |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
bss[sq][i][l] = bb;
}
}
}
for (sq = 0; sq <= 63; sq++) {
for (ii = 0; ii <= 127; ii++) {
for (jj = 0; jj <= 127; jj++) {
i = ((ii << 8) & bob[sq]) >> 8;
j = ((jj << 32) & bob[sq]) >> 32;
bss[sq][i | j][0] = bss[sq][i][0] & bss[sq][j][3];
i = ((ii << 16) & bob[sq]) >> 16;
j = ((jj << 40) & bob[sq]) >> 40;
bss[sq][i | j][1] = bss[sq][i][1] & bss[sq][j][4];
i = ((ii << 24) & bob[sq]) >> 24;
j = ((jj << 48) & bob[sq]) >> 48;
bss[sq][i | j][2] = bss[sq][i][2] & bss[sq][j][5];
}
}
}
}
void InitializeQSS() {
uint8_t sq, sqr, k, l;
int8_t x, y, dx, dy;
int32_t i;
uint64_t b, bb;
for (sq = 0; sq < 64; sq++) {
y = sq >> 3;
x = sq & 7;
bob[sq] = 0;
rob[sq] = 0;
for (i = 0; i < 256; i++) {
for (k = 0, l = 0; k <= 56; k += 8, l++) {
bb = 0;
b = (uint64_t)i << k;
for (dx = +1, dy = +1; x + dx < +8 && y + dy < +8; dx++, dy++) {
sqr = (((y + dy) << 3) + x + dx);
bb |= 1ull << sqr;
bob[sq] |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dx = -1, dy = +1; x + dx > -1 && y + dy < +8; dx--, dy++) {
sqr = (((y + dy) << 3) + x + dx);
bb |= 1ull << sqr;
bob[sq] |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dx = +1, dy = -1; x + dx < +8 && y + dy > -1; dx++, dy--) {
sqr = (((y + dy) << 3) + x + dx);
bb |= 1ull << sqr;
bob[sq] |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dx = -1, dy = -1; x + dx > -1 && y + dy > -1; dx--, dy--) {
sqr = (((y + dy) << 3) + x + dx);
bb |= 1ull << sqr;
bob[sq] |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dx = -1; x + dx > -1; dx--) {
sqr = (y << 3) + x + dx;
bb |= 1ull << sqr;
rob[sq] |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dx = +1; x + dx < +8; dx++) {
sqr = (y << 3) + x + dx;
bb |= 1ull << sqr;
rob[sq] |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dy = +1; y + dy < +8; dy++) {
sqr = ((y + dy) << 3) + x;
bb |= 1ull << sqr;
rob[sq] |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
for (dy = -1; y + dy > -1; dy--) {
sqr = ((y + dy) << 3) + x;
bb |= 1ull << sqr;
rob[sq] |= 1ull << sqr;
if ((1ull << sqr) & b) break;
}
qss[sq][i][l] = bb;
}
}
b7e[sq] = bob[sq] & 0x007e7e7e7e7e7e00;
}
}
void Init() {
InitializeQSS();
InitializeBSS();
}
uint64_t Queen(int sq, uint64_t occ) {
return qss[sq][occ & 255][0]
& qss[sq][(occ >> 8) & 255][1]
& qss[sq][(occ >> 16) & 255][2]
& qss[sq][(occ >> 24) & 255][3]
& qss[sq][(occ >> 32) & 255][4]
& qss[sq][(occ >> 40) & 255][5]
& qss[sq][(occ >> 48) & 255][6]
& qss[sq][(occ >> 56) & 255][7];
}
}