Answers.Body: <p><a href="https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation" rel="noreferrer">https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation</a></p>
  
  <p>"FEN does not represent sufficient information to decide whether a draw by threefold repetition may be legally claimed or a draw offer may be accepted; for that, a different format such as Extended Position Description is needed."</p>
  
  <p>QED.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-22T06:15:36.480Z
Answers.LastActivityDate: 2017-12-22T06:15:36.480Z
Answers.UserDisplayName: lenik
Body: <p>When I run the engine (UCI interface), I usually feed the last position from the game using <code>position fen ...</code> command and get the best move back. The FEN encodes the possibility of the castlings, en passant moves and keeps the move count since the last piece capture or pawn move to enforce to 50-move draw rule.</p>
  
  <p>How can the engine detect the 3-fold repetition and avoid it while playing the game? I've seen a few occasions when the engine is about 5-6 pawns ahead (a clear victory), but draws because it keeps repeating giving check to the opponent's king again and again.</p>
  
  <p>Clarification: I DON'T program my own engine (well, I do, but this is totally unrelated to this question). In this question I use existing engine, think StockFish or Fruit or anything else you like. This existing engine is given the FEN and returns the "best" move it can think of. Sometimes this leads to a 3-fold repetition in a clearly won positions. How can I tell the StockFish, that it has already made this move before and should do better?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-22T04:55:26.567Z
Comments.Text: https://chess.stackexchange.com/questions/17127/programming-the-three-fold-repetition-for-my-chess-engine
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-16T00:03:03.250Z
Comments.Text: This is why UCI GUIs usually give the engine the position as startpos plus a series of moves, not FEN.
Comments.UserDisplayName: Kef Schecter
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-16T07:24:48.820Z
Comments.Text: @KefSchecter thanks, that's a very nice idea to implement =)
Comments.UserDisplayName: lenik
Tags: <engines><draw><fen>
Title: How the engine can detect the 3-fold repetition using FEN input?
ThreadText: # How the engine can detect the 3-fold repetition using FEN input?
  
  (Asked by: username_0 on 2017-12-22)
  
  When I run the engine (UCI interface), I usually feed the last position from the game using `position fen ...` command and get the best move back. The FEN encodes the possibility of the castlings, en passant moves and keeps the move count since the last piece capture or pawn move to enforce to 50-move draw rule.
  
  How can the engine detect the 3-fold repetition and avoid it while playing the game? I've seen a few occasions when the engine is about 5-6 pawns ahead (a clear victory), but draws because it keeps repeating giving check to the opponent's king again and again.
  
  Clarification: I DON'T program my own engine (well, I do, but this is totally unrelated to this question). In this question I use existing engine, think StockFish or Fruit or anything else you like. This existing engine is given the FEN and returns the "best" move it can think of. Sometimes this leads to a 3-fold repetition in a clearly won positions. How can I tell the StockFish, that it has already made this move before and should do better?
  
  **Tags:** engines, draw, fen
  
  > **Comments:**
  > **username_1**: https://chess.stackexchange.com/questions/17127/programming-the-three-fold-repetition-for-my-chess-engine  
  > **username_2**: This is why UCI GUIs usually give the engine the position as startpos plus a series of moves, not FEN.  
  > **username_0**: @KefSchecter thanks, that's a very nice idea to implement =)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-12-22. Score: 5
  
  <https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation>
  
  "FEN does not represent sufficient information to decide whether a draw by threefold repetition may be legally claimed or a draw offer may be accepted; for that, a different format such as Extended Position Description is needed."
  
  QED.
  
  
  ---
  
  