FreeRepublic wrote on 01/13/26 at 13:21:21:
Do engines recognize triple repetition and a draw?
I suppose different engines handle it differently. Traditionally draw
claims are left to the GUI, but engines can and commonly do detect repetitions. Crafty for instance even had code to avoid repetitions in the opening book.
FreeRepublic wrote on 01/13/26 at 13:21:21:
It seems to me that if the best move it can find is to repeat, it should move on to a second best move
In fact just yesterday I was reviewing some openings analysis and came across the following note to myself.
21...Be3+?? (+-)
21...Bh4! (-+)
21...Qg5+ 22.Kd1 Qg1+ 23.Kd2 Bh4
Quote:weird that Stockfish15 gives 21...Qg5+ as best, only to repeat and then play the correct 23...Bh4 (2025.02.20)
Stockfish15 ordered them top
21...Qg5+, 2nd
21...Bh4 but looking at the PV it switched to
...Bh4 on move 23. So it is handling the repetition, but in a non-intuitive way, because it is allowing the first repetition, only avoiding the second repetition. Just now I re-ran the same position with Stockfish17 to see what is going on. Because the repetition has four useless ply, the effective depth of the repetition line is four less than the non-repetition line. So the eval of
...Qg5 at depth N is the same as the eval of
...Bh4 at depth (N-4). When the eval of
...Bh4 is increasing with depth,
...Bh4 is preferred. When the eval of
...Bh4 is decreasing with depth,
...Qg5 is preferred.
Edited: Oops. I used increasing/decreasing in an inexact way. By increasing I meant more favorable to black (more top move), decreasing meant less favorable to black.
This was an easy case to analyze because I already knew the answer, and the repeating variation is quite short.
...Bh4 | ...Qg5+ | overall
depth eval | depth eval | top
---------------+-----------------+---------
32 -6.03 | 32 |
36 -5.95 | 36 -6.03 | ...Qg5+
40 -6.11 | 40 -5.95 | ...Bh4
The general case of repetitions is tricky. For example, what if the overall eval is close to zero and switches from positive to negative with increasing depth? Then we switch from wanting to avoid a repetition to wanting to achieve it. Credit to the programmers for handling the many edge cases correctly. It's up to the human to notice the repetition in the PV and interpret the engine eval in a way that makes sense to the human.