src/chess/rules.c

changeset 68
b34de5ce7d0e
parent 67
c76e46970a59
child 69
c8f2c280cff7
--- a/src/chess/rules.c	Wed Aug 29 17:05:40 2018 +0200
+++ b/src/chess/rules.c	Wed Aug 29 17:31:36 2018 +0200
@@ -576,6 +576,7 @@
 static int getlocation(GameState *gamestate, Move *move) {   
 
     uint8_t color = move->piece & COLOR_MASK;
+    uint8_t piece = move->piece & PIECE_MASK;
     _Bool incheck = gamestate->lastmove?gamestate->lastmove->move.check:0;
     
     Move threats[16], *threat = NULL;
@@ -588,8 +589,8 @@
         
         /* find threats for the specified position */
         for (uint8_t i = 0 ; i < threatcount ; i++) {            
-            if ((threats[i].piece & (PIECE_MASK | COLOR_MASK))
-                    == move->piece &&
+            if ((threats[i].piece & PIECE_MASK) == piece
+                    && (threats[i].piece & COLOR_MASK) == color &&
                     (move->fromrow == POS_UNSPECIFIED ||
                     move->fromrow == threats[i].fromrow) &&
                     (move->fromfile == POS_UNSPECIFIED ||
@@ -600,7 +601,8 @@
                 } else {
                     /* found threat is no real threat */
                     if (is_pinned(gamestate, &(threats[i]))) {
-                        reason = incheck?KING_IN_CHECK:PIECE_PINNED;
+                        reason = incheck?KING_IN_CHECK:
+                            (piece==KING?KING_MOVES_INTO_CHECK:PIECE_PINNED);
                     } else {
                         threat = &(threats[i]);
                     }

mercurial