Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Position Representation


Revision as of 08:40, 19 October 2006 by Borko (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Bitboard

Bitboard is the best presentation of a chess position. Main advantage of that representation is a speed becaus it based on bitwise operations. The presentation contains a set of 64-bit integer numbers. Both sides have six numbers for all different types of pieces. For example, the position below has the following white pawns presentation:

Chess zhor 26.png
Chess zver 26.png
a8 b8 c8 d8 e8 f8 g8 h8
a7 b7 c7 d7 e7 f7 g7 h7
a6 b6 c6 d6 e6 f6 g6 h6
a5 b5 c5 d5 e5 f5 g5 h5
a4 b4 c4 d4 e4 f4 g4 h4
a3 b3 c3 d3 e3 f3 g3 h3
a2 b2 c2 d2 e2 f2 g2 h2
a1 b1 c1 d1 e1 f1 g1 h1
Chess zver 26.png
Chess zhor 26.png

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 1 0 0 0

0 0 0 0 0 0 1 0

1 1 0 0 0 1 0 1

0 0 0 0 0 0 0 0

The 64-bit presentation allows a fast move generator and a fast evaluation function. For example, the expression (WhitePawns << 8) & ~AllSquares is used to represent all possible destination squares of white pawns for one square up. Let us see this expression in grater detail. Firstly, the presentation of white pieces was shifted by 8 bits or moved for one square up. Then with negation of presentation of all pieces we get presentation of empty squares. Finally, with bitwise operation AND between both presentations we get presentation of destination squares. This presentation and presentation of white pawns enables generating all possible moves for white pawns for one square up. Similarly, we can calculate all possible moves for pawns, knights, and the king. For generating moves for sliding pieces we use addition information which is described below.

Rotated bitboard

The standard bitboard presentation described above is very useful in generating moves for all pieces except sliding ones (bishop, rock, queen). Rotated bitboard provides additional information for certain types of pieces, namely the sliding ones. Bitboard is rotated by 45, 90, and 135 degreees. The 45 and 135 degrees rotations are used for calculating diagonal and the 90 degrees for calculating vertical moves. The speedup of rotated bitboard relies on quick discovery of attacks on certain squares without the need to use program loops which is the case for all other representations.

Links