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

Difference between revisions of "Position Representation"


 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
The representation of a chess game includes representation of positions and moves. Positions represent states of game and moves represent operators which are used to achieve transition from one position to another. Both of these representations must be able to do the following operations:
+
== Bitboard ==
 
 
* make move
 
* unmake move
 
* generate a list of all possible moves
 
* generate a list of all possible capture moves
 
* evaluate a position
 
* store moves
 
* compare positions
 
* set position
 
* check if position has been repeated 3 times
 
* check rule of 50 moves
 
* check if king is in check
 
 
 
All of these operations must be very time efficient because they take place inside the search algorithm. Efficient presentation of game will therefore exhibit an efficient chess program.
 
 
   
 
   
Bitboard is the best presentation of a chess position. 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
+
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:
 
presentation:
 
<center>
 
<center>
Line 68: Line 54:
  
 
[[Category:Borko Bošković]]
 
[[Category:Borko Bošković]]
 +
[[Category:Research activity]]
 
[[Category:Chess program BBChess]]
 
[[Category:Chess program BBChess]]
 
+
[[Category:Representation of Chess Game]]
 
[[sl:Bitna predstavitev igre]]
 
[[sl:Bitna predstavitev igre]]

Latest revision as of 08:40, 19 October 2006

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