bitboard # / . click squares to toggle.

Bitboards are a technique used to represent the state of a board game in software. A bitboard is a bit field where each bit corresponds to a specific space on the board. Typically multiple bitboards are necessary to fully encode the state of a board. For example, to represent a checkers board you’d need two bitboards: one for each player. Chess requires eight; one for each type of piece and one for each player.

These bit fields allow you to access the state of the board using fast bitwise operations. If you need to find white pawns, white & pawns will return a board with only the white pawns on it. Bitboards are also very compact, able to store the complete state of a chess board in 64 * 8 = 512 bits. This is a big part of what makes bitboards so fast: computers are very good at doing bitwise operations on numbers that fit neatly into memory.

This sketch has been reduced from a full 8x8 chess board to a 4x4 square. It has also been simplified to remove chess board numbering. You can get the chessboard version on editor.p5js.org.

<< go back • get the code