src/chess/rules.h

changeset 131
c33567d61ba7
parent 130
3fc6b1d6cbe9
--- a/src/chess/rules.h	Thu May 28 13:58:24 2026 +0200
+++ b/src/chess/rules.h	Sun Jun 07 14:55:20 2026 +0200
@@ -125,6 +125,7 @@
     char premove[8];
     bool checkmate;
     bool stalemate;
+    bool threefold;
     bool remis;
     bool wresign;
     bool bresign;
@@ -134,7 +135,7 @@
 } GameState;
 
 #define is_game_running(gamestate) !((gamestate)->checkmate || \
-    (gamestate)->wresign || (gamestate)->bresign || \
+    (gamestate)->wresign || (gamestate)->bresign || (gamestate)->threefold || \
     (gamestate)->stalemate || (gamestate)->remis || (gamestate)->review)
 
 #define last_move(gamestate) \
@@ -395,5 +396,19 @@
  */
 int print_clk(uint16_t time, char *str, bool always_hours);
 
+/**
+ * Checks if the current position already appeared two times before.
+ *
+ * This does not set the threefold flag in the game state as this flag is
+ * intended to be set only when the game ends after actually claiming a draw.
+ *
+ * By standard chess rules this is not automatically a draw.
+ * But implementation may choose to automatically draw the game anyway.
+ *
+ * @param gamestate the current game state
+ * @return true if the game is in a threefold repetition position
+ */
+bool check_threefold_repetition(GameState *gamestate);
+
 #endif	/* RULES_H */
 

mercurial