src/chess/rules.c

changeset 161
3ff96fec144a
parent 160
f87832cba8b8
child 163
2a6d83f4677e
--- a/src/chess/rules.c	Wed Jul 29 13:45:51 2026 +0200
+++ b/src/chess/rules.c	Thu Jul 30 11:49:47 2026 +0200
@@ -92,7 +92,7 @@
     if (gamestate->movecount > 0) {
         simulation.fen_start = strdup(gamestate->movecount == 1 ?
             gamestate->fen_start : gamestate->fen[gamestate->movecount - 2]);
-        simulation.moves[0] = last_move(gamestate);
+        simulation.moves[0] = gamestate->moves[gamestate->movecount - 1];
         simulation.fen[0] = strdup(gamestate->fen[gamestate->movecount - 1]);
         simulation.movecount++;
     } else {
@@ -200,7 +200,8 @@
     move->movetime.tv_usec = 0;
     move->movetime.tv_sec = 0;
     if (gamestate->movecount > 1) {
-        struct movetimeval lasttstamp = last_move(gamestate).timestamp;
+        struct movetimeval lasttstamp =
+            gamestate->moves[gamestate->movecount - 1].timestamp;
         uint64_t sec = curtimestamp.tv_sec - lasttstamp.tv_sec;
         suseconds_t micros;
         if (curtimestamp.tv_usec < lasttstamp.tv_usec) {
@@ -469,9 +470,11 @@
         if (piece_type(move->piece) == KING) {
             return KING_MOVES_INTO_CHECK;
         } else {
-            /* last move is always not null in this case */
-            return last_move(gamestate).check ?
-                KING_IN_CHECK : PIECE_PINNED;
+            if (gamestate->moves[gamestate->movecount - 1].check) {
+                return KING_IN_CHECK;
+            } else {
+                return PIECE_PINNED;
+            }
         }
     }
     
@@ -710,7 +713,10 @@
 static int getlocation(GameState *gamestate, Move *move) {   
 
     Color color = piece_color(move->piece);
-    bool incheck = gamestate->movecount > 0 ? last_move(gamestate).check:false;
+    bool incheck = false;
+    if (gamestate->movecount > 0) {
+        incheck = gamestate->moves[gamestate->movecount - 1].check;
+    }
     
     Move threats[16], *threat = NULL;
     size_t threatcount;

mercurial