Mistake in Threefold Repetition Rule relating to En Passant
Chess Database and PGN viewer
Brought to you by:
hognose
Take the following simple game:
1. e4 Nf6
2. Nf3 Ng8
3. Ng1 Nf6
4. Nf3 Ng8
5. Ng1
According to FIDE rule 9.2.2, as explained in answers to this Chess Stack Exchange question, the board position after 5. Ng1 should be considered a threefold repetition. ChessX does not, however, presumably since the e pawn was moved two spaces, theoretically creating the opportunity for en passant (which is encoded in the FEN for this position), but obviously no such move exists. I presume this came about because ChessX compares FEN encodings to establish threefold repetition, which doesn't work in this corner case.
It should be noted that ChessX (correctly) declares the continuation 5... Nf6 to be a threefold repetition draw.
So in
GameX::positionRepetition, position equality is determined using the==operator forBoardXobjects. In that operator, board equality is determined using the board'sgetHashValuemethod, which seems to be related somehow to the position's FEN.Last edit: Noah Simon 2024-03-03
So any time a
BoardX's hash is generated inBoardX::createHash, it runsBoardX::hashEpSquare, which XORs the en passant square onto the hash, defined byBoardX::m_epFileas the "file of a possible ep capture". Therefore, the hash state of a board where a pawn was just pushed two squares, even if no en passant is possible, is different from the hash state two moves later when the board looks exactly the same.Another related fix might be improving the efficiency of
GameX::positionRepetitionfor very long games (hundreds of moves). As it is, if I'm understanding the code correctly, the method checks every past board hash. However, it is not necessary to check beyond the most recent pawn move or capture, as no position before then can possibly be identical to the current one.Very tricky scenario - thanks for finding this. I will fix it some day :-)
Committed
Took a look at the commit - does it account for the scenario where en passant rights actually DO affect three-fold repetition?
Fixed this scenario, too.