From b484dc6eab877084cdd82c9c56da5bd0a24656f0 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 5 May 2024 16:38:41 +0200 Subject: Reformatted in_check() --- FICS/movecheck.c | 63 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/FICS/movecheck.c b/FICS/movecheck.c index 6bd8cd5..bfe65cc 100644 --- a/FICS/movecheck.c +++ b/FICS/movecheck.c @@ -754,38 +754,45 @@ PUBLIC int legal_andcheck_move(game_state_t * gs, return 0; } -PUBLIC int in_check(game_state_t * gs) +PUBLIC int +in_check(game_state_t *gs) { - int f, r; - int kf = -1, kr = -1; + int f, r; + int kf = -1, kr = -1; + + /* Find the king */ + if (gs->onMove == WHITE) { + for (f = 0; f < 8 && kf < 0; f++) { + for (r = 0; r < 8 && kf < 0; r++) { + if (gs->board[f][r] == B_KING) { + kf = f; + kr = r; + } + } + } + } else { + for (f = 0; f < 8 && kf < 0; f++) { + for (r = 0; r < 8 && kf < 0; r++) { + if (gs->board[f][r] == W_KING) { + kf = f; + kr = r; + } + } + } + } - /* Find the king */ - if (gs->onMove == WHITE) { - for (f = 0; f < 8 && kf < 0; f++) - for (r = 0; r < 8 && kf < 0; r++) - if (gs->board[f][r] == B_KING) { - kf = f; - kr = r; + if (kf < 0) { + fprintf(stderr, "FICS: Error game with no king!\n"); + return 0; } - } else { - for (f = 0; f < 8 && kf < 0; f++) - for (r = 0; r < 8 && kf < 0; r++) - if (gs->board[f][r] == W_KING) { - kf = f; - kr = r; + + for (InitPieceLoop(gs->board, &f, &r, gs->onMove); + NextPieceLoop(gs->board, &f, &r, gs->onMove);) { + if (legal_move(gs, f, r, kf, kr)) // // In Check? + return 1; } - } - if (kf < 0) { - fprintf(stderr, "FICS: Error game with no king!\n"); - return 0; - } - for (InitPieceLoop(gs->board, &f, &r, gs->onMove); - NextPieceLoop(gs->board, &f, &r, gs->onMove);) { - if (legal_move(gs, f, r, kf, kr)) { /* In Check? */ - return 1; - } - } - return 0; + + return 0; } PRIVATE int -- cgit v1.2.3