Chess - Programming - Polyglot Book Format - Extensions for other forms of Chess - Chess960
The Zobrist hash function used in Polyglot does not keep track of which rook has castling rights if there are multiple rooks present on the same side of the king.
- However it is rather unlikely that this situation would occur in the opening.
- So the ambiguity can be resolved in a satisfactory way by making the following convention.
Positions in which a rook has castling rights which is not an outer rook (closest to a or h file) should not be included in the book.
- Nonetheless this is an unsatisfactory situation.
- Therefore the upcoming versions of xboard/winboard extend the Polyglot hash function in such a way that it takes into account the full castling rights in Chess960, therefore removing the need of the above disambiguating convention.
- This is done in a backward compatible way. i.e. ordinary chess positions or Chess960 positions in which there is no castling ambiguity will keep their old hash key.
The declaration of RANDOM_CASTLE is replaced by:
const uint64 RandomCastle[16]={ < to be filled in > }
In this case “castle” will be the exclusive or of entries taken from RANDOM_CASTLE, one for each rook that has castling rights (so at most four offsets).
The offset for a rook that has castling rights is computed as:
- If the rook is an outer rook (i.e. closest to the a or h file) then the offset is
0 | If the rook is white and on the king side. |
1 | If the rook is white and on the queen side. |
2 | If the rook is black and on the king side. |
3 | If the rook is black and on the queen side. |
This is like in ordinary chess.
- If the rook is not an outer rook then the offset is:
3+file | If the rook is white. |
9+file | If the rook is black. |
- where “file” denotes the file the Rook is on, encoded in the usual way, i.e. b=1,c=2,d=3,e=4,f=5,g=6.
Encoding of moves
A castling move is encoded as a usual move (see above) in which the “from square” is the position of the king and the “to square” is the position of the rook.
- This is to maintain compatibility with various Fruit derivatives.