aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/movecheck.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-03-16 21:08:06 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-03-16 21:08:06 +0100
commita35f58a4cc3acd8e4c89b6de0a334510dbbc1709 (patch)
tree6f420c32bb94729db5bff5318737b244c6844d1a /FICS/movecheck.c
parentc5781670b233a62370cb45c5ae657eec5967cf8b (diff)
Reformatted legal_move()
Diffstat (limited to 'FICS/movecheck.c')
-rw-r--r--FICS/movecheck.c108
1 files changed, 55 insertions, 53 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c
index 0f406e8..dcae95c 100644
--- a/FICS/movecheck.c
+++ b/FICS/movecheck.c
@@ -593,62 +593,64 @@ PRIVATE void possible_king_moves(game_state_t * gs,
}
/* Doesn't check for check */
-PUBLIC int legal_move(game_state_t * gs,
- int fFile, int fRank,
- int tFile, int tRank)
+PUBLIC int
+legal_move(game_state_t *gs,
+ int fFile, int fRank,
+ int tFile, int tRank)
{
- int move_piece;
- int legal;
+ int legal;
+ int move_piece;
+
+ if (fFile == ALG_DROP) {
+ if ((move_piece = fRank) == KING)
+ return 0;
+ if (gs->holding[gs->onMove == WHITE ? 0 : 1][move_piece - 1]
+ == 0)
+ return 0;
+ if (gs->board[tFile][tRank] != NOPIECE)
+ return 0;
+ if (move_piece == PAWN && (tRank == 0 || tRank == 7))
+ return 0;
+ return 1;
+ } else {
+ move_piece = piecetype(gs->board[fFile][fRank]);
+ }
- if (fFile == ALG_DROP) {
- move_piece = fRank;
- if (move_piece == KING)
- return 0;
- if (gs->holding[gs->onMove==WHITE ? 0 : 1][move_piece-1] == 0)
- return 0;
- if (gs->board[tFile][tRank] != NOPIECE)
- return 0;
- if (move_piece == PAWN && (tRank == 0 || tRank == 7))
- return 0;
- return 1;
- } else {
- move_piece = piecetype(gs->board[fFile][fRank]);
- }
- if (gs->board[fFile][fRank] == NOPIECE)
- return 0;
- if (!iscolor(gs->board[fFile][fRank], gs->onMove)) /* Wrong color */
- return 0;
- if ((gs->board[tFile][tRank] != NOPIECE) &&
- iscolor(gs->board[tFile][tRank], gs->onMove)) /* Can't capture own */
- return 0;
- if ((fFile == tFile) && (fRank == tRank)) /* Same square */
- return 0;
- switch (move_piece) {
- case PAWN:
- legal = legal_pawn_move(gs, fFile, fRank, tFile, tRank);
- break;
- case KNIGHT:
- legal = legal_knight_move(gs, fFile, fRank, tFile, tRank);
- break;
- case BISHOP:
- legal = legal_bishop_move(gs, fFile, fRank, tFile, tRank);
- break;
- case ROOK:
- legal = legal_rook_move(gs, fFile, fRank, tFile, tRank);
- break;
- case QUEEN:
- legal = legal_queen_move(gs, fFile, fRank, tFile, tRank);
- break;
- case KING:
- legal = legal_king_move(gs, fFile, fRank, tFile, tRank);
- break;
- default:
- return 0;
- break;
- }
- return legal;
-}
+ if (gs->board[fFile][fRank] == NOPIECE)
+ return 0;
+ if (!iscolor(gs->board[fFile][fRank], gs->onMove)) // Wrong color
+ return 0;
+ if (gs->board[tFile][tRank] != NOPIECE &&
+ iscolor(gs->board[tFile][tRank], gs->onMove)) // Can't capture own
+ return 0;
+ if (fFile == tFile && fRank == tRank) // Same square
+ return 0;
+ switch (move_piece) {
+ case PAWN:
+ legal = legal_pawn_move(gs, fFile, fRank, tFile, tRank);
+ break;
+ case KNIGHT:
+ legal = legal_knight_move(gs, fFile, fRank, tFile, tRank);
+ break;
+ case BISHOP:
+ legal = legal_bishop_move(gs, fFile, fRank, tFile, tRank);
+ break;
+ case ROOK:
+ legal = legal_rook_move(gs, fFile, fRank, tFile, tRank);
+ break;
+ case QUEEN:
+ legal = legal_queen_move(gs, fFile, fRank, tFile, tRank);
+ break;
+ case KING:
+ legal = legal_king_move(gs, fFile, fRank, tFile, tRank);
+ break;
+ default:
+ return 0;
+ }
+
+ return legal;
+}
/*
* This fills in the rest of the mt structure once it is determined