# Rules: How does right to castle and en passant get considered for the purpose of calculating a threefold repetition?

I'm writing a chess app, and have some questions regarding the intricacies of the threefold repetition rules.

As of 2018, the FIDE handbook has this to say about what constitutes identical positions for the purpose of threefold repetitions.

9.2.2 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:

9.2.2.1 at the start of the sequence a pawn could have been captured en passant

9.2.2.2 a king had castling rights with a rook that has not been moved, but forfeited these after moving. The castling rights are lost only after the king or rook is moved.

This question and `Rule 9.2.2.2` address calculating right to castle. Looking at both, my conclusion is that it only checks whether the relevant piece(s) have moved; other restrictions like check, obstructions, or even whether the relevant rook was captured are not considered (though the last is probably irrelevant).

The same rule also seems to specify that each player starts with 2 castling rights- one for kingside and one for queenside- rather than 3- one for the king and one for each rook.

So the first part of my question is, am I correct in my assessment of how the right to castle affects whether positions are identical?

For the second part of my question, there seems to be a little ambiguity regarding en-passant.`Rule 9.2.2.1` is clear about the case of if a pawn can legally en-passant one turn and can't during a later turn, then the positions aren't identical even if everything else is the same.

But there are two cases with en passant that aren't clear, or at least, should be clarified in light of how right to castle is calculated.

First, say a pawn moves two squares, thus making it capturable by en-passant, but there's no enemy pawn next to its destination. Does the fact that it would have been vulnerable to en passant make the position non-identical to another otherwise identical position a few turns later?

Second, say a pawn moves two squares, landing next to an enemy pawn, giving that pawn the right to en-passant, but where exercising the right to en-passant would expose the king (thus barring the otherwise legal en passant). Would that position be considered different from an otherwise identical position a few turns later?

• This is a good question. It might be a duplicate, though. – thb Nov 18 '18 at 22:50
• I don't think it is. The question you referenced only mentions en passant. This is the only question, as far as I could tell, which mentions both special cases in one question. – SarcasticSully Nov 19 '18 at 1:55
• The answer is there "...the possible moves of all the pieces of both players are the same." So if there is a change in the possible moves it does not count toward the repetition. – Ywapom Nov 19 '18 at 22:26
• @Ywapom that's what I initially thought. But considering how it works around castling, which accounts for more than currently possible move, it's worth at least clarifying. – SarcasticSully Nov 19 '18 at 22:35
• So the answer is castling does effect the repetition but only if it is possible to castle in one of the positions being considered for 3-fold as that would change the possible moves? But it is possible to claim 3 fold in positions where castling in the future has not been ruled out in some and is allowed in others but in all of them it is not possible on that turn say due to a piece being in the way? – silent-tiger Nov 20 '18 at 1:21

You have identified the correct rule governing these situations. 9.2.2 is the relevant clause that applies; 9.2.2.1 and 9.2.2.2 are just clarifications of this rule.

1) Your interpretation of castling rights is correct. Each player has two castling rights which are irrespective of the current board position. The right to castle short is lost only when the king or h-rook moves for the first time. The right to castle long is lost only when the king or a-rook moves for the first time. Other restrictions are irrelevant.

2) If a pawn moves two squares without an enemy pawn ready to capture en passant next to it, the position is the same as the one which could reoccur after some more moves. This is because all the players have the same possible (legal) moves (the relevant en passant is, was, and will be unavailable) so under 9.2.2 it would be the same position.

3) Similarly, if en passant is illegal due to a pin (exposing own king to check) or another reason, it does not count as a possible (legal) move, so under 9.2.2 the position and the repeated one later are considered the same.

An additional note: comparing FEN is not a correct implementation according to the FIDE rules, since FEN always records down a pawn moving two squares, regardless of whether an en passant capture is possible or not. Hence a direct PGN comparison would yield a wrong conclusion in the two scenarios you described.

• Your answer is not wrong but, unfortunately, I believe that it partly misses the point. The point is that FIDE rules are written in a way that allows opposite interpretations. – thb Nov 18 '18 at 23:02

I think that your question is an excellent one. @Remillion, @itub and @SmallChess have answered it already. I believe that I mostly—perhaps wholly—agree with their answers, so now I would like to add an answer on a different level.

The FIDE has not shown that it fully grasps the kind of question you are asking. You and I get it. To some extent, the FIDE does not.

Therefore, for the time being, one probably cannot find authoritative answers to all such questions. This is a shame. If the FIDE asked your advice, they could fix the rules, but they don't quite see the need. Not yet.

The FIDE's problem (though imperfectly grasped by the FIDE) is to express game mechanics in a way that

• is logically complete,
• does not require the reader to process the phraseology of rulebook language through complex chains of verbal inference,
• is unambiguous,
• is unlikely to be incorrectly understood, and
• is computationally tractable.

Moreover, it would help if the FIDE would do as the American Contract Bridge League (ACBL) has done, cleanly separating game mechanics (which are abstract mathematical/logical constructs) from rules of player conduct (which are concrete and inherently imprecise).

A good software engineer like you implicitly understands the problem. The FIDE, unfortunately, so far, is still groping toward an understanding.

• In my own answer, I deliberately "missed the point" that you're making, on the grounds that such an answer would be needlessly complicated for the task at hand, i.e. writing a program conforming to the word of the Laws. As a (retro) problemist, I dabble a little in conceiving positions that poke holes at the ambiguities, and am aware of several previous and ongoing efforts to make the rules complete, consistent and extensible to fairy rules (i.e. few artificial explicit exceptions). It is surprisingly hard to do so - the issue is much deeper than it first seems. – Remellion Nov 19 '18 at 2:48
• I completely agree with your sentiment, and thanks for the reference to Bridge. So +1 from me. Magic the Gathering is another popular game where the rules are separated from the tournament guidelines. Having said that it is possible to use the existing laws to extract a correct meaning about draw by repetition – Laska Aug 29 '19 at 0:09

While comparing FEN strings may be common practice, I don't think it is correct according a close reading of the rule. I would say that the rule is already completely specified by its first sentence (emphasis added):

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.

The rest is an addendum just to emphasize that the "possible moves of all the pieces" may be different for seemingly identical positions (i.e., all pieces in the same squares) due to castling or en passant. But I think it would be fundamentally wrong to count an "en passant state change" when no en passant move was actually possible, either because there was no enemy pawn next to the pawn that just moved or the enemy pawn is pinned. FEN records an "en passant target square" anyway for simplicity of implementation, but that doesn't mean that it is a possible move.

As for castling, lack of castling rights due to check or obstruction doesn't matter for the purpose of this rule because if you couldn't castle due to check or obstruction in position 1, the same must be true for position 3 if all the pieces are in the same squares. If they were not, the position would already be obviously different without having to look at castling rights!

• The FIDE would do well to seek the advice of OP or someone like him, because the FIDE is finding it difficult to express the rules in a logically complete, computationally tractable way. They're not thinking this through correctly. They have not quite understood the problem. – thb Nov 18 '18 at 23:00

This is an important corner case for programming and also comes up in certain chess problems. I begin explanations by saying that castling and en passant are handled slightly differently, but don’t worry about this. Each is handled in the most sensible way.

Ideally one would look ahead in the game to find out whether the moves are actually playable. For en passant this is totally practicable because it just means looking one move ahead. Can the en passant actually be played or does a pin prevent it?

Whether or not castling is actually playable may be complicated to determine by looking st the deeper future of the game. So the rule simply looks at whether the two rights have changed, i.e. whether king or rook have just moved.

A genetics metaphor might be “check castling genotype and ep phenotype”.

This is the intention behind the FIDE rules according to the head of the rules committee. There is some unwillingness to make arbitrary changes to the wording, but the current 2018 phrasing seems fairly clear. Certainly FIDE get the exact issue here.

This applies both over the board and for chess problems

...So the first part of my question is, am I correct in my assessment of how the right to castle affects whether positions are identical?...

...other restrictions like check, obstructions, or even whether the relevant rook was captured are not considered (though the last is probably irrelevant)...

Yes. Imagine we play a game from the starting position, but you don't have castling rights and I do. Obviously, it'd be a different game. For instance, you won't be to castle in Ruy Lopez. Winning advantage for me even before the first move.

First, say a pawn moves two squares, thus making it capturable by en passant, but there's no enemy pawn next to its destination. Does the fact that it would have been vulnerable to en-passant make the position non-identical to another otherwise identical position a few turns later?

Pawns never move backward. A position that no enemy pawn being able to explore en passant is obviously different to one that does.

Second, say a pawn moves two squares, landing next to an enemy pawn, giving that pawn the right to en passant, but where exercising the right to en passant would expose the king (thus barring the otherwise legal en passant)

You don't have to check for king safety.

I think you're over-complicating the rules. In programming, all you have to do is compare your FEN strings (ignore 50 moves counter and impossible en passant).

``````FEN compareFEN = ...;
for (i from 0 to current move) {
FEN fen = fens[i]
if compareFENIgnore50MoveAndImpossibleEnpassant(compareFEN, fen)
print("Repetition found!")
}
``````
• To OP, you write, "I think you're over-complicating the rules." I disagree. The FIDE could use the help of someone like OP to rewrite these draw rules in a clean, clear, logically unambiguous way. The draw rules are cleaner and clearer than they used to be, but they still need work. OP's problem, if I understand, is not that he is unable to impute a definite meaning to the rules as he reads them. Rather, his problem is that the rules fail to afford him confidence that his future users will impute the same meaning to the rules as they read them. – thb Nov 18 '18 at 22:56

Although not directly answering the question, here is a problem that I recently came across that demonstrates how the right the castle affects caluclating threefold repeition.

``````[Title "Petrović, Nenad, Problem (Zagreb) 1959, 1st Prize, White To Move And Mate In 8"]
[FEN "r3k2r/p2p4/p1pP2p1/5pN1/5p2/1Q3p2/PP4b1/KB6 w kq - 0 1"]

1. Qb7 {In the intial position, Black had both castling rights.} Rd8 2. Qb3 Ra8 {Now we have reached the intial position again, but now Black has lost the right to castle queenside} 3. Bd3 Rh1+ 4. Bb1 Rh8 {For the third and final time we have the intial positon, but now Black has lost both castling rights. Now Black has no hope claiming a draw at all.} 5. Qc3 Rh1 6. Qg7 Rxb1+ 7. Kxb1 Rb8 8. Qg8#
``````

The point is that when Black plays, or before hand, 4... Rh8, they may not claim a draw by threefold repetition. This is because in each instance, the position was the same, but the right, i.e. Black’s ability to castle, has not. In position #1, Black has both rights, in positon #2, Black has only one right, and in position #3, Black has zero rights. Each positon is different, and therefore, by the FIDE laws of chess, as cited in other answers, Black cannot claim a draw.

I hope that this helps!