lichess.org
Donate

Triple Repetition Implementation

It's a bit strange, as I've tested with a few easy king and pawn positions against myself, and in those positions it does seem to correctly account for who is to move.

However, I played out the game in question starting with Kxf6, and it does indeed offer white the chance to claim threefold after the final Rd5.

I'll do some more testing to see if I can recreate this in other positions.
Hmm, so far I've not been able to reproduce that behavior. In all the positions I've tried, the side to move is correctly accounted for.

Since it relies on a hash, it is quite possible that the representation of the position correctly includes all the relevant information, but that in this particular case, two different positions get the same hash.

That's highly improbable in any given case, but I guess if you play enough positions it might happen.
Hmm...odd, as I've confirmed a few times that I don't get a threefold draw as an option if I repeat a position in a king and pawn ending with the last identical position arising after triangulation (so it's the same piece configuration, just with a different side to move).

If what you say is correct, then I should be able to get threefold in that scenario, unless I'm grossly misunderstanding it.
Just to make that clear, I'm not saying that according to the rules of chess I should be able to get threefold repetition, but that according to how you suggest the code works, I would be able to claim threefold in lichess.

I realized right after I typed it that I used the dreadful "should" word, which is all too easy to misread :)
it has to be;
-the same persons turn
-if catstleing was availble it has to be availble again
I read many different opinions here. I'll need a single, clear set of rules, backed up by official (FIDE) sources.
Article 9.2 at http://www.fide.com/fide/handbook.html?id=171&view=article

The game is drawn, upon a correct claim by a player having the move, when the same position for at least the third time (not necessarily by a repetition of moves):
- is about to appear, if he first writes his move, which cannot be changed, on his scoresheet and declares to the arbiter his intention to make this move, or
- has just appeared, and the player claiming the draw has the move.
Positions are considered the same if and only if the same player has the move, pieces of the same kind and colour occupy the same squares and the possible moves of all the pieces of both players are the same. Thus positions are not the same if:
- at the start of the sequence a pawn could have been captured en passant.
- a king or rook had castling rights, but forfeited these after moving. The castling rights are lost only after the king or rook is moved.
The way that I've always tested for threefold repetition programatically has been to use the FEN without the move number and half move clock. That includes the board position, color to move, castling, and en passant. Per the FIDE laws in the post above (full version also in pdf form www.fide.com/FIDE/handbook/LawsOfChess.pdf) that must all be consistent.

Out of curiosity (I don't remember claiming a triple repetition yet), is there a button that pops up that encourages a player to claim a draw?
One subtlety about castling rights - for the purposes of threefold repetition, castling is considered to be allowed if it is prevented only by the side to move either being currently in check or if the king would pass through check.

So in an entirely hypothetical situation where the f1 square is attacked but neither the white king nor the h1 rook have moved, castling is "allowed" for threefold purposes. If the same board position arises later but the white king has moved, the position is no longer the same for threefold purposes.

There have been some interesting debates on the uschess forums about things like this, but it basically comes down to comparing the FEN (minus the numbers) to determine if the position is the same.

This topic has been archived and can no longer be replied to.