src/chess/rules.c

changeset 177
18dbb0dc9cd6
parent 173
e541b6002933
--- a/src/chess/rules.c	Mon Aug 17 12:14:51 2026 +0200
+++ b/src/chess/rules.c	Mon Aug 17 12:22:08 2026 +0200
@@ -397,11 +397,6 @@
     Move *melem = &gamestate->moves[gamestate->movecount];
     *melem = *move;
 
-    /* calculate the FEN and store it in the FEN array */
-    char fen[FEN_MAX_LENGTH];
-    fen_compute(fen, gamestate);
-    gamestate->fen[gamestate->movecount] = strdup(fen);
-
     /* only if move has no time info, compute it */
     if (melem->movetime.tv_sec == 0 && melem->movetime.tv_usec == 0) {
         calc_movetime(gamestate, melem);
@@ -409,6 +404,11 @@
 
     /* important: only "add" the move after calculating the time! */
     gamestate->movecount++;
+
+    /* calculate the FEN of the new position and store it in the FEN array */
+    char fen[FEN_MAX_LENGTH];
+    fen_compute(fen, gamestate);
+    gamestate->fen[gamestate->movecount - 1] = strdup(fen);
 }
 
 void apply_move(GameState *gamestate, Move *move) {

mercurial