diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-05-05 16:49:46 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-05-05 16:49:46 +0200 |
commit | dfd1b35e80c6d17c238327bd61c46c3af3c65b8f (patch) | |
tree | 86b18779a3106967662bd16042e81961388bdc0a | |
parent | 9c5df0e8a1e085215a5e7fbac282250e41e4e745 (diff) |
Reformatted legal_move()
-rw-r--r-- | FICS/movecheck.c | 111 |
1 files changed, 58 insertions, 53 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c index 08fb846..df13cd5 100644 --- a/FICS/movecheck.c +++ b/FICS/movecheck.c @@ -591,62 +591,67 @@ 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) { - 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 (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; +} /* * This fills in the rest of the mt structure once it is determined |