How does Threefold Repetition get handeled with the Universal Chess Interface?

84 Views Asked by At

I am coding a Chess-Engine in C++. I want it to be able to communicate via the universal chess interface (UCI). But i'm not sure how it is supposed to get enough information about possible repetitions of the position. Because after the opponent has made a move, it just gets the information about the position via the new fen. This means that it has to throw away all information about previous positions because it cannot know what happened since the last position. Therefore it would not know how many times the new position was already reached. This could lead it to blunder a threefold-draw.

I know there is the "moves" command, which can be sent with the position command. This could theoretically solve the problem if the engine always recieves the starting position and then every move made since the beginning. But since this is very inefficient i'm guessing that this is not really what happens in apps like lichess or generally on GUI's.

So my question is how do other chess engine like stockfish, leela and so on handle this problem? Or do they just ignore it?

1

There are 1 best solutions below

0
Jane Doe On

There's nothing inefficient about sending moves alongside the FEN. That's how every relevant GUI does it and if not, then it's not adhering to the UCI standard and it's a GUI bug.

Engines do detect three-fold repetition when performing search and take all the previous moves into account.

Now, this part is slightly contentious, but every GUI i know of will do this - under the UCI standard it is the GUI's job to automatically claim a draw for the engine if the position has been seen 3 times already, as there is no UCI command for the engine itself to claim a draw. So it should never happen that the engine receives a position with moves that would end up in repetition. However, even if such a situation happend the engine can simply refuse to move by sending the null move as a response.