Almost perfect DTM tablebase

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: Almost perfect DTM tablebase

Post by syzygy »

hgm wrote: Wed Apr 15, 2020 11:14 am
Nordlandia wrote: Tue Apr 14, 2020 6:40 pm DTM50 is the optimum format ...
Not really. It can lead to very stupid defense, because it tries at all cost to guarantee the mate is delayed as long as possible. Even when that massively reduces the probability to get a draw through an opponent error. While in the end delaying mate in terms of the move number will not gain you any points, while delaying a zeroing event beyond the 50-move limit would have earned you a draw.
DTM50 would have recognised the position as a cursed draw (just like DTZ50 does).

However, I agree that DTM50 does not necessarily give the best defense of a losing position. But what is the best defense depends on how the opponent is playing. If he is using anything like DTZ50, you can as well resign immediately. If he has imperfect information, you have a chance but there is still no mathematically best way of playing (without knowing exactly what the opponent does not know).

Likewise, DTM50 is not of much help when playing a TB position that is a cursed win. The DTM50 table will only tell you it's a draw even though you may have realistic winning chances against an imperfect opponent. Here, Syzygy DTZ50+ will be of real help.
So you should always go for postponing the zeroing event that is closest to the 50-move limit, when defending a lost position. Often that is the first zeroing event you will encounter, as defending gets progressively more difficult as the opponent approches the winning goal. E.g. sacrificing a Knight in KBBKN just to secure a KBBK postion with a maximum DTM is a completely hopeless tactic, as the max DTM in KBBK is only 18 and the mate is easy, so you will never be able to draw it out to more than 50 moves even against a very fallible opponent. While in KBBKN you might have been only 1 sub-optimal move removed from a draw. Most KBBKN positions are cursed wins, so there are lots of possibilities for the opponent to err. It isn't very likely he will blunder away a Bishop in KBBK, though.
When in a lost TB position, my approach is to just let the engine play without checking TBs, except if DTZ is somewhat close to the 50-move limit. In the latter case, just maximise DTZ and hope the opponent plays sufficiently inaccurate.
User avatar
hgm
Posts: 27837
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Almost perfect DTM tablebase

Post by hgm »

syzygy wrote: Wed Apr 15, 2020 12:27 pmDTM50 would have recognised the position as a cursed draw (just like DTZ50 does).
Not if the zeroing was 49 moves away with perfect DTZ50 play. Then it would see it as a loss, and might stupidly convert to an end-game which is 100% lost in at most 30 moves, which the opponent can impossibly bungle, instead of keeping the margin at 1 move that requires the opponent to find the only winning move for 20 moves in a row.

Against a fallible opponent, always defending according to DTC should produce better results than defending according to DTM50. If the opponent has material to spare that he can forcibly sacrifice to reset the ply counter there is not much you could achieve anyway. But if he has the bare minimum of what is needed, the next conversion will be you losing material. And after that it will be much easier for him; the max DTC in the next phase will be shorter, the number of non-lost positions will be smaller, etc. If he can be swindled, it must be in the current phase. If he cannot be swindled, it does not matter what you do. If you expect perfect play, the only good 'move' in a losing position is an immediate resign. Anything else is a waste of time for no gain. The only reason to play on is that you hope for a swindle, and maximize the chances one will occur.

BTW, this doesn't only hold for end-games. Defending by DTM almost always leads to the worst possible move, also in the case of a checkmate found by search.
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: Almost perfect DTM tablebase

Post by syzygy »

hgm wrote: Wed Apr 15, 2020 12:58 pm
syzygy wrote: Wed Apr 15, 2020 12:27 pmDTM50 would have recognised the position as a cursed draw (just like DTZ50 does).
Not if the zeroing was 49 moves away with perfect DTZ50 play. Then it would see it as a loss, and might stupidly convert to an end-game which is 100% lost in at most 30 moves, which the opponent can impossibly bungle, instead of keeping the margin at 1 move that requires the opponent to find the only winning move for 20 moves in a row.
Agreed. DTZ50 seems the most useful when it comes to aiming for a 50-move draw.

Still, the advantage is limited. DTZ50 of the current position gives you no information about DTZ50 after a pawn move. DTC may help there but still not enough.
User avatar
hgm
Posts: 27837
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Almost perfect DTM tablebase

Post by hgm »

True, this is why I mentioned DTC rather than DTZ. With Pawns it is much less clear; advancing it doesn't necessarily make it easier to make the next advance.

But in principle one can build DTZ49, DTZ48, ... EGT, and for any position defend according to the lowest of those where the current position is still won (i.e. is a 'nearly-cursed win').

I don't know if there are end-games where this really buys you much; in end-games where the winning player has Pawns it is very difficult to achieve a 50-move draw. Perhaps if the defender can do a lot of semi-perpetual checking.
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: Almost perfect DTM tablebase

Post by syzygy »

hgm wrote: Wed Apr 15, 2020 3:41 pm But in principle one can build DTZ49, DTZ48, ... EGT, and for any position defend according to the lowest of those where the current position is still won (i.e. is a 'nearly-cursed win').
I once helped a correspondence player win a drawn position (I think it was KBBvKNP but am not sure) by building the DTZ51 and DTZ52 tables. The starting position was drawn under the 50-move rule but won under the 52-move rule. The opponent initially defended very well (even deviating from what Nalimov tables would have suggested at just the right moments) but then made a small error which turned the position in a win under the 50-move rule.
I don't know if there are end-games where this really buys you much; in end-games where the winning player has Pawns it is very difficult to achieve a 50-move draw. Perhaps if the defender can do a lot of semi-perpetual checking.
Example:
[d]6B1/3B4/5R2/6q1/P7/1k6/8/3K4 b - - 0 1
https://syzygy-tables.info/?fen=6B1/3B4 ... _b_-_-_0_1
User avatar
hgm
Posts: 27837
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Almost perfect DTM tablebase

Post by hgm »

Ah yes, that is a very spectacular example. The DTZ is enormous, but does its qualification as a blessed loss imply that in all of the successor phases the DTZ is < 100ply? Or can it also be 'doubly blessed'?

For positions like this it could be that subsequent phases do get faster. Because to escape the checking you would have to build some kind of fortress around your King with the other pieces, and once you have done that, the safety could be permanent, or at least stay very close, so that you can concentrate your moves on advancing the Pawn. So then it would also hold that when you want to achieve something, you better do it in the current phase.
User avatar
phhnguyen
Posts: 1442
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Almost perfect DTM tablebase

Post by phhnguyen »

syzygy wrote: Wed Apr 15, 2020 12:15 pm So to know whether a 7-piece position is winning, losing or drawn (or cursed), the engine needs to do only a single probe of a 7-piece WDL table. (It may in addition have to do some probes of 6-piece WDL tables if any direct captures are available.)

If the engine needs to know the DTZ value (which is only necessary when a TB root position has been reached), the probing code may have to do a 1-ply search to get to the "right" side of the DTZ table.
I become confused since your answer here is different from my thoughts. Could you explain:
- When searching (not on root) what should an engine do if a WDL table returns a curved win/loss? Should it probe deeper or accept them as sure win/loss?
- Similar for probing DTZ at root, what should an engine do when a DTZ table returns a curved win/loss?

Thanks
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: Almost perfect DTM tablebase

Post by syzygy »

phhnguyen wrote: Sun Apr 19, 2020 4:02 pm
syzygy wrote: Wed Apr 15, 2020 12:15 pm So to know whether a 7-piece position is winning, losing or drawn (or cursed), the engine needs to do only a single probe of a 7-piece WDL table. (It may in addition have to do some probes of 6-piece WDL tables if any direct captures are available.)

If the engine needs to know the DTZ value (which is only necessary when a TB root position has been reached), the probing code may have to do a 1-ply search to get to the "right" side of the DTZ table.
I become confused since your answer here is different from my thoughts. Could you explain:
- When searching (not on root) what should an engine do if a WDL table returns a curved win/loss? Should it probe deeper or accept them as sure win/loss?
In Stockfish this is dependent on the value of Syzygy50MoveRule.
If Syzygy50MoveRule is set to "true", a cursed win/loss is given the smallest possible positive/negative value.
If Syzygy50MoveRule is set to "false", a cursed win/loss is treated in the same way as a real win/loss.
- Similar for probing DTZ at root, what should an engine do when a DTZ table returns a curved win/loss?
If (cursed) winning, Stockfish will play one of the moves that minimises DTZ (if I am not mistaken)
This should work well if the 50-move rule will be exceeded in the current phase (against optimal play by the opponent) because the opponent will be forced to play accurately (and so is more likely to make a mistake).
It should also work well if the 50-move rule is expected to be exceed in the next phase (so after a pawn move or capture) because the next zeroing move will not e.g. give away a piece (if a bad zeroing move would lead to a cursed win, the current phase should be winning).

If (cursed) losing, Stockfish will play one of the moves that preserve the 50-move draw.
User avatar
phhnguyen
Posts: 1442
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Almost perfect DTM tablebase

Post by phhnguyen »

syzygy wrote: Fri Apr 24, 2020 3:20 am
phhnguyen wrote: Sun Apr 19, 2020 4:02 pm
syzygy wrote: Wed Apr 15, 2020 12:15 pm So to know whether a 7-piece position is winning, losing or drawn (or cursed), the engine needs to do only a single probe of a 7-piece WDL table. (It may in addition have to do some probes of 6-piece WDL tables if any direct captures are available.)

If the engine needs to know the DTZ value (which is only necessary when a TB root position has been reached), the probing code may have to do a 1-ply search to get to the "right" side of the DTZ table.
I become confused since your answer here is different from my thoughts. Could you explain:
- When searching (not on root) what should an engine do if a WDL table returns a curved win/loss? Should it probe deeper or accept them as sure win/loss?
In Stockfish this is dependent on the value of Syzygy50MoveRule.
If Syzygy50MoveRule is set to "true", a cursed win/loss is given the smallest possible positive/negative value.
If Syzygy50MoveRule is set to "false", a cursed win/loss is treated in the same way as a real win/loss.
- Similar for probing DTZ at root, what should an engine do when a DTZ table returns a curved win/loss?
If (cursed) winning, Stockfish will play one of the moves that minimises DTZ (if I am not mistaken)
This should work well if the 50-move rule will be exceeded in the current phase (against optimal play by the opponent) because the opponent will be forced to play accurately (and so is more likely to make a mistake).
It should also work well if the 50-move rule is expected to be exceed in the next phase (so after a pawn move or capture) because the next zeroing move will not e.g. give away a piece (if a bad zeroing move would lead to a cursed win, the current phase should be winning).

If (cursed) losing, Stockfish will play one of the moves that preserve the 50-move draw.
Thanks a lot for your info and explanation.

Just a few more questions:
1) "If (cursed) winning, Stockfish will play one of the moves that minimises DTZ ": does it mean by doing that there is still a risk of being drawn?
2) If an engine probes Syzygy right after capturing/pushing Pawn and see cursed winning/losing, can it consider them as sure winning/losing since 50-move-rule has just reset?
3) If 1 & 2 are correct, can the engine continue searching Syzygy until capturing/pushing Pawns to make sure the probe result is sure winning or sure draw?
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
Terje
Posts: 347
Joined: Tue Nov 19, 2019 4:34 am
Location: https://github.com/TerjeKir/weiss
Full name: Terje Kirstihagen

Re: Almost perfect DTM tablebase

Post by Terje »

phhnguyen wrote: Fri Apr 24, 2020 4:05 pm
syzygy wrote: Fri Apr 24, 2020 3:20 am
phhnguyen wrote: Sun Apr 19, 2020 4:02 pm
syzygy wrote: Wed Apr 15, 2020 12:15 pm So to know whether a 7-piece position is winning, losing or drawn (or cursed), the engine needs to do only a single probe of a 7-piece WDL table. (It may in addition have to do some probes of 6-piece WDL tables if any direct captures are available.)

If the engine needs to know the DTZ value (which is only necessary when a TB root position has been reached), the probing code may have to do a 1-ply search to get to the "right" side of the DTZ table.
I become confused since your answer here is different from my thoughts. Could you explain:
- When searching (not on root) what should an engine do if a WDL table returns a curved win/loss? Should it probe deeper or accept them as sure win/loss?
In Stockfish this is dependent on the value of Syzygy50MoveRule.
If Syzygy50MoveRule is set to "true", a cursed win/loss is given the smallest possible positive/negative value.
If Syzygy50MoveRule is set to "false", a cursed win/loss is treated in the same way as a real win/loss.
- Similar for probing DTZ at root, what should an engine do when a DTZ table returns a curved win/loss?
If (cursed) winning, Stockfish will play one of the moves that minimises DTZ (if I am not mistaken)
This should work well if the 50-move rule will be exceeded in the current phase (against optimal play by the opponent) because the opponent will be forced to play accurately (and so is more likely to make a mistake).
It should also work well if the 50-move rule is expected to be exceed in the next phase (so after a pawn move or capture) because the next zeroing move will not e.g. give away a piece (if a bad zeroing move would lead to a cursed win, the current phase should be winning).

If (cursed) losing, Stockfish will play one of the moves that preserve the 50-move draw.
Thanks a lot for your info and explanation.

Just a few more questions:
1) "If (cursed) winning, Stockfish will play one of the moves that minimises DTZ ": does it mean by doing that there is still a risk of being drawn?
2) If an engine probes Syzygy right after capturing/pushing Pawn and see cursed winning/losing, can it consider them as sure winning/losing since 50-move-rule has just reset?
3) If 1 & 2 are correct, can the engine continue searching Syzygy until capturing/pushing Pawns to make sure the probe result is sure winning or sure draw?
Cursed wins are draws if the opponent plays perfectly, regardless of what you do. If you probe a position and get result cursed win, this position is already a draw. Same for blessed loss, if you play perfectly it's a draw no matter what your opponent tries.