Turning off 50-move draw rule in Stockfish & other engines

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

jp
Posts: 1470
Joined: Mon Apr 23, 2018 7:54 am

Turning off 50-move draw rule in Stockfish & other engines

Post by jp »

Is there a quick and easy way to hack the Stockfish (or other engines') code so that the 50-move draw rule can be turned off or changed (e.g. to 100 moves)? If so, can you please post here enough details that we can do it?
(Ditto for the threefold repetition rule.)


The motivation is both to look at cursed wins and to see if this helps SF find long wins it currently fails to find that still have DTZ <=100.


e.g.
Zenmastur wrote: Tue Mar 03, 2020 9:36 pm If should be noted that it's a COMPLETE waste of time to try to analyze this with ANY engine that enforces the 50-move-rule. <snip>

The problem is that a mate when it's first found is likely to be very long, MUCH longer than the minimum length mate. Then, with additional searching, the mate gets shortened when the engine finds better lines of play. This can NEVER happen if the 50-move-rule is enforced and the first mate found is over 50 moves long.

So, even if the mate is a mate in 49 AND the engine first finds a mate in 73 (for instance), instead of refining the line of play to achieve a shorter mate the engine will disregard the line of play because its over 50 moves long. If it ever finds the mate in 49, it will be by pure luck.

It would be nice if they would put an option to disable the 50-move rule for analysis. But, I'm not holding my breath! So, in the mean time, it's a waste of time to try to analyze positions like this. It's not that Stockfish can't solve it, it's prevented from solving it because of the 50-move-rule.
Uri Blass wrote: Wed Mar 04, 2020 6:51 pm If you ignore the 50 move rules things are easier because there are no misleading draw scores by the 50 move rule to hide mates but I think that there still may be a problem of draw score by repetition that is not correct in the hash table because in another line there is no repetition so I suspect that there may be mates that stockfish never find even if you ignore the 50 move rule.

If the last case never happen in stockfish then it may be interesting to understand why.
User avatar
Ovyron
Posts: 4556
Joined: Tue Jul 03, 2007 4:30 am

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by Ovyron »

Yeah, in:

position.cpp

Find all instances of this code:

Code: Select all

  st->rule50++;
Change them to this:

Code: Select all

  st->rule50 = 0;
Now Stockfish would not increase it anymore.

SPOILER ALERT - This will not correct the observed behavior because it's not caused by this.
User avatar
Ovyron
Posts: 4556
Joined: Tue Jul 03, 2007 4:30 am

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by Ovyron »

For three-fold repetition this should be the relevant part:

position.cpp

Code: Select all

  // Draw by repetition? 
  StateInfo* stp = st;
  for (int i = 2, e = Min(st->rule50, st->pliesFromNull); i <= e; i += 2)
  {
      stp = stp->previous->previous;

      if (stp->key == st->key)
          return true; // Draw at first repetition
  }
Changing "true" to "false" in the end would make Stockfish blind to repetitions.
jp
Posts: 1470
Joined: Mon Apr 23, 2018 7:54 am

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by jp »

Ovyron wrote: Sun Mar 15, 2020 6:33 pm position.cpp

Code: Select all

 ...
I'm wondering whether all those lines can just be commented out, or whether that'll leave some variable dangling ill-defined.

Ovyron wrote: Sun Mar 15, 2020 6:33 pm SPOILER ALERT - This will not correct the observed behavior because it's not caused by this.
The engine's behavior will surely change, because you can see its output hanging around not going beyond move 49.

Whether that (presumably differently shaped analysis tree) ever turns a failure into a success (or vice versa) I don't know. It might behave "better" and still fail if the problem is too difficult. Like all claims, it needs to be tested. (But for sure you'll need changes to find cursed wins.)
Zenmastur
Posts: 919
Joined: Sat May 31, 2014 8:28 am

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by Zenmastur »

Ovyron wrote: Sun Mar 15, 2020 6:33 pm Yeah, in:

position.cpp

Find all instances of this code:

Code: Select all

  st->rule50++;
Change them to this:

Code: Select all

  st->rule50 = 0;
Now Stockfish would not increase it anymore.

SPOILER ALERT - This will not correct the observed behavior because it's not caused by this.
SPOILER ALERT - Removing 50-move-rule enforcement WILL change the behavior of the program anytime it finds a mate/capture/pawn push past the 50 move limit. To suppose otherwise is pure stupidity on your part!
Only 2 defining forces have ever offered to die for you.....Jesus Christ and the American Soldier. One died for your soul, the other for your freedom.
jp
Posts: 1470
Joined: Mon Apr 23, 2018 7:54 am

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by jp »

Zenmastur wrote: Sun Mar 15, 2020 9:48 pm SPOILER ALERT - Removing 50-move-rule enforcement WILL change the behavior of the program anytime it finds a mate/capture/pawn push past the 50 move limit.
Can you make changes and try it out to see? (I hope the others with fast machines will be interested too.)
Joerg Oster
Posts: 937
Joined: Fri Mar 10, 2006 4:29 pm
Location: Germany

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by Joerg Oster »

You might give Moonfish a try. https://github.com/joergoster/Moonfish

If you set "Syzygy50MoveRule" to false, this will also switch it off for the search.
Jörg Oster
User avatar
Ovyron
Posts: 4556
Joined: Tue Jul 03, 2007 4:30 am

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by Ovyron »

Zenmastur wrote: Sun Mar 15, 2020 9:48 pmSPOILER ALERT - Removing 50-move-rule enforcement WILL change the behavior of the program anytime it finds a mate/capture/pawn push past the 50 move limit. To suppose otherwise is pure stupidity on your part!
Of course. I'm talking about the problem you're trying to solve by changing that behavior. Will the change help solving the problem? I suppose you'll find out soon enough...
User avatar
MikeB
Posts: 4889
Joined: Thu Mar 09, 2006 6:34 am
Location: Pen Argyl, Pennsylvania

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by MikeB »

jp wrote: Sun Mar 15, 2020 2:03 pm Is there a quick and easy way to hack the Stockfish (or other engines') code so that the 50-move draw rule can be turned off or changed (e.g. to 100 moves)? If so, can you please post here enough details that we can do it?
(Ditto for the threefold repetition rule.)


The motivation is both to look at cursed wins and to see if this helps SF find long wins it currently fails to find that still have DTZ <=100.


e.g.
Zenmastur wrote: Tue Mar 03, 2020 9:36 pm If should be noted that it's a COMPLETE waste of time to try to analyze this with ANY engine that enforces the 50-move-rule. <snip>

The problem is that a mate when it's first found is likely to be very long, MUCH longer than the minimum length mate. Then, with additional searching, the mate gets shortened when the engine finds better lines of play. This can NEVER happen if the 50-move-rule is enforced and the first mate found is over 50 moves long.

So, even if the mate is a mate in 49 AND the engine first finds a mate in 73 (for instance), instead of refining the line of play to achieve a shorter mate the engine will disregard the line of play because its over 50 moves long. If it ever finds the mate in 49, it will be by pure luck.

It would be nice if they would put an option to disable the 50-move rule for analysis. But, I'm not holding my breath! So, in the mean time, it's a waste of time to try to analyze positions like this. It's not that Stockfish can't solve it, it's prevented from solving it because of the 50-move-rule.
Uri Blass wrote: Wed Mar 04, 2020 6:51 pm If you ignore the 50 move rules things are easier because there are no misleading draw scores by the 50 move rule to hide mates but I think that there still may be a problem of draw score by repetition that is not correct in the hash table because in another line there is no repetition so I suspect that there may be mates that stockfish never find even if you ignore the 50 move rule.

If the last case never happen in stockfish then it may be interesting to understand why.
Stockfish , as do many engines, have a checkbox to turnoff 50 move rule enforcement.
# stockfish
Stockfish 140320 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
uci
id name Stockfish 140320 64 POPCNT
id author T. Romstad, M. Costalba, J. Kiiski, G. Linscott

option name Debug Log File type string default
option name Contempt type spin default 24 min -100 max 100
option name Analysis Contempt type combo default Both var Off var White var Black var Both
option name Threads type spin default 1 min 1 max 512
option name Hash type spin default 16 min 1 max 131072
option name Clear Hash type button
option name Ponder type check default false
option name MultiPV type spin default 1 min 1 max 500
option name Skill Level type spin default 20 min 0 max 20
option name Move Overhead type spin default 30 min 0 max 5000
option name Minimum Thinking Time type spin default 20 min 0 max 5000
option name Slow Mover type spin default 84 min 10 max 1000
option name nodestime type spin default 0 min 0 max 10000
option name UCI_Chess960 type check default false
option name UCI_AnalyseMode type check default false
option name UCI_LimitStrength type check default false
option name UCI_Elo type spin default 1350 min 1350 max 2850
option name SyzygyPath type string default <empty>
option name SyzygyProbeDepth type spin default 1 min 1 max 100
option name Syzygy50MoveRule type check default true
option name SyzygyProbeLimit type spin default 7 min 0 max 7
uciok

If you using stockfish under GUI, the GUI also must be able to turn the 50 move off ( usually, since most GUIs on by default). Older versions of Winboard/xBoard, which use polyglot, must also use a hacked version of Polyglot since polyglot also enforces the 50 move rule, which I have if you need it.
Image
jp
Posts: 1470
Joined: Mon Apr 23, 2018 7:54 am

Re: Turning off 50-move draw rule in Stockfish & other engines

Post by jp »

Joerg Oster wrote: Sun Mar 15, 2020 10:35 pm You might give Moonfish a try. https://github.com/joergoster/Moonfish

If you set "Syzygy50MoveRule" to false, this will also switch it off for the search.
MikeB wrote: Sun Mar 15, 2020 10:57 pm Stockfish , as do many engines, have a checkbox to turnoff 50 move rule enforcement.
...
option name Syzygy50MoveRule type check default true
...

If you using stockfish under GUI, the GUI also must be able to turn the 50 move off ( usually, since most GUIs on by default). Older versions of Winboard/xBoard, which use polyglot, must also use a hacked version of Polyglot since polyglot also enforces the 50 move rule, which I have if you need it.
Can you clarify?

Descriptions of Syzygy50MoveRule are like this:
Syzygy50MoveRule
Disable to let fifty-move rule draws detected by Syzygy tablebase probes count as wins or losses. This is useful for ICCF correspondence games.
Does it turn off all 50-move rule enforcement, even if no Syzygy tablebases (no tablebases of any sort) are used (or it's far from any TB position)? That's what's wanted.