Menu

#344 Mistake in Threefold Repetition Rule relating to En Passant

None
closed
nobody
None
5
2024-06-02
2024-03-03
Noah Simon
No

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.

Discussion

  • Noah Simon

    Noah Simon - 2024-03-03

    So in GameX::positionRepetition, position equality is determined using the == operator for BoardX objects. In that operator, board equality is determined using the board's getHashValue method, which seems to be related somehow to the position's FEN.

     

    Last edit: Noah Simon 2024-03-03
    • Noah Simon

      Noah Simon - 2024-03-04

      So any time a BoardX's hash is generated in BoardX::createHash, it runs BoardX::hashEpSquare, which XORs the en passant square onto the hash, defined by BoardX::m_epFile as 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.

       
  • Noah Simon

    Noah Simon - 2024-03-03

    Another related fix might be improving the efficiency of GameX::positionRepetition for 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.

     
  • Jens Nissen

    Jens Nissen - 2024-03-05

    Very tricky scenario - thanks for finding this. I will fix it some day :-)

     
  • Jens Nissen

    Jens Nissen - 2024-03-06
    • status: open --> closed
     
  • Jens Nissen

    Jens Nissen - 2024-03-06

    Committed

     
    • Noah Simon

      Noah Simon - 2024-03-06

      Took a look at the commit - does it account for the scenario where en passant rights actually DO affect three-fold repetition?

       
  • Jens Nissen

    Jens Nissen - 2024-06-02

    Fixed this scenario, too.

     

Log in to post a comment.

MongoDB Logo MongoDB