lichess-org / lila

♞ lichess.org: the forever free, adless and open source chess server ♞
https://lichess.org
GNU Affero General Public License v3.0
15.67k stars 2.28k forks source link

Clamining draw for threefold repetition from custom position #7009

Closed dlbbld closed 4 years ago

dlbbld commented 4 years ago

White gets draw claim from initial position after below moves, which is correct:

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]

1. Nf3 Nf6 2. Ng1 Ng8 3. Nh3 Nh6 4. Ng1 Ng8

White gets no draw claim from custom position after below moves, which is incorrect:

[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[FEN "4k3/8/8/8/8/4P3/8/4K3 w - - 0 1"]

1. Kd2 Kd7 2. Ke1 Ke8 3. Kf2 Kf7 4. Ke1 Ke8
dlbbld commented 4 years ago

Can you please check this? It looks like it ignores the initial position, so miscounting by one.

For another example, I take the game between Fischer and Petrosian from 1971 in Wikipedia (https://en.wikipedia.org/wiki/Threefold_repetition#Fischer_versus_Petrosian,_1971).

In this game, there is a threefold repetition per Wikipedia after 30.Qe2, 32.Qe2, then 34.Qe2. When the game is continued starting after 30. Qe2 was played, after 34. Qe2 no draw claim is offered, so the threefold repetition is not detected.

When I play through this game from beginning with a friend (ok, I don't have always time to do so, but tried), then after 34.Qe2 the draw can be claimed. The threefold repetition works fine in normal games; this only happens when continuing from a position.

When the game is continued one move earlier, starting after 29... Kh7, after 34.Qe2 the threefold repetition can be claimed. But this is wrong, as the initial position has all the necessary information (en passant information and castling rights) to determine later threefold repetition from this point onwards, so there is no need to start earlier. It looks as it ignores the initial position for the threefold count, so when starting one move earlier, only then the example works.

The first examples are, however, easier, this is provided as a second example.

niklasf commented 4 years ago

Via next scalachess update: https://github.com/ornicar/scalachess/pull/204