NULP

(Number of Unique Legal Positions in chess endgames)

Method

What is a position?

For the purpose of this experiment a position is defined as a combination of piece placement, side to move, castling rights and en-passant rights. Storing the evaluations for all such positions from a particlar endgame allows perfect play from the point of entering that endgame, so the number of such positions is directly related to the amount of necessary storage space.

A complete game state should include the move counter for detecting a draw by 50-move rule. Move counter can be very important when distance to mate (DTM) is stored in the database and used for choosing the moves. However using distance to zeroing (DTZ) allows to avoid storing the move counter while still respecting the 50-move rule. (Most of endgame databases in use today simply ignore the 50-move rule, in which case the move counter is also unnecessary).

A complete game state should also include the relevant part of game history for detecting 3-fold repetitions. Repetitions can't occur in a winning line if the winning side plays perfectly, and they won't matter in a drawing line, therefore the history can be safely omitted as well.

Uniqueness

Counting, solving or storing the same position twice is obviously a waste of time and space. Similarly, if two positions can be proven to produce identical outcomes with best play of both sides (let's call such positions equivalent), it's a waste of space to store both of them independently. Whether it's also a waste of time depends on how fast the equivalence can be tested and on how it impacts indexing design and performance.

In this experiment I require equivalence to perfectly take into account board mirroring, board rotation and color swapping. Such equivalence is easy to test, so counting unique positions (or equivalence classes) is possible. (It's less trivial to design a gapless indexing scheme omitting all redundant positions, but this is outside of the scope of current experiment).

Two positions are called equivalent if one can be obtained from the other through a sequence of transformations, which may include:

 1. Swapping colors of all pieces, mirroring locations of all pieces and en-passant target squares around the horizontal middle line, swapping castling rights and side to move: k3/4/4/KR2 wwhite to move kr2/4/4/K3 wblack to move
 2. (Only for positions with no castling rights, except on a board of odd width) Mirroring locations of all pieces and en-passant rights around the vertical middle line. k3/4/4/KR2 wwhite to move 3k/4/4/2RK wwhite to move
 3. (Only for pawnless positions with no castling rights) Mirroring locations of all pieces around the horizontal middle line. k3/4/4/KR2 wwhite to move KR2/4/4/k3 wwhite to move
 4. (Only for pawnless positions with no castling rights, only for square board) Mirroring locations of all pieces around the a8-h1 diagonal (or around the line connecting top-left and bottom-right corners for other board sizes). k3/4/4/KR2 wwhite to move k2K/3R/4/4 wwhite to move

Note that board rotations and mirroring around the other diagonal can be produced by combining several of the listed transformations. Also you can notice that this equivalence is reflexive, symmetric and transitive.

4-th transformation can produce identical position if all pieces are located on a8-h1 diagonal. 2-nd and 3-rd transformations can produce identical positions on an odd-sized board. The 1-st transformation however can be applied to any position, and will always produce a non-identical position. Therefore every position has at least one equivalent non-identical variant. Each transformation applied twice returns back to the original position, so the maximum possible number of equivalent non-identical variants for a position is 16.

Here is one example of equivalence class — all these positions are considered to be equivalent to each other (4x4 board is used for compactness):

k3/4/4/KR2 wwhite to move 3k/4/4/2RK wwhite to move KR2/4/4/k3 wwhite to move 2RK/4/4/3k wwhite to move 4/4/R3/K2k wwhite to move K2k/R3/4/4 wwhite to move 4/4/3R/k2K wwhite to move k2K/3R/4/4 wwhite to move
K3/4/4/kr2 wblack to move 3K/4/4/2rk wblack to move kr2/4/4/K3 wblack to move 2rk/4/4/3K wblack to move 4/4/r3/k2K wblack to move k2K/r3/4/4 wblack to move 4/4/3r/K2k wblack to move K2k/3r/4/4 wblack to move

Counting unique positions means counting such equivalence classes (or counting only one position out of each equivalence class).

One case of trivial equivalence ignored in the definition above is between two positions that differ by just en-passant capture right, when the en-passant capture is not a legal move. Such two positions have identical sets of available moves, so it's redundant to solve or store both of them. However in this experiment I count such positions separately.

Legality

Traditionally legal positions are defined as those that can be reached from the starting position after a sequence of legal moves. Checking for such legality is prohibitively expensive, so more simple concepts of legality are used in endgame solving. Such legality is easy to verify, but can include some positions that are illegal in traditional sense. Here is the definition used in this experiment:

A position is called illegal when any of the following conditions holds:

All other positions are considered to be legal and counted in this experiment (none of the illegal positions are counted).


© 2013–2014 Kirill Kryukov
Available under the CC BY 3.0 License