Page 1 of 2

Simple triple repetition handler

Posted: Sun Feb 21, 2016 10:41 am
by stegemma
Satana, in G6 tourney, often lose a lot of ELO points just because it fall in triple repetition while in advantage over its opponent. Because I haven't TT active (but I can enable position hash-key), now, I would like to implement a very simple repetition handler, like this one:

Code: Select all

at any node, just compare the position with the one at two nodes before: if it is the same position, then return a zero score
I would test this morning but anybody have some hint about some situation where this simple method will not works?

I already know that it would be a partial method... but it is better than having nothing, like now.

Re: Simple triple repetition handler

Posted: Sun Feb 21, 2016 11:29 am
by hgm
It will certainly not have any effect if you don't compare to the position four nodes before.

And this will actually solve the worst problem. I used something similar in my engine Usurpator II in the eighties. Except that it was not based on any position key, but on the last 4 moves being non-captures, and having the from- and to-square of the move 2 ply earlier swapped. It hardly ever fell into repeat cycles.

Most engines don't do this through the hash table, but just keep a stack of position keys, and run through it (in steps of 2, as you need same side to move to count as a repetition) upto the last irreversible move. Especially if you treat null moves as irreversible these will never be far away. In games without irreversible moves it would be better to keep a small hash table that can hold (say) 256 keys, which rehashes to the first available empty slot, to prevent you have to search all the way to the start of the game in every node.

Re: Simple triple repetition handler

Posted: Sun Feb 21, 2016 12:05 pm
by stegemma
Yes, of course it was 4 nodes and not 2. A second hash table would be better, of course, but I've already have troubles to make the principal one to work! :)

PS: I've corrected the value bug in satana, so the next monthly tourney it should give the correct "pv" line

Re: Simple triple repetition handler

Posted: Mon Feb 22, 2016 6:08 pm
by Fabio Gobbato
A simple way for an engine to handle repetitions is to not detect the 3rd repetition but to detect if a position is a repetition or not.
To do that you have only to find the current position between currentposition-4 and currentposition-50movecounter.
The function that detect the repetition is very fast because usually there are only few reversible moves between fifty move counter resets.

Re: Simple triple repetition handler

Posted: Tue Feb 23, 2016 9:56 am
by stegemma
Of course this would be limited to ply 6 or less (depending on the time control), because doing it at the leaves would be too much expensive. The idea of a cache could be good. of course, I can implement the simplest solution and then make my TT works correctly. It seems that any thing that I add to satana won't works: TT, quiescence and so on... I have to change dramatically my approach to engine programming; I must be more pragmatic and "professional".

Re: Simple triple repetition handler

Posted: Wed Feb 24, 2016 6:40 pm
by bob
stegemma wrote:Of course this would be limited to ply 6 or less (depending on the time control), because doing it at the leaves would be too much expensive. The idea of a cache could be good. of course, I can implement the simplest solution and then make my TT works correctly. It seems that any thing that I add to satana won't works: TT, quiescence and so on... I have to change dramatically my approach to engine programming; I must be more pragmatic and "professional".
I do this all the way to and including nodes with depth >= 1. Doing it in the q-search is almost free since any capture resets the 50 move counter and the loop will never execute anyway... In fact, when doing my single ply of checking moves followed by escaping check at the second ply (only) of q-search, I do it there as well...

Re: Simple triple repetition handler

Posted: Thu Feb 25, 2016 12:27 am
by op12no2
Does it make any sense to not check for reps if losing by a threshold - the idea being in such circumstances a draw is fine and it releases resources for a bit more searching... ?

Re: Simple triple repetition handler

Posted: Thu Feb 25, 2016 6:49 am
by bob
op12no2 wrote:Does it make any sense to not check for reps if losing by a threshold - the idea being in such circumstances a draw is fine and it releases resources for a bit more searching... ?
Not sure what you mean. Would you not want to choose a draw over being material behind??? If you don't check, you would not know it was possible...

Re: Simple triple repetition handler

Posted: Thu Feb 25, 2016 6:50 am
by bob
op12no2 wrote:Does it make any sense to not check for reps if losing by a threshold - the idea being in such circumstances a draw is fine and it releases resources for a bit more searching... ?
Not sure what you mean. Would you not want to choose a draw over being material behind??? If you don't check, you would not know it was possible...

Re: Simple triple repetition handler

Posted: Thu Feb 25, 2016 9:13 am
by op12no2
bob wrote: Not sure what you mean. Would you not want to choose a draw over being material behind??? If you don't check, you would not know it was possible...
Ah yes I see. Historically my very early Lozzas were walking into rep draws, so in my head the rep test is to avoid rep, but you can also look at it the other way as you say, to try and force one.