src/chess/rules.c

changeset 80
b980a7192b5a
parent 78
ceb9197b3c6d
--- a/src/chess/rules.c	Tue Jun 03 08:43:17 2025 +0200
+++ b/src/chess/rules.c	Wed Jun 04 23:56:40 2025 +0200
@@ -207,7 +207,7 @@
     }
 }
 
-static void apply_move_impl(GameState *gamestate, Move *move, _Bool simulate) {
+static void apply_move_impl(GameState *gamestate, Move *move, bool simulate) {
     /* format move before moving (s.t. ambiguities can be resolved) */
     if (!simulate) {
         if (!move->string[0]) {
@@ -294,7 +294,7 @@
     }
     
     /* validate individual rules */
-    _Bool chkrules;
+    bool chkrules;
     switch (move->piece & PIECE_MASK) {
     case PAWN:
         chkrules = pawn_chkrules(gamestate, move) &&
@@ -380,7 +380,7 @@
     
     if (move->check) {
         /* determine possible escape fields */
-        _Bool canescape = 0;
+        bool canescape = false;
         for (int dr = -1 ; dr <= 1 && !canescape ; dr++) {
             for (int df = -1 ; df <= 1 && !canescape ; df++) {
                 if (!(dr == 0 && df == 0)  &&
@@ -455,7 +455,7 @@
     return VALID_MOVE_SEMANTICS;
 }
 
-_Bool get_threats(GameState *gamestate, uint8_t row, uint8_t file,
+bool get_threats(GameState *gamestate, uint8_t row, uint8_t file,
         uint8_t color, Move *threats, uint8_t *threatcount) {
     Move candidates[32];
     int candidatecount = 0;
@@ -485,12 +485,12 @@
     }
     
     
-    _Bool result = 0;
+    bool result = false;
     
     for (int i = 0 ; i < candidatecount ; i++) {
         if (validate_move_rules(gamestate, &(candidates[i]))
                 == VALID_MOVE_SEMANTICS) {
-            result = 1;
+            result = true;
             if (threats && threatcount) {
                 threats[(*threatcount)++] = candidates[i];
             }
@@ -500,7 +500,7 @@
     return result;
 }
 
-_Bool is_pinned(GameState *gamestate, Move *move) {
+bool is_pinned(GameState *gamestate, Move *move) {
     uint8_t color = move->piece & COLOR_MASK;
 
     GameState simulation = gamestate_copy_sim(gamestate);
@@ -517,14 +517,14 @@
         }
     }
     
-    _Bool covered = is_covered(&simulation,
+    bool covered = is_covered(&simulation,
         kingrow, kingfile, opponent_color(color));
     gamestate_cleanup(&simulation);
     
     return covered;
 }
 
-_Bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file,
+bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file,
         uint8_t color, Move *threats, uint8_t *threatcount) {
     
     if (threatcount) {
@@ -535,7 +535,7 @@
     uint8_t candidatecount;
     if (get_threats(gamestate, row, file, color, candidates, &candidatecount)) {
         
-        _Bool result = 0;
+        bool result = false;
         uint8_t kingfile = 0, kingrow = 0;
         for (uint8_t row = 0 ; row < 8 ; row++) {
             for (uint8_t file = 0 ; file < 8 ; file++) {
@@ -552,7 +552,7 @@
             apply_move(&simulation, &simmove);
             if (!is_covered(&simulation, kingrow, kingfile,
                     opponent_color(color))) {
-                result = 1;
+                result = true;
                 if (threats && threatcount) {
                     threats[(*threatcount)++] = candidates[i];
                 }
@@ -561,7 +561,7 @@
         
         return result;
     } else {
-        return 0;
+        return false;
     }
 }
 
@@ -569,7 +569,7 @@
 
     uint8_t color = move->piece & COLOR_MASK;
     uint8_t piece = move->piece & PIECE_MASK;
-    _Bool incheck = gamestate->lastmove?gamestate->lastmove->move.check:0;
+    bool incheck = gamestate->lastmove?gamestate->lastmove->move.check:false;
     
     Move threats[16], *threat = NULL;
     uint8_t threatcount;
@@ -745,7 +745,7 @@
     }
 }
 
-_Bool is_protected(GameState *gamestate, uint8_t row, uint8_t file,
+bool is_protected(GameState *gamestate, uint8_t row, uint8_t file,
         uint8_t color) {
     
     Move threats[16];
@@ -753,12 +753,12 @@
     if (get_real_threats(gamestate, row, file, color, threats, &threatcount)) {
         for (int i = 0 ; i < threatcount ; i++) {
             if (threats[i].piece != (color|KING)) {
-                return 1;
+                return true;
             }
         }
-        return 0;
+        return false;
     } else {
-        return 0;
+        return false;
     }
 }
 

mercurial