Syzygy and draw by repetition

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

basil00
Posts: 55
Joined: Thu Oct 22, 2015 2:14 am

Re: Syzygy and draw by repetition

Post by basil00 »

jdart wrote:I am still looking at it. I am using the Fathom library, which is a repackaging of the Stockfish code (https://github.com/basil00/Fathom). Apparently the library does not consider repetitions, so it has no way of knowing when scoring root moves whether any might play into a repetition.
That's correct, the Fathom tb_probe_root() does not consider repetitions. This is mainly because Fathom aims to be engine-independent.

There are two options for using Fathom 'safely' (avoid repetitions) in an engine in a winning position:
  1. Always play the DTZ-optimal move returned by tb_probe_root(). (this is the Gullgyzy approach).
  2. Use search() as normal, but call tb_probe_root() with a non-null "results" argument use this to filter drawing/losing root moves. But if a repetition occurs then fall-back to DTZ-optimal mode. Most engines seem to do something like this.
The first method is the simplest, and allows the engine to insta-move in TB positons, but leads to complaints about "unnatural play". That said, the second method can also lead to lame play, e.g. in some positions the engine will aimlessly shuffle pieces around until the 50-move draw approaches. Personally I prefer the former approach and don't care about so-called unnatural play.
User avatar
hgm
Posts: 28123
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Syzygy and draw by repetition

Post by hgm »

50-move-safe DTM is just as easy to build as naive DTM. But it only guarantees the recorded wins if you enter the tables with the ply counter at zero. Apart from artificially set-up positions, the relevant case where this occurs is when you swindle a fallible opponent in a drawn situation. The opponent might hold the draw very long, running up the ply count, and then blunder by making a reversible move into a lost position. Then you have to secure the win starting from a non-zero (and possibly very sub-optimal) ply count. Zeroing the counter might become the dominant concern in that case.

Playing according to DTZ in that case does not seem a very silly thing to do. Playing by "DTZ50-approved DTM" also is a good solution. Probing too close to the root in general is a bad idea. A 6-ply search in general still takes negligible time, so you might as well probe only from the 6-ply level, to plan around possible repetitions.
syzygy
Posts: 5647
Joined: Tue Feb 28, 2012 11:56 pm

Re: Syzygy and draw by repetition

Post by syzygy »

hgm wrote:50-move-safe DTM is just as easy to build as naive DTM. But it only guarantees the recorded wins if you enter the tables with the ply counter at zero.
No, it does not do that. Not if you store one DTM-value per position and if you want to be able to play out the mate using the table.

If you have a DTM table that gives correct information with 50-move counter == 0, then it does not give correct information for positions with 50-move counter > 0. This is not a problem of artificially set-up positions or suboptimally playing opponents but is simply inherent in DTM50. UNLESS you build a very bulky DTM50 table that stores information for each position and for each ply count.

A non-bulky DTM50 table might tell you that the current position is a mate in 60. This mate in 60 could be, for example, 50 moves until a capture and 10 more moves. Now both sides play a move and this time the table might tell you that the new position is a mate in 56: 50 moves until a capture and 6 more moves. Great, a shorter mate, but useless, because we only have 49 moves left to reach a pawn move or capture. The position is of course still won, but we don't know how.
User avatar
hgm
Posts: 28123
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Syzygy and draw by repetition

Post by hgm »

What I had in mind was building a DTM table starting from all winning conversions / zeroings, doing 50 retrograde cycles. That would at least guarantee every position marked as DTM=N would have a move leading to a won position with DTM=N-1 two ply later. It could indeed be that there are also other moves to DTM=N-1, which are not won if you go there because the ply counter is too high. But DTZ50 probing would enable you to avoid those.
syzygy
Posts: 5647
Joined: Tue Feb 28, 2012 11:56 pm

Re: Syzygy and draw by repetition

Post by syzygy »

hgm wrote:What I had in mind was building a DTM table starting from all winning conversions / zeroings, doing 50 retrograde cycles.
Yes, and as I pointed out such a table has far more limitations than what you were suggesting.

If you're using DTZ50 anyway as a safeguard, there seems to be no good reason for using DTM50 over DTM. The DTM table will deliver sensible moves and the DTZ50 table can be used to check for the relatively rare case where a different move saves the win (or achieves the draw).
User avatar
hgm
Posts: 28123
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Syzygy and draw by repetition

Post by hgm »

I wasn't suggesting anything, other than that a position is a win when the table says it is a win and the ply counter is zero. Normal DTM does not have that property.

I would expect DTM tables that avoid conversion to cursed wins to lead to somewhat more natural play in combination with DTZ50 than DTM tables that don't avoid such conversions.
syzygy
Posts: 5647
Joined: Tue Feb 28, 2012 11:56 pm

Re: Syzygy and draw by repetition

Post by syzygy »

hgm wrote:I wasn't suggesting anything, other than that a position is a win when the table says it is a win and the ply counter is zero. Normal DTM does not have that property.
hgm wrote:Apart from artificially set-up positions, the relevant case where this occurs is when you swindle a fallible opponent in a drawn situation.
Ok, not a suggestion. Just wrong information.
jdart
Posts: 4375
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Syzygy and draw by repetition

Post by jdart »

I am doing 2. but not with the addition "But if a repetition occurs then fall-back to DTZ-optimal mode.". So that is likely the problem.

Btw.: I have a pull request pending against Fathom, for a different issue (problems compiling on a non-x86 architecture).

--Jon
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Syzygy and draw by repetition

Post by jwes »

What would happen if you used standard DTM tables and always made the move with the shortest DTM that is also a win in the WLD table?
Dirt
Posts: 2851
Joined: Wed Mar 08, 2006 10:01 pm
Location: Irvine, CA, USA

Re: Syzygy and draw by repetition

Post by Dirt »

jwes wrote:What would happen if you used standard DTM tables and always made the move with the shortest DTM that is also a win in the WLD table?
That could work, but the only publicly available six piece DTM files I am aware of (Nalimov) are huge. Gaviota tablebases, since they are only five piece, are of reasonable size, but cover only a small part of the problem. You still wouldn't know for certain how far you are from mate, either.

I'm not seeing sufficient benefit to make it worth the trouble.
Deasil is the right way to go.