Take this position as an example:
[d]4k3/8/8/8/8/8/5PPP/4K2R w - - 0 1
This is obviously a win for white, and the DTZ is obviously 1, because there are pawn moves. Let's assume now that white can still castle. What would that change? Intuition tells me that the distance to mate is smaller with castling rights because it is easier to free the rook, but that detail does not have any significant impact on the outcome of the game.
I cannot think of any position where castling rights for the side to move can turn a technical win into a draw or loss (correct me if I'm wrong). So why not probe the tablebase nevertheless iff the WDL is greater than 0 and only the side to move has the right to castle? The DTZ should in that case be treated as an upper bound, but, again, that will hardly ever matter.
Yes, I know that the impact on playing strength would probably not be measurable. And, yes, I know that the tablebase files are created only with positions where both sides have already lost their rights to castle. But what am I missing?
Why not Probe Syzygy Tablebases When Side to Move Can Castle?
Moderator: Ras
-
gflohr
- Posts: 90
- Joined: Fri Jul 23, 2021 5:24 pm
- Location: Elin Pelin
- Full name: Guido Flohr
-
gflohr
- Posts: 90
- Joined: Fri Jul 23, 2021 5:24 pm
- Location: Elin Pelin
- Full name: Guido Flohr
Re: Why not Probe Syzygy Tablebases When Side to Move Can Castle?
When I think about it, the condition could actually be WDL >= 0, not WDL > 0. If I can reach a draw without castling rights, how could I not reach that draw with castling rights? I think that stalemate can be ignored here because a castling move can never be the only legal move. If you can castle, you always have at least one more king move and at least two more rook moves.
-
gflohr
- Posts: 90
- Joined: Fri Jul 23, 2021 5:24 pm
- Location: Elin Pelin
- Full name: Guido Flohr
Re: Why not Probe Syzygy Tablebases When Side to Move Can Castle?
Sorry for correcting myself once more: I think that the WDL score of the position is not relevant at all. It all boils down to the fact that my own castling rights can only ever improve my position. They can never make it worse.
-
Ajedrecista
- Posts: 2192
- Joined: Wed Jul 13, 2011 9:04 pm
- Location: Madrid, Spain.
Re: Why not probe Syzygy tablebases when side to move can castle?
Hello:
This is not a technical answer, but an unsuccessful try to find such key positions. Here is an example of a position where castling wins and not being able to castle loses:
8/8/1q6/5R2/8/8/1P1PP1pp/R3K1k1 w - - 0 1
8/8/1q6/5R2/8/8/1P1PP1pp/R3K1k1 w Q - 0 1
But I am afraid you are asking for the opposite: a position where castling is worse for the castling side. I worked other example where the castling move loses in a drawn position (O-O?, Ne2#):
5k2/8/8/8/3n4/5b2/5P1P/4K2R w K - 0 1
I guess this is not enough. We might search for a position where castling is the only legal move and loses while without castling, not legal moves mean a stalemate. I think it is impossible because a castling needs that f1-g1 or c1-d1 (f8-g8 or c8-d8 for black) are empty and not attacked by the opponent, so the king can also move to f1 or d1 (f8 or d8 for black) in this case, as well the rook through the king, since there are not pins (already written by you, but I really had not read it until I posted).
------------
Going for the castling winning side, not castling wins in one (Kd2#) while castling wins slower:
8/8/8/8/8/8/pp6/1k2K2R w - - 0 1
8/8/8/8/8/8/pp6/1k2K2R w K - 0 1
Though castling is not compulsory when available, of course, as in othe example above (O-O?, Ne2#).
Regards from Spain.
Ajedrecista.
This is not a technical answer, but an unsuccessful try to find such key positions. Here is an example of a position where castling wins and not being able to castle loses:
8/8/1q6/5R2/8/8/1P1PP1pp/R3K1k1 w - - 0 1
8/8/1q6/5R2/8/8/1P1PP1pp/R3K1k1 w Q - 0 1
But I am afraid you are asking for the opposite: a position where castling is worse for the castling side. I worked other example where the castling move loses in a drawn position (O-O?, Ne2#):
5k2/8/8/8/3n4/5b2/5P1P/4K2R w K - 0 1
I guess this is not enough. We might search for a position where castling is the only legal move and loses while without castling, not legal moves mean a stalemate. I think it is impossible because a castling needs that f1-g1 or c1-d1 (f8-g8 or c8-d8 for black) are empty and not attacked by the opponent, so the king can also move to f1 or d1 (f8 or d8 for black) in this case, as well the rook through the king, since there are not pins (already written by you, but I really had not read it until I posted).
------------
Going for the castling winning side, not castling wins in one (Kd2#) while castling wins slower:
8/8/8/8/8/8/pp6/1k2K2R w - - 0 1
8/8/8/8/8/8/pp6/1k2K2R w K - 0 1
Though castling is not compulsory when available, of course, as in othe example above (O-O?, Ne2#).
Regards from Spain.
Ajedrecista.
-
gflohr
- Posts: 90
- Joined: Fri Jul 23, 2021 5:24 pm
- Location: Elin Pelin
- Full name: Guido Flohr
Re: Why not probe Syzygy tablebases when side to move can castle?
Exactly.Ajedrecista wrote: ↑Mon Feb 02, 2026 8:23 pm But I am afraid you are asking for the opposite: a position where castling is worse for the castling side.
There is no such position, at least not in standard chess. The rook can always reach every square between itself and the king.Ajedrecista wrote: ↑Mon Feb 02, 2026 8:23 pm We might search for a position where castling is the only legal move
That is my point. If the side to move can castle but the other side can not, then it is legitimate to probe the endgame tablebase and take the result as a lower bound. Having the option to castle can make things only better.Ajedrecista wrote: ↑Mon Feb 02, 2026 8:23 pm Going for the castling winning side, not castling wins in one (Kd2#) while castling wins slower:
8/8/8/8/8/8/pp6/1k2K2R w - - 0 1
8/8/8/8/8/8/pp6/1k2K2R w K - 0 1
Though castling is not compulsory when available, of course, as in othe example above (O-O?, Ne2#).
Regards back from snowy Bulgaria.
-
syzygy
- Posts: 5897
- Joined: Tue Feb 28, 2012 11:56 pm
Re: Why not Probe Syzygy Tablebases When Side to Move Can Castle?
1. Yoiu have to be sure that there are no exceptions.
2. You have to check castling rights for both sides and deal with them.
3. This will never ever happen in a real game.
4. Feel free to implement it anyway.
-
jorose
- Posts: 385
- Joined: Thu Jan 22, 2015 3:21 pm
- Location: Zurich, Switzerland
- Full name: Jonathan Rosenthal
Re: Why not Probe Syzygy Tablebases When Side to Move Can Castle?
You are probably right in theory, but I highly doubt it would improve gameplay or even change it in a noticeable way. The vast majority of tablebase positions reached have no castling rights anyways.
-Jonathan
-
gflohr
- Posts: 90
- Joined: Fri Jul 23, 2021 5:24 pm
- Location: Elin Pelin
- Full name: Guido Flohr
Re: Why not Probe Syzygy Tablebases When Side to Move Can Castle?
I know. This was mostly an academic question. I had no intention to create a PR for Stockfish.
But it may matter for other engines. Depending on the architecture, it may be expensive to check the castling rights, and it may be cheaper to check the castling rights for just one side. For my engine, this is not the case. So I will stick with the conventional approach.
But I was also curious to see how relevant the question actually is. I'm currently running a script that parses all (about 95 million) standard games on lichess from December 25. Whenever the piece count drops to 7, 6, 5, 4, 3, I check whether any side can still castle, and if an en passant capture is theoretically possible until the end of the game. These are the current results:
After 7.75 million games, the rate of games with potential en passant captures has stabilised around 20.5 %. Taking it into account during tablebase probes obviously makes sense.
Castling seems to be possible with 7 pieces on the board in a little bit more than 1 out of 10,000 games. I took a look at some of these games. There was one by a banned account, one seemed to be a fun game, but most of them looked like real games by humans. I've seen a lot of bullet games. Maybe people forget to castle under time pressure. I have a list of links to these games, if anybody is interested.
Conclusion? Not probing positions with any castling rights is certainly not wrong. Looking only at the castling rights of the other side seems to be correct as well, for me at least.
Ignoring them altogether will probably also not hurt a lot. With 7 pieces on the board, one in about 10k probes may give a wrong result, although highly unlikely. For fewer pieces on the board, this rate rapidly goes down to 0. If checking for castling rights happens to be expensive, it may well be worth trying to just ignore them.
But it may matter for other engines. Depending on the architecture, it may be expensive to check the castling rights, and it may be cheaper to check the castling rights for just one side. For my engine, this is not the case. So I will stick with the conventional approach.
But I was also curious to see how relevant the question actually is. I'm currently running a script that parses all (about 95 million) standard games on lichess from December 25. Whenever the piece count drops to 7, 6, 5, 4, 3, I check whether any side can still castle, and if an en passant capture is theoretically possible until the end of the game. These are the current results:
Code: Select all
----------------------------------------------------------------
Parsed 7759376 games
7 pieces:
en-passant still possible: 175160/852123 (20.555717895186 %)
castling still possible: 119/852123 (0.013965120059 %)
6 pieces:
en-passant still possible: 69853/642779 (10.867343208163 %)
castling still possible: 35/642779 (0.005445106327 %)
5 pieces:
en-passant still possible: 19367/454193 (4.264046341533 %)
castling still possible: 7/454193 (0.001541195043 %)
4 pieces:
en-passant still possible: 2754/289309 (0.951923376044 %)
castling still possible: 0/289309 (0.000000000000 %)
3 pieces:
castling still possible: 0/148772 (0.000000000000 %)
----------------------------------------------------------------
Castling seems to be possible with 7 pieces on the board in a little bit more than 1 out of 10,000 games. I took a look at some of these games. There was one by a banned account, one seemed to be a fun game, but most of them looked like real games by humans. I've seen a lot of bullet games. Maybe people forget to castle under time pressure. I have a list of links to these games, if anybody is interested.
Conclusion? Not probing positions with any castling rights is certainly not wrong. Looking only at the castling rights of the other side seems to be correct as well, for me at least.
Ignoring them altogether will probably also not hurt a lot. With 7 pieces on the board, one in about 10k probes may give a wrong result, although highly unlikely. For fewer pieces on the board, this rate rapidly goes down to 0. If checking for castling rights happens to be expensive, it may well be worth trying to just ignore them.
-
syzygy
- Posts: 5897
- Joined: Tue Feb 28, 2012 11:56 pm
Re: Why not Probe Syzygy Tablebases When Side to Move Can Castle?
Well, it seems having castling rights can never be negative, but depending on which side still has the right to castle, the returned TB value will be a lower bound or an upper bound (or neither if both sides can still castle). Instead, if no castling rights remain, you can use the TB value as the exact (WDL) value of the position.
Of course it won't measurably hurt playing strength if you probe as normal but simply do not check castling rights at all. But then someone might set up a special position and post a video on TikTok that shows your engine has a bug.