#1: The SquareMask array, (1ULL << sq)
Code: Select all
#define A(s) (1ULL << (s)), (1ULL << (s+1)), (1ULL << (s+2)), (1ULL << (s+3))
#define S(s) A(s), A(s+4), A(s+8), A(s+12)
// SquareMask[64] stores the Bitboard square masks. It's only a faster
// alternative to 1ULL << square
const Bitboard SquareMask[Square::SQ_NB] = {
S(0), S(16), S(32), S(48)
};
#undef A
#undef S
Code: Select all
#define F(f) ((FileAMask << ((f) - 1)) | (FileAMask << ((f) + 1)))
// AdjacentFileMask[8] stores the masks of the adjacent files of the index
const Bitboard AdjacentFilesMask[Square::FILE_NB] = {
FileBMask, F(1), F(2), F(3), F(4), F(5), F(6), FileGMask
};
Code: Select all
#define X(s) ((1ULL << ((s) * 8)) - 1)
#define A(s) (X((s)>>3) & (FileAMask << ((s)&7)))
#define B(s) A(s), A(s+1), A(s+2), A(s+3)
#define S(s) B(s), B(s+4), B(s+8), B(s+12)
const Bitboard ForwardBlackMask[Square::SQ_NB] = {
S(0), S(16), S(32), S(48)
};
#undef A
#define A(s) ((~X(((s)>>3)+1)) & (FileAMask << ((s)&7)))
const Bitboard ForwardWhiteMask[Square::SQ_NB] = {
S(0), S(16), S(32), B(48), B(52)
};
#undef A
Code: Select all
// Not my code, see https://graphics.stanford.edu/~seander/bithacks.html
// This array stores the number of bits set in an integer from 0 to 255.
const uint8_t BitCountTable[] = {
#define B2(n) n, n+1, n+1, n+2
#define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
#define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2)
B6(0), B6(0+1), B6(0+1), B6(0+2)
};
Code: Select all
// Max(x, y)
#define M(x, y) (((x) > (y)) ? (x) : (y))
// A(x, y) returns the distance between files and ranks
#define A(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
#define F(x, y) (A((x&7), (y&7)))
#define R(x, y) A((x>>3), (y>>3))
// D(x, y) returns the distance between two squares
#define D(x, y) M(F(x, y), R(x, y))
#define X(x, y) D(x, y), D(x, y+1), D(x, y+2), D(x, y+3)
#define X1(x, y) X(x, y), X(x, y+4), X(x, y+8), X(x, y+12)
#define X2(x) { X1(x, 0), X1(x, 16), X1(x, 32), X1(x, 48) }
#define X3(x) X2(x), X2(x+1), X2(x+2), X2(x+3)
#define X4(x) X3(x), X3(x+4), X3(x+8), X3(x+12)
const unsigned Distance[SQ_NB][SQ_NB] = {
X4(0), X4(16), X4(32), X4(48)
};
#undef M
#undef A
#undef F
#undef R
#undef D
#undef X
#undef X1
#undef X2
#undef X3
#undef X4
Also, I'll keep this forum updated whenever I find more ways to initialize more arrays at compile time.