Two fold or three fold repetition?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Two fold or three fold repetition?

Post by Henk »

If my engine only checks for two fold repetition then it miscalculates the position value for it assumes opponent will play same move again in the second identical opposition.

But a clever engine has learned that the move played was a mistake (or just played to win time) so it plays a better move which has a better score.

If my engine checks for three fold repetition instead of two fold repetion and being in a won position then after second position is encountered opponent may play a move which is a forced line and my engine has no option than to play the forced move leading to three fold repetition which it wanted to avoid.

So what to do?


Actually I don't know what happened. But position below ended in a draw. g4-h4 is a forced move. Game continued: g4-h4, g3-a3, h4-g4, a3-g3 etc. So h4-g4 is a blunder. But apparently it recognizes it too late. Thinking it can still play an alternative move after Rg3 perhaps.

[d]4k3/4p3/3bN1p1/6P1/3B2K1/6r1/8/5R2 w - - 83 116
brianr
Posts: 536
Joined: Thu Mar 09, 2006 3:01 pm

Re: Two fold or three fold repetition?

Post by brianr »

FWIW I follow Crafty's approach and count 3 reps at the root and only 2 during the search as draws.
pedrojdm2021
Posts: 157
Joined: Fri Apr 30, 2021 7:19 am
Full name: Pedro Duran

Re: Two fold or three fold repetition?

Post by pedrojdm2021 »

my engine just avoids repetitions all the way, and it plays quite good,

i do it the same as the cpw-engine does it, it's quite simple to implement, see:

https://github.com/nescitus/cpw-engine/ ... #L651-L659

And then in your search function return draw score if you found repetition:

Code: Select all

if (ply > 0 && is_repetition()) return 0;
Jakob Progsch
Posts: 40
Joined: Fri Apr 16, 2021 4:44 pm
Full name: Jakob Progsch

Re: Two fold or three fold repetition?

Post by Jakob Progsch »

Henk wrote: Tue Jul 13, 2021 5:22 pm If my engine only checks for two fold repetition then it miscalculates the position value for it assumes opponent will play same move again in the second identical opposition.
But you should have seen the forced line the first time it was available? The position having repeated once doesn't really factor into this? If I don't see that line and think the opponent will repeat that's not because there is an issue with the repetition it's because I didn't see the forced line in the first place.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Two fold or three fold repetition?

Post by Sven »

I count a twofold repetition as a draw if the repeated position belongs to the current search tree, i.e. the distance to it is <= the current distance to the root. Otherwise I would ignore that the engine could find a better move than the one played in the game and could therefore avoid a repetition draw.
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
User avatar
Kotlov
Posts: 266
Joined: Fri Jul 10, 2015 9:23 pm
Location: Russia

Re: Two fold or three fold repetition?

Post by Kotlov »

two
Eugene Kotlov
Hedgehog 2.1 64-bit coming soon...
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Two fold or three fold repetition?

Post by Henk »

Again two fold repetition draw. White did not see that Bf2 means a draw.
Can't reproduce it. So it's transposition table.
Maybe clear transposition table before search?
Add MoveCount to depth when storing entry?

Move history changed so all entries may be polluted.

[pgn]
[Event "?"]
[Site "?"]
[Date "?"]
[Round "-"]
[White "?"]
[Black "?"]
[Result "*"]
[FEN "1k3r2/1P5R/6p1/4p3/6PP/8/P4b2/1R5K b - - 1 1"]
[SetUp "1"]

1... e4 2. Rb5 Ba7 3. Rb1 Bf2 4. Rb5 Ba7 5. Rb1
*
[/pgn]
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: Two fold or three fold repetition?

Post by Henk »

First time or second time when position with bishop on f2 was encountered (after e5e4 or Tb1 ) two fold repetition condition was not valid and that value had been stored in the TTable.

By the way my futility pruning does not count two fold repetition draws as well. So it may discard moves in a bad position that made a draw.
User avatar
lithander
Posts: 880
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Two fold or three fold repetition?

Post by lithander »

I score every move that leads to a repetition as worth zero because it leads towards a draw. Don't care if it's two or threefold as I don't know what practical difference it would make?
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
amanjpro
Posts: 883
Joined: Sat Mar 13, 2021 1:47 am
Full name: Amanj Sherwany

Re: Two fold or three fold repetition?

Post by amanjpro »

Two fold repetition in practice should be a bit faster, because you will have smaller search trees... I do like Sven, I have two fold repetition for current ply searches, and three fold for played moves