Michel wrote:This discussion came up on the Stockfish developers forum.
https://chessprogramming.wikispaces.com/Repetitions quotes John Stanback about his implementation in Zarkov
If the count is 2, then this is the third repetition and a draw score is returned. If the count is 1 and the current_ply > root_ply+2 then a draw score is also returned. This avoids problems that can occur if the program thinks that a move at the root leads to a draw (due to a single repetition) when the opponent may vary, but it also lets the program treat repeated positions in the search as draws which helps a lot.
I think that the claim that the root position should be excluded from the two fold repetition rule is incorrect. If one of the players can force a repetition in search then it will be able to force a second repetition. The root position is in no way special in this regard.
Comments?
I was in that r.g.c.c discussion way back. What I remember John saying was that to count as a repetition, the position either had to be repeated three times overall, or repeated twice inside the current search.
That has 3 cases.
1. two repetitions in the game history (before the root move) means the next repetition is an actual draw, no escape.
2. one repetition in the game history, the first repetition in the search is NOT scored as a repetition, but the second one would be.
3. no repetition in the game history, the first repetition in the search IS scored as a repetition, even though it is not proven to be correct yet.
That was an attempt to address a pretty simple problem. With one position in the game history, any repeat (for those programs that just count 2 repetitions as a draw) appears to be a draw. But on some occasions you actually need to walk THROUGH the first repetition to escape a draw. But since any repetition is a draw, your program may well choose to go the wrong way.
An example. Your king is on e8, white has connected rooks on h7 and g7. You have a bishop that attacks the square a7. White checks with Rge7, and you go to f8. White checks with Ref7 and you go to g8. When white plays Rfg7 you see a 2-fold rep and think it is a draw. You move to f8. Now white plays Rgf7 and you have two choices. BOTH appear to lead to a draw since moving the K to e8 repeats, and moving it to g8 repeats (note one position is in game history, one is in search, but that is 2x which is treated just like 3x by most everyone. If you go to g8 is will end in a real draw.
If you use stanback's idea, you will play Ke8 and not score it as a draw, because one position is in the game history, one is in the current search, which is not enough. You need 2 in search or 3 if two of them are in history. You score Ke8 as safe, and on Rfe7 you have two choices. Kf8 gives a 3rd repeat, Kd8 does not, you get to a8 where the checks stop since you have a7 covered.
Now, more info.
The reason we score 2-fold as a draw is to recognize draws sooner. In the above position without the bishop, it would take you a LOT of searching to realize that you are winning, but your opponent can force a 3-fold rep, because if you start on a8, the king can walk all the way to g8, back to a8 back go g8 and back to a8 before the 3-fold rep triggers. DEEP search. Scoring the 2-fold rep as a draw catches it much sooner.
But it has a drawback, because you were originally checked, you went the wrong way not knowing, and now you can't get back to the original square and go the other way because your search is saying all of those positions are drawn.
But there is another side of the story. Twice in search or once in search + twice in history has its own problem. Sometimes repeating twice in search is too deep to find, particularly when you search a deep PV to win material and overlook an opponent's draw. "The crazy rook" is an example where you inadvertently make a move that stalemates your opponent, except that he has one rook that can move, nothing else. And he calmly moves it next to your king and checks you. You can't capture as it is a stalemate. All you can hope for is that you can search deeply enough to see the rep. It is easier to see 2 than 3.
I have not seen (or at least don't remember) the root+2 idea, although it might have come up. I tried this back then as the r.g.c.c discussion will show, but I didn't like the way it tended to delay detecting repetitions. Today, two repeats = draw from the search's perspective, although I require 3 to actually claim a repetition and end the game.
I agree with your reasoning. There is also an issue with search inconsistency and hashing, but that's best left to another topic.