src/chess/pawn.c

changeset 160
f87832cba8b8
parent 80
b980a7192b5a
--- a/src/chess/pawn.c	Tue Jul 28 13:44:10 2026 +0200
+++ b/src/chess/pawn.c	Wed Jul 29 13:45:51 2026 +0200
@@ -31,12 +31,12 @@
 #include "rules.h"
 
 bool pawn_chkrules(GameState *gamestate, Move *move) {
-    int8_t d = ((move->piece & COLOR_MASK) == WHITE ? -1 : 1);
+    int8_t d = piece_color(move->piece) == WHITE ? -1 : 1;
     
     if (move->torow == (d < 0 ? 7 : 0)) {
         if (move->promotion) {
-            uint8_t promopiece = move->promotion & PIECE_MASK;
-            if (!promopiece || promopiece == PAWN || promopiece == KING) {
+            unsigned ppiecetype = piece_type(move->promotion);
+            if (!ppiecetype || ppiecetype == PAWN || ppiecetype == KING) {
                 return false;
             }
         } else {
@@ -53,9 +53,8 @@
             move->fromfile == move->tofile + 1 ||
             move->fromfile == move->tofile - 1)) {
 
-            return mdst(gamestate->board, move) ||
-                (gamestate->board[move->fromrow][move->tofile]
-                & ENPASSANT_THREAT);
+            return piece_at(gamestate, mdst(move)) ||
+                enpassant_threat_exists(gamestate, move->fromrow, move->tofile);
         } else {
             return false;
         }
@@ -72,9 +71,9 @@
 
 bool pawn_isblocked(GameState *gamestate, Move *move) {
     if (move->torow == move->fromrow + 1 || move->torow == move->fromrow - 1) {
-        return mdst(gamestate->board, move) && !move->capture;
+        return piece_at(gamestate, mdst(move)) && !move->capture;
     } else {
-        return mdst(gamestate->board, move) ||
+        return piece_at(gamestate, mdst(move)) ||
             gamestate->board[(move->fromrow+move->torow)/2][move->tofile];
     }
 }

mercurial