Code: Select all

```
// King Hunter
// It is written for MSVC 2019 Community
#include <intrin.h>
#define s08 signed char;
#define u08 unsigned char
#define s32 int
#define u32 unsigned long
#define u64 unsigned long long
#define one 1ull
#define OOO 0
enum { BLACK, WHITE };
enum { OO, WP, WN, WB, WR, WQ, WC, WK, BP, BN, BB, BR, BQ, BC, BK };
enum { UNO, TWO, CEP };
struct threads {
s32 wtm;
u64 ebb;
u64 pieces[2];
u64 brdbb[64];
s32 board[64];
};
struct moves {
u08 fs;
u08 ts;
u08 ty;
u08 id;
s32 sc;
s32 st;
};
threads t[32];
s32 wptyp[] = { OOO, OOO, OOO, OOO, OOO, OOO, OOO, OOO,
TWO, TWO, TWO, TWO, TWO, TWO, TWO, TWO,
UNO, UNO, UNO, UNO, UNO, UNO, UNO, UNO,
UNO, UNO, UNO, UNO, UNO, UNO, UNO, UNO,
CEP, CEP, CEP, CEP, CEP, CEP, CEP, CEP,
UNO, UNO, UNO, UNO, UNO, UNO, UNO, UNO,
UNO, UNO, UNO, UNO, UNO, UNO, UNO, UNO };
s32 bptyp[] = { OOO, OOO, OOO, OOO, OOO, OOO, OOO, OOO,
UNO, UNO, UNO, UNO, UNO, UNO, UNO, UNO,
UNO, UNO, UNO, UNO, UNO, UNO, UNO, UNO,
CEP, CEP, CEP, CEP, CEP, CEP, CEP, CEP,
UNO, UNO, UNO, UNO, UNO, UNO, UNO, UNO,
UNO, UNO, UNO, UNO, UNO, UNO, UNO, UNO,
TWO, TWO, TWO, TWO, TWO, TWO, TWO, TWO };
u64 wpmoves[64];
u64 wpcapts[64];
u64 bpmoves[64];
u64 bpcapts[64];
u64 ktmoves[64];
u64 kgmoves[64];
u64 above[64];
u64 below[64];
u64 qss[64][256][8];
u64 bob[64];
u64 rob[64];
u64 wcastle(s32 ti) {
u64 bb;
return bb;
};
u64 bcastle(s32 ti) {
u64 bb;
return bb;
};
void GenMoves(s32 ti) {
u64 pieces, wpieces, bpieces, apieces, empty, notme;
u32 typ, fs, sq;
pieces = t[ti].pieces[t[ti].wtm];
wpieces = t[ti].pieces[WHITE];
bpieces = t[ti].pieces[BLACK];
apieces = wpieces | bpieces;
empty = 0xffffffffffffffff ^ apieces;
notme = 0xffffffffffffffff ^ pieces;
do {
_BitScanForward64(&fs, pieces);
pieces ^= one << fs;
typ = t[ti].board[fs];
switch (typ) {
case OO:
break;
case WP:
typ = wptyp[fs];
switch (typ) {
case UNO:
t[ti].brdbb[fs] = (wpmoves[fs] & empty)
| (wpcapts[fs] & bpieces);
break;
case TWO:
_BitScanForward64(&sq, (wpmoves[fs] & apieces));
t[ti].brdbb[fs] = (wpmoves[fs] & below[sq])
| (wpcapts[fs] & bpieces);
break;
case CEP:
t[ti].brdbb[fs] = (wpmoves[fs] & empty)
| (wpcapts[fs] & bpieces | t[ti].ebb);
break;
}
break;
case WN:
t[ti].brdbb[fs] = ktmoves[fs] & notme;
break;
case WB:
t[ti].brdbb[fs] = qss[fs][(apieces >> (fs & 56)) & 127][0]
& qss[fs][(apieces >> 8) & 255][1]
& qss[fs][(apieces >> 16) & 255][2]
& qss[fs][(apieces >> 24) & 255][3]
& qss[fs][(apieces >> 32) & 255][4]
& qss[fs][(apieces >> 40) & 255][5]
& qss[fs][(apieces >> 48) & 255][6]
& bob[fs]
& notme;
break;
case WR:
t[ti].brdbb[fs] = qss[fs][(apieces >> (fs & 56)) & 127][0]
& qss[fs][(apieces >> 8) & 255][1]
& qss[fs][(apieces >> 16) & 255][2]
& qss[fs][(apieces >> 24) & 255][3]
& qss[fs][(apieces >> 32) & 255][4]
& qss[fs][(apieces >> 40) & 255][5]
& qss[fs][(apieces >> 48) & 255][6]
& rob[fs]
& notme;
break;
case WQ:
t[ti].brdbb[fs] = qss[fs][(apieces >> (fs & 56)) & 127][0]
& qss[fs][(apieces >> 8) & 255][1]
& qss[fs][(apieces >> 16) & 255][2]
& qss[fs][(apieces >> 24) & 255][3]
& qss[fs][(apieces >> 32) & 255][4]
& qss[fs][(apieces >> 40) & 255][5]
& qss[fs][(apieces >> 48) & 255][6]
& notme;
break;
case WC:
t[ti].brdbb[fs] = (kgmoves[fs] & notme) | wcastle(ti);
break;
case WK:
t[ti].brdbb[fs] = (kgmoves[fs] & notme);
break;
case BP:
typ = bptyp[fs];
switch (typ) {
case UNO:
t[ti].brdbb[fs] = (bpmoves[fs] & empty)
| (bpcapts[fs] & bpieces);
break;
case TWO:
_BitScanForward64(&sq, (bpmoves[fs] & apieces));
t[ti].brdbb[fs] = (bpmoves[fs] & below[sq])
| (bpcapts[fs] & bpieces);
break;
case CEP:
t[ti].brdbb[fs] = (bpmoves[fs] & empty)
| (bpcapts[fs] & bpieces | t[ti].ebb);
break;
}
break;
case BN:
t[ti].brdbb[fs] = ktmoves[fs] & notme;
break;
case BB:
t[ti].brdbb[fs] = qss[fs][(apieces >> (fs & 56)) & 127][0]
& qss[fs][(apieces >> 8) & 255][1]
& qss[fs][(apieces >> 16) & 255][2]
& qss[fs][(apieces >> 24) & 255][3]
& qss[fs][(apieces >> 32) & 255][4]
& qss[fs][(apieces >> 40) & 255][5]
& qss[fs][(apieces >> 48) & 255][6]
& bob[fs]
& notme;
break;
case BR:
t[ti].brdbb[fs] = qss[fs][(apieces >> (fs & 56)) & 127][0]
& qss[fs][(apieces >> 8) & 255][1]
& qss[fs][(apieces >> 16) & 255][2]
& qss[fs][(apieces >> 24) & 255][3]
& qss[fs][(apieces >> 32) & 255][4]
& qss[fs][(apieces >> 40) & 255][5]
& qss[fs][(apieces >> 48) & 255][6]
& rob[fs]
& notme;
break;
case BQ:
t[ti].brdbb[fs] = qss[fs][(apieces >> (fs & 56)) & 127][0]
& qss[fs][(apieces >> 8) & 255][1]
& qss[fs][(apieces >> 16) & 255][2]
& qss[fs][(apieces >> 24) & 255][3]
& qss[fs][(apieces >> 32) & 255][4]
& qss[fs][(apieces >> 40) & 255][5]
& qss[fs][(apieces >> 48) & 255][6]
& notme;
break;
case BC:
t[ti].brdbb[fs] = (kgmoves[fs] & notme) | bcastle(ti);
break;
case BK:
t[ti].brdbb[fs] = (kgmoves[fs] & notme);
break;
}
} while (pieces);
}
void InitializeQSS() {
u08 sq, sqr, i;
u08 x, y, dx, dy;
u64 bb, b;
for (sq = 0; sq < 64; sq++) {
y = sq >> 3;
x = sq & 7;
for (i = 0; i < 128; i++) {
bb = 0;
b = (u64)i << (sq & 56);
for (dx = +1, dy = +1; x + dx < +8 && y + dy < +8; dx++, dy++) {
sqr = (((y + dy) << 3) + x + dx);
bb |= one << sqr;
bob[sq] |= one << sqr;
if ((one << sqr) & b) break;
}
for (dx = -1, dy = +1; x + dx > -1 && y + dy < +8; dx--, dy++) {
sqr = (((y + dy) << 3) + x + dx);
bb |= one << sqr;
bob[sq] |= one << sqr;
if ((one << sqr) & b) break;
}
for (dx = +1, dy = -1; x + dx < +8 && y + dy > -1; dx++, dy--) {
sqr = (((y + dy) << 3) + x + dx);
bb |= one << sqr;
bob[sq] |= one << sqr;
if ((one << sqr) & b) break;
}
for (dx = -1, dy = -1; x + dx > -1 && y + dy > -1; dx--, dy--) {
sqr = (((y + dy) << 3) + x + dx);
bb |= one << sqr;
bob[sq] |= one << sqr;
if ((one << sqr) & b) break;
}
for (dx = -1; x + dx > -1; dx--) {
sqr = (y << 3) + x + dx;
bb |= one << sqr;
rob[sq] |= one << sqr;
if ((one << sqr) & b) break;
}
for (dx = +1; x + dx < +8; dx++) {
sqr = (y << 3) + x + dx;
bb |= one << sqr;
rob[sq] |= one << sqr;
if ((one << sqr) & b) break;
}
for (dy = +1; y + dy < +8; dy++) {
sqr = ((y + dy) << 3) + x;
bb |= one << sqr;
rob[sq] |= one << sqr;
if ((one << sqr) & b) break;
}
for (dy = -1; y + dy > -1; dy--) {
sqr = ((y + dy) << 3) + x;
bb |= one << sqr;
rob[sq] |= one << sqr;
if ((one << sqr) & b) break;
}
qss[sq][i][0] = bb;
}
}
}
void Initialize() {
InitializeQSS();
}
s32 main() {
s32 ti = 0;
Initialize();
return 0;
}
```