diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-05-05 17:58:13 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-05-05 17:58:13 +0200 |
commit | 5f838735df6917ff95b658f486d548928f59723d (patch) | |
tree | 6a9d5c8cd4d2db269e6e3a592143f53b1b846190 | |
parent | d5dfd38e882c32f8d6788afb3a47e40ff34db73f (diff) |
Reformatted legal_king_move()
-rw-r--r-- | FICS/movecheck.c | 98 |
1 files changed, 59 insertions, 39 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c index 005eaf1..e3d1f51 100644 --- a/FICS/movecheck.c +++ b/FICS/movecheck.c @@ -307,46 +307,66 @@ PRIVATE int is_square_attacked(game_state_t * gs, int kf, int kr) } */ -PRIVATE int legal_king_move(game_state_t * gs, int ff, int fr, int tf, int tr) +PRIVATE int +legal_king_move(game_state_t *gs, int ff, int fr, int tf, int tr) { - if (gs->onMove == WHITE) { - /* King side castling */ - if ((fr == 0) && (tr == 0) && (ff == 4) && (tf == 6) && !gs->wkmoved - && (!gs->wkrmoved) && (gs->board[5][0] == NOPIECE) && - (gs->board[6][0] == NOPIECE) && (gs->board[7][0] == W_ROOK) && - (!is_square_attacked(gs, 4, 0)) && (!is_square_attacked(gs, 5, 0))) { - return 1; - } - /* Queen side castling */ - if ((fr == 0) && (tr == 0) && (ff == 4) && (tf == 2) && !gs->wkmoved - && (!gs->wqrmoved) && (gs->board[3][0] == NOPIECE) && - (gs->board[2][0] == NOPIECE) && (gs->board[1][0] == NOPIECE) && - (gs->board[0][0] == W_ROOK) && - (!is_square_attacked(gs, 4, 0)) && (!is_square_attacked(gs, 3, 0))) { - return 1; - } - } else { /* Black */ - /* King side castling */ - if ((fr == 7) && (tr == 7) && (ff == 4) && (tf == 6) && !gs->bkmoved - && (!gs->bkrmoved) && (gs->board[5][7] == NOPIECE) && - (gs->board[6][7] == NOPIECE) && (gs->board[7][7] == B_ROOK) && - (!is_square_attacked(gs, 4, 7)) && (!is_square_attacked(gs, 5, 7))) { - return 1; - } - /* Queen side castling */ - if ((fr == 7) && (tr == 7) && (ff == 4) && (tf == 2) && (!gs->bkmoved) - && (!gs->bqrmoved) && (gs->board[3][7] == NOPIECE) && - (gs->board[2][7] == NOPIECE) && (gs->board[1][7] == NOPIECE) && - (gs->board[0][7] == B_ROOK) && - (!is_square_attacked(gs, 4, 7)) && (!is_square_attacked(gs, 3, 7))) { - return 1; - } - } - if (((ff - tf) > 1) || ((tf - ff) > 1)) - return 0; - if (((fr - tr) > 1) || ((tr - fr) > 1)) - return 0; - return 1; + if (gs->onMove == WHITE) { + /* King side castling */ + if ((fr == 0) && (tr == 0) && (ff == 4) && (tf == 6) && + (!gs->wkmoved) && + (!gs->wkrmoved) && + (gs->board[5][0] == NOPIECE) && + (gs->board[6][0] == NOPIECE) && + (gs->board[7][0] == W_ROOK) && + (!is_square_attacked(gs, 4, 0)) && + (!is_square_attacked(gs, 5, 0))) { + return 1; + } + + /* Queen side castling */ + if ((fr == 0) && (tr == 0) && (ff == 4) && (tf == 2) && + (!gs->wkmoved) && + (!gs->wqrmoved) && + (gs->board[3][0] == NOPIECE) && + (gs->board[2][0] == NOPIECE) && + (gs->board[1][0] == NOPIECE) && + (gs->board[0][0] == W_ROOK) && + (!is_square_attacked(gs, 4, 0)) && + (!is_square_attacked(gs, 3, 0))) { + return 1; + } + } else { /* Black */ + /* King side castling */ + if ((fr == 7) && (tr == 7) && (ff == 4) && (tf == 6) && + (!gs->bkmoved) && + (!gs->bkrmoved) && + (gs->board[5][7] == NOPIECE) && + (gs->board[6][7] == NOPIECE) && + (gs->board[7][7] == B_ROOK) && + (!is_square_attacked(gs, 4, 7)) && + (!is_square_attacked(gs, 5, 7))) { + return 1; + } + + /* Queen side castling */ + if ((fr == 7) && (tr == 7) && (ff == 4) && (tf == 2) && + (!gs->bkmoved) && + (!gs->bqrmoved) && + (gs->board[3][7] == NOPIECE) && + (gs->board[2][7] == NOPIECE) && + (gs->board[1][7] == NOPIECE) && + (gs->board[0][7] == B_ROOK) && + (!is_square_attacked(gs, 4, 7)) && + (!is_square_attacked(gs, 3, 7))) { + return 1; + } + } + + if (((ff - tf) > 1) || ((tf - ff) > 1)) + return 0; + if (((fr - tr) > 1) || ((tr - fr) > 1)) + return 0; + return 1; } PRIVATE void |