Changes

Jump to: navigation, search

Encoding Moves

93 bytes removed, 18:25, 10 May 2020
fix calculation of the upper bound of moves on an empty board (used separate castling encoding before)
NOTE: We will always use this upper bound instead of the actual number of possible legal moves because this way we don't have to compute any attacks.
So for the standard chess piece set we have an upper bound of <code>2 + 12*8 + 8*2 + 13*2 + 14*2 + 27 + 8 == 203201</code> possible moves before considering promotions. Each knight promotion reduces it by 12-8=4. Each bishop promotion increases it by 1; rook promotion by 2; queen promotion by 15. In the parametrized worst case (all pawns promoted to either rooks or queens) we have <code>n</code> queen and <code>8-n</code> rook promotions, so the upper bound is <code>f(n) = 2 + 8*2 + 13*2 + 14*(2+8-n) + 27*(1+n) + 8 == 219 217 + 13n</code>. <code>f(n=23)=245</code> is the highest <code>n</code> such that the upper bound is lower than 256 <code>256==2^8</code>.
So for legal Chess960 positions with at most 2 3 queens on the board one can encode any legal move in just one byte. Note that whether the result can always fit in one byte is determined based solely one the position, so no additional information needs to be stored for disambiguation. This way it's easy to implement a fallback for the positions not supported by this encoding (this could be either to use 2 bytes for the move index or use legal move generation to ensure all values take one byte).
One way to encode a position using this information is in the following way:

Navigation menu