diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-05-05 16:38:41 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-05-05 16:38:41 +0200 |
commit | b484dc6eab877084cdd82c9c56da5bd0a24656f0 (patch) | |
tree | 34ea5962b61b6119eb7a8fc4b3ddc74f8b04d9df /FICS/movecheck.c | |
parent | a162b31328b95f2007c96028ef07c66731769a24 (diff) |
Reformatted in_check()
Diffstat (limited to 'FICS/movecheck.c')
-rw-r--r-- | FICS/movecheck.c | 63 |
1 files 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 |