I am modifying my chess engine to use a bitboard based approach to board representation instead of the current mailbox approach.
I've read much about using magic bitboards to retrieve bitboards of legal moves.
The approach is summed up in this Chess SE post (Understanding magic bitboard) with the following pseudocode
bbBlockers = bbAllPieces & occupancyMaskRook[C3]
databaseIndex = (int)((bbBlockers * magicNumberRook[C3]) >> rookMagicShifts[C3])
bbMoveSquares = magicMovesRook[C3][databaseIndex] & ~bbFriendlyPieces
I am comfortable with how this works. However, I am not sure why we bother with the magic numbers. Essentially, multiplying the blocker bitboard by the magic number for a given square gives us a key which we then use to look up the moves bitboard.
Why can't we just use the integer value of the blockers bitboard as the key instead since it is just a 64 bit value?
Going back to the pseudo-code above it would be as follows:
bbBlockers = bbAllPieces & occupancyMaskRook[C3]
bbMoveSquares = rookMoves[C3][bbBlockers] & ~bbFriendlyPieces
Which indicates that removing magic numbers would reduce the number of operations needed.
Also, looking at the numbers involved for rooks we have 64 possible squares and a maximum of 4096 (212) which gives us 262,144 dictionary entries. Each entry is 16 bytes (8 for the key and 8 for the payload) so we only need to store 4,194,304 bytes (roughly 4MiB) so the storage requirements aren't huge. The values for bishops will be less so I'm not sure that this is a justification for avoiding the approach.
I could just be missing a key point so I hope someone can help clarify things for me.