src/chess/rules.c

changeset 166
1a9b662bc201
parent 165
3e27c99ed721
child 167
fd1d3f0a7a73
--- a/src/chess/rules.c	Sat Aug 01 10:58:39 2026 +0200
+++ b/src/chess/rules.c	Sat Aug 01 11:26:48 2026 +0200
@@ -1040,18 +1040,20 @@
 }
 
 bool is_protected(const GameState *gamestate, Row row, File file, Color color) {
-    Move threats[16];
-    size_t threatcount;
-    if (get_real_threats(gamestate, row, file, color, threats, &threatcount)) {
-        for (size_t i = 0 ; i < threatcount ; i++) {
-            if (threats[i].piece != (color|KING)) {
-                return true;
-            }
+    Move candidates[16];
+    size_t ccount;
+    /* we need all candidates - not only threats! */
+    if (get_candidates(gamestate, row, file, color, candidates, &ccount)) {
+        for (size_t i = 0 ; i < ccount ; i++) {
+            /* skip the king */
+            if (piece_type(candidates[i].piece) == KING) continue;
+            /* skip pinned pieces */
+            if (is_pinned(gamestate, &candidates[i])) continue;
+            /* found one */
+            return true;
         }
-        return false;
-    } else {
-        return false;
     }
+    return false;
 }
 
 uint16_t remaining_movetime(const GameState *gamestate, Color color) {

mercurial