Internal Board Representation#
chessengine uses bitboards to represent a chess board internally. A bitboard is just a 64-bit integer in which each bit corresponds to one square on the chess board (since a chess board also has 64 squares). A 1 at a certain position means that a piece is present on that square, and a 0 means that no piece is present on that square.
The board is defined in the chessengine.bitboard.Board class. It stores the bitboards of all pieces for each side as attributes with the naming
convention <side>_<piece>s
. For example, you can access the bitboard
corresponding to black bishops by accessing the black_bishops
attribute
on your Board
object.
Available Attributes#
The following attributes are available on the chessengine.bitboard.Board class -
Attributes For Chess Board#
Attribute |
Type |
Description |
---|---|---|
|
|
A bitboard representing the positions of all pieces on the board |
|
|
A dictionary mapping tuples of the format |
|
|
A list of all moves made on the board. Moves are stored as a tuple containing the fields listed below -
|
|
|
The side of the board. Can be |
|
|
The side of the opponent. Can be |
|
|
The position on the board to which a pawn can move to capture a pawn of the opposite side by en passant. Set to |
Attributes For White Side#
Attribute |
Description |
---|---|
|
A bitboard representing the positions of all white bishops on the board |
|
A bitboard representing the position of the white king on the board |
|
A bitboard representing the positions of all white knights on the board |
|
A bitboard representing the positions of all white pawns on the board |
|
A bitboard representing the positions of all white queens on the board |
|
A bitboard representing the positions of all white rooks on the board |
|
A bitboard representing the positions of all white pieces on the board |
Attributes For Black Side#
Attribute |
Description |
---|---|
|
A bitboard representing the positions of all black bishops on the board |
|
A bitboard representing the position of the black king on the board |
|
A bitboard representing the positions of all black knights on the board |
|
A bitboard representing the positions of all black pawns on the board |
|
A bitboard representing the positions of all black queens on the board |
|
A bitboard representing the positions of all black rooks on the board |
|
A bitboard representing the positions of all black pieces on the board |
Representing Positions On The Board#
The squares on the chessboard are numbered as follows -
All positions on the board are specified as a power of 2, where the power is the index according to
the diagram above. For example, to refer to the square c2
, you would pass 2**10
to whichever
function you are working with, and to refer to the square e5
, you would pass 2**36
.
All functions in chessengine.moves
accept position
as an argument, which is specified
as mentioned here. In general, all functions that accept a position
argument require it to
be specified as mentioned here. Moreover, the Board.move
function also requires this format for
its start
and end
arguments.
To help with converting between coordinates on the board, positions, and powers of 2, you can use the chessengine.lookup_tables module.