I am writing a C++ chess engine based on the magic bitboard, where ordering for bitboards is from LSB to MSB in Little-Endian Rank-File mapping. I'd like to have a 6x64 dimension 2D array for all possible attack sets for each piece on every square to save time during program execution.

Is there a resource that has these bitboards already defined so that I don't have to spend several hours constructing them manually, or is there a way to generate the attack sets with a program?

  • 1
    Of course there's a way to generate them from a program! Have you tried writing the program? It seems pretty easy to calculate e.g. which squares a rook can attack.
    – user253751
    Jan 7, 2021 at 2:53
  • @user253751 I'm having trouble figuring out a closed form formula that gives me a number (that I can use for an attack map bitboard) given a position and piece type. If there's a simple way to do this, I'd love to learn how.
    – Noah43554
    Jan 7, 2021 at 3:40
  • Why does it need to be closed-form? Write a program to check whether each square can attack each other square.
    – user253751
    Jan 7, 2021 at 8:59

1 Answer 1


Stockfish (https://stockfishchess.org/download/) is open source and uses magic bitboards.
Crafty (https://craftychess.com/) uses bitboards and is heavily commented. There are other using bitboards, but these two are the best.

Hopefully this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.