I am having some difficulty with magic bitboards, in that multiple blocker bitboards which would result in different attack boards having the same index. I realize this is likely because of one of the following reasons:
The magics I am using are incorrect.
I am generating indexes incorrectly.
I am generating attack masks incorrectly.
I have tested my code relating to problems 2), and 3), finding it to be correct, as well as trying different sets of magics, however this has not worked. I would greatly appreciate any help. I have attached the relevant code (C++17), or refer to a set of working magics.
// to generate the attack sets
for (int i = 0; i < 64; i++){
int n = count1s(rookMasks[i]);
for (int j = 0; j < 1 << n; j++){
ull bb = int2blocker(j, rookMasks[i]);
int ind = index(bb,rookMagics[i],rookShift[i]);
ull attack = rookMask(i,1,bb);
blockedRookMasks[i][ind] = attack;
}
n = count1s(bishopMasks[i]);
for (int j = 0; j < n; j++){
ull bb = int2blocker(j, bishopMasks[i]);
int ind = index(bb,bishopMagics[i],bishopShift[i]);
ull attack = bishopMask(i,1,bb);
blockedBishopMasks[i][ind] = attack;
}
}
The magics and shifts I am using come from here https://github.com/goutham/magic-bits/blob/master/include/magic_bits.hpp (lines 108-191)