src/chess/king.c

changeset 194
619f07c95894
parent 193
d1420f5c5704
child 195
27d02ccb0cef
--- a/src/chess/king.c	Tue Aug 25 18:35:18 2026 +0200
+++ b/src/chess/king.c	Tue Aug 25 18:59:18 2026 +0200
@@ -31,11 +31,11 @@
 #include "king.h"
 
 static bool king_castling_chkmoved(
-        const GameState *gamestate, Row row, File file) {
+        const GameState *gamestate, Rank rank, File file) {
 
     for (unsigned i = 0; i < gamestate->movecount; i++) {
         if (gamestate->moves[i].fromfile == file
-            && gamestate->moves[i].fromrow == row) {
+            && gamestate->moves[i].fromrank == rank) {
             return true;
         }
     }
@@ -44,19 +44,19 @@
 }
 
 bool king_chkrules(const GameState *gamestate, const Move* move) {
-    if (abs(move->torow - move->fromrow) <= 1 &&
+    if (abs(move->torank - move->fromrank) <= 1 &&
         abs(move->tofile - move->fromfile) <= 1) {
         return true;
     } else {
         /* castling */
-        if (move->fromrow == move->torow &&
-            move->fromrow == (piece_color(move->piece) == WHITE ? 0 : 7) &&
+        if (move->fromrank == move->torank &&
+            move->fromrank == (piece_color(move->piece) == WHITE ? 0 : 7) &&
             move->fromfile == fileidx('e') &&
             (move->tofile == fileidx('c') || move->tofile == fileidx('g'))) {
             
             return !king_castling_chkmoved(gamestate,
-                move->fromrow, move->fromfile) &&
-                !king_castling_chkmoved(gamestate, move->fromrow,
+                move->fromrank, move->fromfile) &&
+                !king_castling_chkmoved(gamestate, move->fromrank,
                 move->tofile == fileidx('c') ? 0 : 7);
         } else {
             return false;
@@ -66,7 +66,7 @@
 
 bool king_isblocked(const GameState *gamestate, const Move *move) {
     
-    uint8_t op_color = opponent_color(piece_color(move->piece));
+    Color op_color = opponent_color(piece_color(move->piece));
     
     /* being in check does not "block" the king, so don't test it here */
     bool blocked = false;
@@ -74,22 +74,22 @@
     /* just test, if castling move is blocked */
     if (abs(move->tofile - move->fromfile) == 2) {
         if (move->tofile == fileidx('c')) {
-            blocked |= gamestate->board[move->torow][fileidx('b')];
+            blocked |= gamestate->board[move->torank][fileidx('b')];
         }
-        uint8_t midfile = (move->tofile+move->fromfile)/2;
+        File midfile = (move->tofile+move->fromfile)/2;
         bool incheck = false;
         if (gamestate->movecount > 0) {
             incheck = is_check_position(gamestate);
         }
-        blocked |= incheck || gamestate->board[move->torow][midfile] ||
-            is_covered(gamestate, move->torow, midfile, op_color);
+        blocked |= incheck || gamestate->board[move->torank][midfile] ||
+            is_covered(gamestate, move->torank, midfile, op_color);
     }
     
     return blocked;
 }
 
 size_t king_moves(const GameState *gamestate,
-        Color c, Row r, File f, Move *moves) {
+        Color c, Rank r, File f, Move *moves) {
 
     size_t count = 0;
     Piece king = mkpiece(KING, c);
@@ -100,39 +100,39 @@
                 continue;
             }
 
-            Row torow = r + dr;
+            Rank torank = r + dr;
             File tofile = f + df;
 
-            if (!isidx(torow) || !isidx(tofile)) {
+            if (!isidx(torank) || !isidx(tofile)) {
                 continue;
             }
 
             moves[count] = (Move){0};
             moves[count].piece = king;
-            moves[count].fromrow = r;
+            moves[count].fromrank = r;
             moves[count].fromfile = f;
-            moves[count].torow = torow;
+            moves[count].torank = torank;
             moves[count].tofile = tofile;
-            moves[count].capture = piece_at(gamestate, torow, tofile) != 0;
+            moves[count].capture = piece_at(gamestate, torank, tofile) != 0;
             count++;
         }
     }
 
-    Row homerow = c == WHITE ? 0 : 7;
-    if (r == homerow && f == fileidx('e')) {
+    Rank homerank = c == WHITE ? 0 : 7;
+    if (r == homerank && f == fileidx('e')) {
         moves[count] = (Move){0};
         moves[count].piece = king;
-        moves[count].fromrow = r;
+        moves[count].fromrank = r;
         moves[count].fromfile = f;
-        moves[count].torow = r;
+        moves[count].torank = r;
         moves[count].tofile = fileidx('c');
         count++;
 
         moves[count] = (Move){0};
         moves[count].piece = king;
-        moves[count].fromrow = r;
+        moves[count].fromrank = r;
         moves[count].fromfile = f;
-        moves[count].torow = r;
+        moves[count].torank = r;
         moves[count].tofile = fileidx('g');
         count++;
     }

mercurial