Non-slider bitboards
Non-sliding pieces in a bitboard chess engine are much easier to understand than the sliders. They don’t even require any magics; they just use plain and simple bitboards. As was discussed in the board reppresentation, each piece type has its own set of bitboards. If you don’t clearly remember, here is how the 64-bit bitboard of the king on e4 would look like:
bits: 00000000 00000000 00000000 00000000 00010000 00000000 00000000 00000000
decimal value: 268,435,456 ^ // This is the only 1
This is obviously unreadable and unusable for a human. Therefore, when working with bitboards, it is recommended to put a print_bitboard() routine into the engine (at least as a debugging tool) to print a bitboard to the screen in an 8x8 grid with A1 on the bottom left, so it can be viewed as a chessboard. The one with the king (or any piece for that matter) on E4 would look like this:
8 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0
4 0 0 0 0 1 0 0 0
3 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
A B C D E F G H
A1 is the least significant bit (LSB, which is the right-most one if you write a bitboard out as 1’s and 0’s), while H8 is the most significant bit (MSB, on the left). For a human, this is much easier to use and understand. Therefore we will use this representation. Now, how can we use bitboards to know where a piece can move? That is easy. For a king on E4, this is the bitboard that marks where the king can move:
8 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0
5 0 0 0 1 1 1 0 0
4 0 0 0 1 · 1 0 0
3 0 0 0 1 1 1 0 0
2 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
A B C D E F G H
Note that we don’t take into account if the king is in check, or if there are any other pieces on the board. The only thing we want to know is: “Where can a king on E4 move, if he’s on an empty board?” The bitboard above tells us exacty that. It works exactly the same for the knight, which is the other non-slider:
8 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0
6 0 0 0 1 0 1 0 0
5 0 0 1 0 0 0 1 0
4 0 0 0 0 · 0 0 0
3 0 0 1 0 0 0 1 0
2 0 0 0 1 0 1 0 0
1 0 0 0 0 0 0 0 0
A B C D E F G H
This bitboard shows where a knight on E4 can move on an empty board.
The pawns are also non-sliders, but they are different enough to give them their own section. Now, we can take a look how we can use the above information to initialize non-slider pieces.