I try to verify my repetition detection.
This is what says the FIDE :
The game is a draw if a position occurs (at least) three times during the game. (Intervening moves do not matter.) It must be claimed by the player with the turn to move. The claim is made:
(a) If the position is about to appear for the third time, the player making the claim first writes their move on their scoresheet and notifies the arbiter that they intend to make this move.
or
(b) If the position has just appeared for the third time, the player with the move can claim the draw.
Positions are considered the same if
(1) the same player has the move,
(2) pieces of the same kind and color occupy the same squares, and
(3) the possible moves of all the pieces are the same.
In search it is better to assume a draw in the first repetition. Waiting for the second just wastes depth. For repetion of positions from the game it is a different matter. But I don't think it would make any difference what you do Elo-wise.
Indeed it would be better to lop in steps of 2 through the history.
A second repetition is also not a draw unless one of the sides claim it(if you consider the fide rules and not engine-engine rules).
The following happened in a human OTB game between X and Y(I guess it happened more than one time in the history).
It was important for X to win in a game against Y but Y played a line that force a repetition(otherwise Y is going to get a clear advantage).
What X should do in order to maximize the chances to win?
Not repeating the position is bad and repeating the position is going to allow Y to claim a draw.
The solution:
X thought for a long time and finally played the repetition move without claiming a draw so Y hoped to win thanks to the time advantage on the clock and did not repeat the position and continued to play and finally X won in the relevant game.
hgm wrote: ↑Sat Feb 05, 2022 10:32 am
Indeed it would be better to lop in steps of 2 through the history.
I just feed all the positions from the history to the TT with a score of 0 and protect them against being overwritten. Because I do a TT lookup anyway checking for repetitions is now free. No loops over the history during the search necessary.
Minimal Chess (simple, open source, C#) - Youtube & Github Leorik (competitive, in active development, C#) - Github & Lichess
You can use TT instead of IID move for move ordering but TT move may lead to a position where chance of a repetiton draw is higher. For TT entries were stored with different game history. So in fact they are polluted. Best not to use TT at all but IID searches are nor for free.
hgm wrote: ↑Sat Feb 05, 2022 10:32 am
Indeed it would be better to lop in steps of 2 through the history.
I just feed all the positions from the history to the TT with a score of 0 and protect them against being overwritten. Because I do a TT lookup anyway checking for repetitions is now free. No loops over the history during the search necessary.
That is what I do in micro-Max too. But only for positions in the game history. To make it fool-proof you would also have to store all positions currently being searched this way, until they are finally overwritten by the score from that search. This could be problematic in multithreaded searches.
Carbec wrote: ↑Sat Feb 05, 2022 9:14 am
I don't understand why it returns true if only 2 repetitions, and not 3.
Thanks
Philippe
Better would be to iterate in steps of 2, yes.
Regarding the return after 2, it's simple:
if a repetition of the position leads to a best move, then the engine goes for a draw, it'll repeat. There's no need to go beyond the first repetition, as the first repetition has conformed it's a best move anyway.
hgm wrote: ↑Sat Feb 05, 2022 10:32 am
Indeed it would be better to lop in steps of 2 through the history.
I just feed all the positions from the history to the TT with a score of 0 and protect them against being overwritten. Because I do a TT lookup anyway checking for repetitions is now free. No loops over the history during the search necessary.
But being able to repeat a history position neither guarantees a draw nor prevents you from still being able to win.
Repeating an already repeated history position does guarantee a draw, so what you could do is put those in the TT as draw.
Carbec wrote: ↑Sat Feb 05, 2022 9:14 am
I don't understand why it returns true if only 2 repetitions, and not 3. There surely be a good reason,
but I don't see it.
A move was just executed on the board. If this move causes a three-fold repetition, the game is a draw. Therefore the position you have on the board NOW, after executing the move, is the THIRD repetition, and thus you look for two repetitions in the past. If you'd look for 3 repetitions in the past, the one on the board would be the fourth.