src/chess/king.c

changeset 163
2a6d83f4677e
parent 161
3ff96fec144a
--- a/src/chess/king.c	Thu Jul 30 18:34:15 2026 +0200
+++ b/src/chess/king.c	Thu Jul 30 19:17:38 2026 +0200
@@ -32,7 +32,9 @@
 
 #include <string.h>
 
-static bool king_castling_chkmoved(GameState *gamestate, Row row, File file) {
+static bool king_castling_chkmoved(
+        const GameState *gamestate, Row row, File file) {
+
     for (unsigned i = 0; i < gamestate->movecount; i++) {
         if (gamestate->moves[i].fromfile == file
             && gamestate->moves[i].fromrow == row) {
@@ -43,7 +45,7 @@
     return false;
 }
 
-bool king_chkrules(GameState *gamestate, Move* move) {
+bool king_chkrules(const GameState *gamestate, const Move* move) {
     if (abs(move->torow - move->fromrow) <= 1 &&
         abs(move->tofile - move->fromfile) <= 1) {
         return true;
@@ -64,7 +66,7 @@
     }
 }
 
-bool king_isblocked(GameState *gamestate, Move *move) {
+bool king_isblocked(const GameState *gamestate, const Move *move) {
     
     uint8_t opponent_color = opponent_color(piece_color(move->piece));
     
@@ -79,7 +81,7 @@
         uint8_t midfile = (move->tofile+move->fromfile)/2;
         bool incheck = false;
         if (gamestate->movecount > 0) {
-            incheck = gamestate->moves[gamestate->movecount-1].check;
+            incheck = is_check_position(gamestate);
         }
         blocked |= incheck || gamestate->board[move->torow][midfile] ||
             is_covered(gamestate, move->torow, midfile, opponent_color);

mercurial