One other thing that bugs me a bit is that we make all this effort to calculate the entire moveset of a piece in one go. But then later we probably end up iterating over that bitset anyway, right?
Somewhere you do something like:
Code: Select all
uint64_t bishop_moves = cool_magic_bitboard_function(bishop, board);
//...
while(bishop_moves) {
bit = extract_one_bit(bishop_moves);
//play the move, insert it into a list etc.
//...
bishop_moves &= ~bit;
}
When you could have just generated the sliding moves iteratively in the first place
Code: Select all
uint64_t bishop_move = bishop;
while(bishop_move & ~blockers) {
bishop_move <<= 9u; // iterate towards positive direction
//play the move, insert it into a list etc.
//...
}
// repeat for the other directions
Of course being able to calculate these in bulk is still useful if you don't actually need to iterate over them. Such as when calculating controlled squares, looking for checks, pins, forks etc. but for raw move generation the first approach is almost a bit dubious compared to the second?