Skip to content

Unify (D)FRC castling rights notation to X-FEN#71

Open
robertnurnberg wants to merge 1 commit intoofficial-stockfish:masterfrom
robertnurnberg:unify-cr
Open

Unify (D)FRC castling rights notation to X-FEN#71
robertnurnberg wants to merge 1 commit intoofficial-stockfish:masterfrom
robertnurnberg:unify-cr

Conversation

@robertnurnberg
Copy link
Copy Markdown
Contributor

In master we have:

> head -n 2 FRC_openings.epd DFRC_openings.epd  
==> FRC_openings.epd <==
bbqnnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w KQkq - 0 1
bqnbnrkr/pppppppp/8/8/8/8/PPPPPPPP/BQNBNRKR w KQkq - 0 1

==> DFRC_openings.epd <==
bbqnnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w HFhf - 0 1
bqnbnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w HFhf - 0 1

In the past this has caused some confusion, especially because in DFRC_4852_v1.epd both notations can be found.

This patch changes all the castling rights for the DFRC start positions to KQkq. This is a "non functional" change, since in the start positions there can be no ambiguity. All the other positions in DFRC_4852_v1.epd already use the KQ based notation (where possible), as they were emitted by python-chess, which defaults to this standard.

@Disservin
Copy link
Copy Markdown
Member

just dont use KQkq notation at all?

@robertnurnberg
Copy link
Copy Markdown
Contributor Author

That would also be possible. But (a) the KQkq seems to be more common (and natural tbh) and (b) the edit from KQkq to rook files is a bit more involved.

I believe in master all FRC books use the KQkq notation.

Out of curiosity, what does fastchess use for the FEN tag in a pgn, say?

@Disservin
Copy link
Copy Markdown
Member

b) that makes little sense to me as for DFRC you would need to be able to parse both formats, easier to assume only the file encoding than KQkq

fastchess only uses file encoding

@robertnurnberg
Copy link
Copy Markdown
Contributor Author

With (b) I meant that the effort for this PR virtually involved sed 's/w.* - 0 1/w KQkq - 0 1/g' on the two DFRC books, whereas the inverse operation would need some chess-aware parsing for all FRC and DFRC books.

I checked Lichess analysis board and python-chess, and both revert to KQkq notation. The latter can be checked by running

import chess

fen = "bbqnnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w HFhf - 0 1"
print(fen)
board = chess.Board(fen, chess960=True)
print(board.fen())

giving the output

bbqnnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w HFhf - 0 1
bbqnnrkr/pppppppp/8/8/8/8/PPPPPPPP/BBQNNRKR w KQkq - 0 1

To me KQkq is more natural. Similar to SAN one can stick with the default, unless one has to disambiguate when there are more than one rook on the side of the king that still allows castling.

I guess we were just unlucky that vondele used a tool/script with rook file notation in #31.

PS: As a bonus, using KQkq everywhere also seems to lead to better compression. :)

@robertnurnberg
Copy link
Copy Markdown
Contributor Author

So it turns out that the X-FEN standard says to use KQkq whenever the outermost of several rooks on one side can castle, and file letters otherwise.

This "strict" X-FEN standard is also used by cdb, by the way. See vondele/cdbdirect#19.

@robertnurnberg robertnurnberg changed the title Unify (D)FRC castling rights notation Unify (D)FRC castling rights notation to X-FEN Dec 20, 2025
@robertnurnberg
Copy link
Copy Markdown
Contributor Author

Now that chess-lib also has x-fen support, any chance we can merge this? @vondele

@Disservin
Copy link
Copy Markdown
Member

wouldn't we a) need to update fastchess and b) fishtest ?
and I still somewhat prefer the Shredder-FEN notation because it is simpler.

@robertnurnberg
Copy link
Copy Markdown
Contributor Author

Hm, x-fen input has worked for a long time in fastchess, stockfish and fishtest, I believe.

Like testing with ./fastchess -engine name="sf12" cmd=./sf12 -engine name="sf12a" cmd=./sf12 -each tc=1 -openings file=fencheck.epd format=epd -rounds 10 -repeat -variant fischerandom -concurrency 4 -pgnout file=fencheck.pgn append=false works fine. (Ofc, fastchess uses shredder fen for the book exit fen in the pgn output, but that is no problem). With the fencheck.epd file from Disservin/chess-library#221 (comment).

My reference to today's x-fen patch to chess-lib was meant to say that now it is trivial for everyone to produce x-fen books in future. So I believe we should consistently use that from now on.

@Ciekce
Copy link
Copy Markdown

Ciekce commented Apr 5, 2026

KQkq seems to be more common (and natural tbh)

I would like to mention that the x-fen form is much less commonly supported in non-SF engines than the shredder fen form (HAha)

of course this doesn't matter for books that are purely used for cutechess and fastchess, and I think at least cutechess will always pass shredder fens to engines(?), but it is not uncommon for engines to want to directly ingest lists of fens for one purpose or another

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants