Answers.Body: <p>You can set the engine so it evaluates every repeat position as 0. That way the player who has even the smallest advantage will try to avoid a repetition unless necessary. Is your current evaluation function valuing the position as 0 even without the repetition? Then you may want to make it consider some extra factors so that it gives either player a small advantage.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-02T17:13:29.080Z
Answers.Text: So my flaw is in the heiristic function I use? At the moment, I only consider presence and vulnerability of the pieces of the state to evaluate.
Answers.UserDisplayName: coderodde
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-02T20:36:08.223Z
Answers.Text: @coderodde Probably. If it sees way too many moves as the same you'll encounter problems like the one you describe. You may solve it by adding a draw avoidance factor (i.e: make repetitions -0.01 rather than 0) so that it prefers picking a different "equal" move over repeating
Answers.UserDisplayName: David
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-05T07:17:15.000Z
Answers.Text: Would using Shannon’s heuristic function solve the issue?
Answers.UserDisplayName: coderodde
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-02T07:10:45.807Z
Answers.LastActivityDate: 2024-08-02T07:10:45.807Z
Answers.UserDisplayName: David
Body: <p>I am working on my chess engine <strong>[1]</strong>. My issue is that if I run the AI bots in <strong>[2]</strong> with the <strong>depth of 4</strong> for both the bots, already after the 13th ply the game breaks the three-fold repetion rule. I have absolutely no idea how to program my engine to avoid going to the breakage of the rule in question.</p>
  <p>Any advice?</p>
  <h2>References</h2>
  <p><strong>[1]</strong> <a href="https://github.com/coderodde/Chess.java" rel="nofollow noreferrer"><strong><code>Chess.java</code></strong></a></p>
  <p><strong>[2]</strong> The demo AI vs AI match runner here: <a href="https://github.com/coderodde/ChessDuel.java" rel="nofollow noreferrer"><strong><code>ChessDuel.java</code></strong></a>.</p>
  
Tags: <engines>
Title: In a chess engine, how to avoid the breakage of the three-fold repetition rule
ThreadText: # In a chess engine, how to avoid the breakage of the three-fold repetition rule
  
  (Asked by: username_0 on 2024-08-02)
  
  I am working on my chess engine **[1]**. My issue is that if I run the AI bots in **[2]** with the **depth of 4** for both the bots, already after the 13th ply the game breaks the three-fold repetion rule. I have absolutely no idea how to program my engine to avoid going to the breakage of the rule in question.
  
  Any advice?
  
  ## References
  
  **[1]** [**`Chess.java`**](https://github.com/username_0/Chess.java)
  
  **[2]** The demo AI vs AI match runner here: [**`ChessDuel.java`**](https://github.com/username_0/ChessDuel.java).
  
  **Tags:** engines
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-08-02. Score: 1
  
  You can set the engine so it evaluates every repeat position as 0. That way the player who has even the smallest advantage will try to avoid a repetition unless necessary. Is your current evaluation function valuing the position as 0 even without the repetition? Then you may want to make it consider some extra factors so that it gives either player a small advantage.
  
  > **Comments:**
  > **username_0**: So my flaw is in the heiristic function I use? At the moment, I only consider presence and vulnerability of the pieces of the state to evaluate.  
  > **username_1**: @username_0 Probably. If it sees way too many moves as the same you'll encounter problems like the one you describe. You may solve it by adding a draw avoidance factor (i.e: make repetitions -0.01 rather than 0) so that it prefers picking a different "equal" move over repeating  
  > **username_0**: Would using Shannon’s heuristic function solve the issue?  
  
  ---
  
  