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:
22.214.171.124 at the start of the sequence a pawn could have been captured en passant
126.96.36.199 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 188.8.131.52 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 184.108.40.206 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?