aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-03-17 19:54:44 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-03-17 19:54:44 +0100
commit6968093d6d4b72e8cc99ab4dce34321df6d98f7e (patch)
tree198ab5c3d2ac877857fc2d4e76dac7d4d5413366 /FICS
parent5706d1c44f9c0eaa7d073539e45ac38d032ce192 (diff)
Reformatted legal_king_move()
Diffstat (limited to 'FICS')
-rw-r--r--FICS/movecheck.c97
1 files changed, 58 insertions, 39 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c
index 3f08b18..5228495 100644
--- a/FICS/movecheck.c
+++ b/FICS/movecheck.c
@@ -291,46 +291,65 @@ PRIVATE int is_square_attacked (game_state_t *gs, int kf, int kr)
else return 0;
}
-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