I'm currently coding a chess engine in C++, and have run into a bit of trouble with my magic bitboard implementation.
So far, I have a function that calculates blockerBoards (all the possible pieces that can block the rook or the bishop).
From there, I have the following code to take these blockerBoards and convert them into attack tables:
bitset<M> mBishopAttacks[64][512]; // 256 K
bitset<M> mRookAttacks[64][4096]; // 2048K
bitset<M> bishopAttacks(bitset<M> blockerBoard, int sq) {
unsigned long long index = blockerBoard.to_ullong();
index *= bishopMagics[sq];
index >>= 64-9
return mBishopAttacks[sq][index]; //outputs corresponding attack board
}
Note that I got the array of magic numbers, bishopMagics[64], from somewhere on the web.
How do I initialize these attack tables, mBishopAttacks and mRookAttacks? Currently, they are empty. Do I simply have to calculate the attack tables for each possible permutation of blockers?