Wed, 04 Jun 2025 23:56:40 +0200
replace _Bool with bool from C23 and/or stdbool.h
--- a/src/chess/bishop.c Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/bishop.c Wed Jun 04 23:56:40 2025 +0200 @@ -31,11 +31,11 @@ #include "rules.h" #include <stdlib.h> -_Bool bishop_chkrules(Move* move) { +bool bishop_chkrules(Move* move) { return abs(move->torow-move->fromrow) == abs(move->tofile-move->fromfile); } -_Bool bishop_isblocked(GameState *gamestate, Move *move) { +bool bishop_isblocked(GameState *gamestate, Move *move) { int dy = move->torow > move->fromrow ? 1 : -1; int dx = move->tofile > move->fromfile ? 1 : -1; @@ -46,9 +46,9 @@ x += dx; y += dy; if (gamestate->board[y][x]) { - return 1; + return true; } } - return 0; + return false; }
--- a/src/chess/bishop.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/bishop.h Wed Jun 04 23:56:40 2025 +0200 @@ -36,8 +36,8 @@ extern "C" { #endif -_Bool bishop_chkrules(Move *move); -_Bool bishop_isblocked(GameState *gamestate, Move *move); +bool bishop_chkrules(Move *move); +bool bishop_isblocked(GameState *gamestate, Move *move); #ifdef __cplusplus }
--- a/src/chess/game-info.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/game-info.h Wed Jun 04 23:56:40 2025 +0200 @@ -31,6 +31,7 @@ #define GAME_INFO_H #include <stdint.h> +#include <stdbool.h> #define WHITE 0x10 #define BLACK 0x20 @@ -99,10 +100,10 @@ MoveList* movelist; MoveList* lastmove; unsigned int movecount; /* number of (half-)moves (counting BOTH colors) */ - _Bool checkmate; - _Bool stalemate; - _Bool remis; - _Bool resign; + bool checkmate; + bool stalemate; + bool remis; + bool resign; } GameState;
--- a/src/chess/king.c Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/king.c Wed Jun 04 23:56:40 2025 +0200 @@ -31,24 +31,24 @@ #include "king.h" #include <stdlib.h> -static _Bool king_castling_chkmoved(GameState *gamestate, +static bool king_castling_chkmoved(GameState *gamestate, uint8_t row, uint8_t file) { MoveList *ml = gamestate->movelist; while (ml) { if (ml->move.fromfile == file && ml->move.fromrow == row) { - return 1; + return true; } ml = ml->next; } - return 0; + return false; } -_Bool king_chkrules(GameState *gamestate, Move* move) { +bool king_chkrules(GameState *gamestate, Move* move) { if (abs(move->torow - move->fromrow) <= 1 && abs(move->tofile - move->fromfile) <= 1) { - return 1; + return true; } else { /* castling */ if (move->fromrow == move->torow && @@ -61,17 +61,17 @@ !king_castling_chkmoved(gamestate, move->fromrow, move->tofile == fileidx('c') ? 0 : 7); } else { - return 0; + return false; } } } -_Bool king_isblocked(GameState *gamestate, Move *move) { +bool king_isblocked(GameState *gamestate, Move *move) { uint8_t opponent_color = opponent_color(move->piece&COLOR_MASK); /* being in check does not "block" the king, so don't test it here */ - _Bool blocked = 0; + bool blocked = false; /* just test, if castling move is blocked */ if (abs(move->tofile - move->fromfile) == 2) {
--- a/src/chess/king.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/king.h Wed Jun 04 23:56:40 2025 +0200 @@ -37,8 +37,8 @@ extern "C" { #endif -_Bool king_chkrules(GameState *gamestate, Move *move); -_Bool king_isblocked(GameState *gamestate, Move *move); +bool king_chkrules(GameState *gamestate, Move *move); +bool king_isblocked(GameState *gamestate, Move *move); #ifdef __cplusplus }
--- a/src/chess/knight.c Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/knight.c Wed Jun 04 23:56:40 2025 +0200 @@ -31,7 +31,7 @@ #include "rules.h" #include <stdlib.h> -_Bool knight_chkrules(Move *move) { +bool knight_chkrules(Move *move) { int dx = abs(move->fromfile - move->tofile); int dy = abs(move->fromrow - move->torow);
--- a/src/chess/knight.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/knight.h Wed Jun 04 23:56:40 2025 +0200 @@ -36,8 +36,8 @@ extern "C" { #endif -_Bool knight_chkrules(Move *move); -#define knight_isblocked(gs,m) 0 +bool knight_chkrules(Move *move); +#define knight_isblocked(gs,m) false #ifdef __cplusplus }
--- a/src/chess/pawn.c Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/pawn.c Wed Jun 04 23:56:40 2025 +0200 @@ -30,21 +30,21 @@ #include "pawn.h" #include "rules.h" -_Bool pawn_chkrules(GameState *gamestate, Move *move) { +bool pawn_chkrules(GameState *gamestate, Move *move) { int8_t d = ((move->piece & COLOR_MASK) == 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) { - return 0; + return false; } } else { - return 0; + return false; } } else { if (move->promotion) { - return 0; + return false; } } @@ -57,7 +57,7 @@ (gamestate->board[move->fromrow][move->tofile] & ENPASSANT_THREAT); } else { - return 0; + return false; } } else { if (move->fromfile == move->tofile) { @@ -65,12 +65,12 @@ (move->fromrow == (d < 0 ? 1 : 6) && /* advanced first move */ move->fromrow == move->torow + d*2); } else { - return 0; + return false; } } } -_Bool pawn_isblocked(GameState *gamestate, Move *move) { +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; } else {
--- a/src/chess/pawn.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/pawn.h Wed Jun 04 23:56:40 2025 +0200 @@ -36,8 +36,8 @@ extern "C" { #endif -_Bool pawn_chkrules(GameState *gamestate, Move *move); -_Bool pawn_isblocked(GameState *gamestate, Move *move); +bool pawn_chkrules(GameState *gamestate, Move *move); +bool pawn_isblocked(GameState *gamestate, Move *move); #ifdef __cplusplus }
--- a/src/chess/pgn.c Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/pgn.c Wed Jun 04 23:56:40 2025 +0200 @@ -63,11 +63,11 @@ char tagvalue[128]; /* read tag pairs */ - _Bool readmoves = 0; + bool readmoves = false; while (!readmoves) { while (isspace(c = fgetc(stream))); if (c == '1') { - readmoves = 1; + readmoves = true; break; } if (c != '[') { @@ -279,31 +279,31 @@ return 1; } -static _Bool fen_castling_chkmoved(GameState *gamestate, +static bool fen_castling_chkmoved(GameState *gamestate, uint8_t row, uint8_t file) { MoveList *ml = gamestate->movelist; while (ml) { if (ml->move.fromfile == file && ml->move.fromrow == row) { - return 1; + return true; } ml = ml->next; } - return 0; + return false; } static size_t fen_castling(char *str, GameState *gamestate) { - _Bool K, Q, k, q; + bool K, Q, k, q; if (fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('e'))) { - K = Q = 0; + K = Q = false; } else { K = !fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('h')); Q = !fen_castling_chkmoved(gamestate, rowidx('1'), fileidx('a')); } if (fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('e'))) { - k = q = 0; + k = q = false; } else { k = !fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('h')); q = !fen_castling_chkmoved(gamestate, rowidx('8'), fileidx('a'));
--- a/src/chess/queen.c Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/queen.c Wed Jun 04 23:56:40 2025 +0200 @@ -32,11 +32,11 @@ #include "bishop.h" #include "queen.h" -_Bool queen_chkrules(Move* move) { +bool queen_chkrules(Move* move) { return bishop_chkrules(move) || rook_chkrules(move); } -_Bool queen_isblocked(GameState *gamestate, Move *move) { +bool queen_isblocked(GameState *gamestate, Move *move) { if (rook_chkrules(move)) { return rook_isblocked(gamestate, move); } else {
--- a/src/chess/queen.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/queen.h Wed Jun 04 23:56:40 2025 +0200 @@ -36,8 +36,8 @@ extern "C" { #endif -_Bool queen_chkrules(Move *move); -_Bool queen_isblocked(GameState *gamestate, Move *move); +bool queen_chkrules(Move *move); +bool queen_isblocked(GameState *gamestate, Move *move); #ifdef __cplusplus }
--- a/src/chess/rook.c Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/rook.c Wed Jun 04 23:56:40 2025 +0200 @@ -30,11 +30,11 @@ #include "rules.h" #include "rook.h" -_Bool rook_chkrules(Move *move) { +bool rook_chkrules(Move *move) { return move->torow == move->fromrow || move->tofile == move->fromfile; } -_Bool rook_isblocked(GameState *gamestate, Move *move) { +bool rook_isblocked(GameState *gamestate, Move *move) { if (move->torow == move->fromrow) { int d = move->tofile > move->fromfile ? 1 : -1; @@ -42,7 +42,7 @@ while (f != move->tofile-d) { f += d; if (gamestate->board[move->fromrow][f]) { - return 1; + return true; } } } else { @@ -51,10 +51,10 @@ while (r != move->torow - d) { r += d; if (gamestate->board[r][move->fromfile]) { - return 1; + return true; } } } - return 0; + return false; }
--- a/src/chess/rook.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/rook.h Wed Jun 04 23:56:40 2025 +0200 @@ -36,8 +36,8 @@ extern "C" { #endif -_Bool rook_chkrules(Move *move); -_Bool rook_isblocked(GameState *gamestate, Move *move); +bool rook_chkrules(Move *move); +bool rook_isblocked(GameState *gamestate, Move *move); #ifdef __cplusplus }
--- 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; } }
--- a/src/chess/rules.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/chess/rules.h Wed Jun 04 23:56:40 2025 +0200 @@ -33,6 +33,7 @@ #include "game-info.h" #include <stdint.h> +#include <stdbool.h> #define VALID_MOVE_SYNTAX 0 #define VALID_MOVE_SEMANTICS 0 /* use same code for a success */ @@ -114,10 +115,10 @@ * the rare maximum of 16 elements) * @param threatcount a pointer to an uint8_t where the count of threats is * stored - * @return TRUE, if any piece of the specified color threatens the specified + * @return true, if any piece of the specified color threatens the specified * field (i.e. could capture an opponent piece) */ -_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); /** @@ -135,10 +136,10 @@ * the rare maximum of 16 elements) * @param threatcount a pointer to an uint8_t where the count of threats is * stored - * @return TRUE, if any piece of the specified color threatens the specified + * @return true, if any piece of the specified color threatens the specified * field (i.e. could capture an opponent piece) */ -_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); /** @@ -148,7 +149,7 @@ * @param row row of the field to check * @param file file of the field to check * @param color the color of the piece that should cover the field - * @return TRUE, if any piece of the specified color threatens the specified + * @return true, if any piece of the specified color threatens the specified * field */ #define is_covered(gamestate, row, file, color) \ @@ -164,7 +165,7 @@ * @param row row of the field to check * @param file file of the field to check * @param color the color of the piece that should cover the field - * @return TRUE, if any piece of the specified color threatens the specified + * @return true, if any piece of the specified color threatens the specified * field and could capture an opponent piece */ #define is_attacked(gamestate, row, file, color) \ @@ -180,10 +181,10 @@ * @param row row of the field to check * @param file file of the field to check * @param color the color of the piece that should cover the field - * @return TRUE, if any piece (excluding the king) of the specified color + * @return true, if any piece (excluding the king) of the specified color * threatens the specified field and could capture an opponent piece */ -_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); /** @@ -197,10 +198,10 @@ * * @param gamestate the current game state * @param move the move to check - * @return TRUE, if the move cannot be performed because the king would be in + * @return true, if the move cannot be performed because the king would be in * check after the move */ -_Bool is_pinned(GameState *gamestate, Move *move); +bool is_pinned(GameState *gamestate, Move *move); /** * Evaluates a move syntactically and stores the move data in the specified
--- a/src/game.c Tue Jun 03 08:43:17 2025 +0200 +++ b/src/game.c Wed Jun 04 23:56:40 2025 +0200 @@ -75,7 +75,7 @@ static void draw_board(GameState *gamestate, uint8_t perspective, - _Bool unicode) { + bool unicode) { char fen[90]; compute_fen(fen, gamestate); mvaddstr(0, 0, fen); @@ -98,7 +98,7 @@ piecestr[1] = '\0'; } - _Bool boardblack = (y&1)==(x&1); + bool boardblack = (y&1)==(x&1); attrset((col==WHITE ? A_BOLD : A_DIM)| COLOR_PAIR(col == WHITE ? (boardblack ? COL_WB : COL_WW) : @@ -135,7 +135,7 @@ } while (logelem) { - _Bool iswhite = (logelem->move.piece & COLOR_MASK) == WHITE; + bool iswhite = (logelem->move.piece & COLOR_MASK) == WHITE; if (iswhite) { logi++; printw("%d. ", logi); @@ -276,7 +276,7 @@ size_t bufpos = 0; char movestr[MOVESTR_BUFLEN]; - _Bool remisrejected = FALSE; + bool remisrejected = false; uint8_t code; flushinp(); @@ -328,7 +328,7 @@ refresh(); return 1; } else { - remisrejected = TRUE; + remisrejected = true; } } } else { @@ -528,7 +528,7 @@ } } - _Bool running; + bool running; do { clear(); draw_board(&gamestate, curcol, settings->unicode); @@ -546,10 +546,10 @@ uint8_t mycolor = is_server(settings) ? settings->gameinfo.servercolor : opponent_color(settings->gameinfo.servercolor); - _Bool myturn = (gamestate->lastmove ? + bool myturn = (gamestate->lastmove ? (gamestate->lastmove->move.piece & COLOR_MASK) : BLACK) != mycolor; - _Bool running; + bool running; do { clear(); draw_board(gamestate, mycolor, settings->unicode); @@ -559,7 +559,7 @@ } else { running = !recvmove(gamestate, &(settings->gameinfo), opponent); } - myturn ^= TRUE; + myturn ^= true; } while (running); post_game(settings, gamestate);
--- a/src/game.h Tue Jun 03 08:43:17 2025 +0200 +++ b/src/game.h Wed Jun 04 23:56:40 2025 +0200 @@ -31,6 +31,7 @@ #define GAME_H #include "chess/game-info.h" +#include <stdbool.h> #ifdef __cplusplus extern "C" { @@ -42,8 +43,8 @@ char* serverhost; /* NULL, if we are about to start a server */ char* continuepgn; char* analyzepgn; - _Bool singlemachine; - _Bool unicode; + bool singlemachine; + bool unicode; } Settings; #define is_server(settings) !((settings)->serverhost)