castling rights as a mask: 1 white kingside, 2 white queenside, 4 black kingside, 8 black queenside
a square a pawn could capture onto, left behind by a double push
king squares, white then black: maintained on every move, so checks never scan
twelve bitboards: white pawn..king, then black pawn..king
Chess on bitboards: the first slice of the tournament engine (item 390).
Twelve 64-bit boards (
pieces[color * 6 + kind], white 0-5, black 6-11, square 0 is a1 exactly likechess.ts), side to move, castling rights, en passant square, the halfmove clock and both king squares. Everything in it is plain data (bigintincluded), so a position structured-clones into a worker untouched.Two implementations of the rules now exist on purpose:
chess.tsis the readable reference a minigame runs directly, this one is the fast mutable board a search makes and unmakes millions of times.tests/board-bitboard.test.tskeeps them honest two ways: every legal move of one is a legal move of the other on a suite of positions, and perft counts match the published node counts.