Home

bitboards

Bitboards are a compact data structure used to represent the state of board games, most notably chess. In a bitboard, the board is mapped to the bits of one or more integers; a set bit indicates the presence of a piece or occupancy on the corresponding square. On an 8x8 chessboard, a 64-bit unsigned integer can represent a single plane, and engines commonly allocate one bitboard per piece type and color (for example white pawns, black pawns, white knights, etc.), along with bitboards for occupancy of all pieces, white, and black.

Common practice in chess engines involves multiple bitboards to describe the full position. A typical configuration

Advantages include fast move generation and evaluation, use of native CPU bitwise instructions, and compact memory

uses
six
piece-type
bitboards
per
color
(pawns,
knights,
bishops,
rooks,
queens,
king)
plus
one
or
more
occupancy
bitboards.
This
allows
efficient
computation
of
moves
and
attacks
via
bitwise
operations
such
as
shifts,
AND,
OR,
and
XOR.
For
example,
shifting
a
pawn
bitboard
by
one
rank
can
generate
pseudo-legal
advances,
while
masks
prevent
moves
off
the
board
or
into
occupied
squares.
Population
count
and
trailing-zero
operations
enable
fast
iteration
over
the
set
bits
to
enumerate
moves.
usage.
Bitboards
also
enable
parallel
evaluation
of
multiple
squares
and
pieces
within
a
single
operation.
Limitations
include
considerable
programming
complexity,
especially
for
sliding
pieces
and
legality
checks,
and
the
approach
is
most
convenient
for
fixed-size
boards
(like
8x8).
Larger
or
differently
shaped
boards
require
multiple
bitboards
or
larger
word
sizes,
which
can
reduce
performance
advantages.