Search code examples
bit-manipulation64-bitchessbitmaskbitboard

how to use bitboards in chess?


I am making a bitboard based chess engine and I would like to ask - assuming that I made a bitboard to every piece, what do I do with it? I read a little bit about some techniques like if you shift the pawns bit board to the left by 7 and 9 you get a bitboard representing the squares they attack, but how do I use it? or how do I use the rook bitboard or bishop bitboard? like what are their targets, and if I find it how do I connect it with the other pieces bitboards? I have been searching on it for days now but did not find a sufficient answer... thanks


Solution

  • Bitboards is another type of board respresentation than for example a 2d array board or a 1d array. The main advantage is that they can help you generate valid moves for a position quicker and that you can use them more easily to get certain evaluation structures and parameters.

    Usually you have 1 bitboard for each piece and each side (12 total), one for each color (2 total), one for all pieces, one for castling rights, one for side to move. With bit operators and bit manipulation you can calculate the valid moves for a position with the help of precomputed tables and only a few bit operations.

    I suggest looking at this YouTube series which goes through the entire process of writing a bitboard chess engine from scratch.

    Another good source to get how the concepts work is to look at the Chessprogramming site.

    I hope it helps! It is not easy to wrap your head around, but the gain from using them is great.