What does HackerNews think of ChessPositionRanking?
Software suite for ranking chess positions and accurately estimating the number of legal chess positions
1. You'd definitely want to deduplicate positions of identical pieces for even more savings 2. That only handles the case where no pieces have been captured, and the full arithmetic coding would probably need separate "sections" of the integer range for different cases, and the number of sections is also quite high. 3. There's extra nuanced things you might want to handle in the coding, like that pawns can't be on their own back row. That is significantly harder.
It looks to me like https://github.com/tromp/ChessPositionRanking has resolved these sorts of issues, but I haven't dug into exactly how.
https://github.com/tromp/ChessPositionRanking
But the major point of this project is to allow for random sampling of positions with a decent likelihood of getting a legal one, which allows for accurate estimation of the number of legal positions.
> let r = multinomialRanking (zip "abc" [1..3])
> size r
60
> unrank r 42
"cbcabc"
> rank r "cbcabc"
42
Various types of rankings, together with combinators to build up more complex ones, were implemented as part of the chess position ranking project [2] which aims to rank a subset of all chess positions that includes all legal ones: > let cpr = sideToMoveRanking `composeURI` (caseRanking `composeRI` wArmyStatRanking `composeURI` bArmyStatRanking `composeRI` guardRanking `composeRI` enPassantRanking `composeURI` epOppRanking `composeURI` sandwichRanking `composeRI` opposeRanking `composeURI` pawnRanking `composeURI` castleRanking `composeURI` wArmyRanking `composeURI` bArmyRanking `composeURI` pieceRanking) $ emptyURPosition
> size cpr
8726713169886222032347729969256422370854716254
> writeFEN . toPosition . unrank cpr $ 2389124290426577024216048831051262280148947032
"1r6/1qrRPk2/1rn1Rn1n/1RQRR2R/3P4/3b2BN/1Knn1b1b/1BR5 w - - 0 1"
> rank cpr . fromPosition . readFEN $ "1r6/1qrRPk2/1rn1Rn1n/1RQRR2R/3P4/3b2BN/1Knn1b1b/1BR5 w - - 0 1"
2389124290426577024216048831051262280148947032
Position data includes side to move, castling status, and en-passant status. This ranking allows one to sample millions of random such positions, determine how many are legal, and thus obtain an accurate estimate of 4.8 * 10^44 legal chess positions.[1] https://github.com/tromp/ChessPositionRanking/blob/main/src/...
http://talkchess.com/forum3/viewtopic.php?f=7&t=77685&sid=e3...
Practically speaking, https://github.com/tromp/ChessPositionRanking gives a number between 0 and approx. 8.7 * 10^45 for any legal position, so it's only a couple of bits away from optimality.
A similar Haskell module [2] was written by Brent Yorgey.
The multinomialRanking function in my module generalizes the binomial rankings considered in the article, as well as permutations. By composing all kinds of rankings together, some very interesting classes of objects can be enumerated.
Even very densely coded chess positions; by nesting 14 different rankings, I obtained a ranking of size ~ 8.7x10^45 that includes all legal chess positions. Sampling millions of random chess positions [3] and determining their legality [4] allowed us to estimate the number of legal chess positions as ~ 4.8 * 10^44.
[1] https://github.com/tromp/ChessPositionRanking/blob/main/src/...
[2] https://hackage.haskell.org/package/simple-enumeration-0.2/d...
[3] https://github.com/tromp/ChessPositionRanking
[4] https://github.com/peterosterlund2/texel/blob/master/doc/pro...
[1] https://github.com/tromp/ChessPositionRanking
[2] https://github.com/tromp/ChessPositionRanking/blob/main/src/...