diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2023-12-14 22:53:34 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2023-12-14 22:53:34 +0100 |
commit | c63c8efd7109ae7695823e4ad612d1f68e0d69c7 (patch) | |
tree | d7b3e0334ed952b71502b9722c599be87e13de98 | |
parent | f7ca190d54973fd3d5d3f67df8414bcc884b0521 (diff) |
Reformatted move_calculate()
-rw-r--r-- | FICS/movecheck.c | 112 |
1 files changed, 62 insertions, 50 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c index 568cbf2..8456e59 100644 --- a/FICS/movecheck.c +++ b/FICS/movecheck.c @@ -646,61 +646,73 @@ PUBLIC int legal_move(game_state_t * gs, } -/* This fills in the rest of the mt structure once it is determined that - * the move is legal. Returns MOVE_ILLEGAL if move leaves you in check */ -PRIVATE int move_calculate(game_state_t * gs, move_t * mt, int promote) +/* + * This fills in the rest of the mt structure once it is determined + * that. (Returns 'MOVE_ILLEGAL' if move leaves you in check.) + */ +PRIVATE int +move_calculate(game_state_t *gs, move_t *mt, int promote) { - game_state_t fakeMove; + game_state_t fakeMove; + + mt->pieceCaptured = gs->board[mt->toFile][mt->toRank]; + mt->enPassant = 0; // Don't know yet, + // let execute move take care of it + + if (mt->fromFile == ALG_DROP) { + mt->piecePromotionTo = NOPIECE; + sprintf(mt->moveString, "%s/%c%c-%c%d", + wpstring[mt->fromRank], + DROP_CHAR, + DROP_CHAR, + mt->toFile + 'a', + mt->toRank + 1); + } else { + if (piecetype(gs->board[mt->fromFile][mt->fromRank]) == PAWN && + (mt->toRank == 0 || mt->toRank == 7)) { + mt->piecePromotionTo = (promote | + colorval(gs->board[mt->fromFile][mt->fromRank])); + } else { + mt->piecePromotionTo = NOPIECE; + } - mt->pieceCaptured = gs->board[mt->toFile][mt->toRank]; - mt->enPassant = 0; /* Don't know yet, let execute move take care - of it */ - if (mt->fromFile == ALG_DROP) { - mt->piecePromotionTo = NOPIECE; - sprintf(mt->moveString, "%s/%c%c-%c%d", - wpstring[mt->fromRank], - DROP_CHAR, DROP_CHAR, - mt->toFile + 'a', mt->toRank + 1); - } else { - if ((piecetype(gs->board[mt->fromFile][mt->fromRank]) == PAWN) && - ((mt->toRank == 0) || (mt->toRank == 7))) { - mt->piecePromotionTo = promote | - (colorval(gs->board[mt->fromFile][mt->fromRank])); - } else { - mt->piecePromotionTo = NOPIECE; - } - if ((piecetype(gs->board[mt->fromFile][mt->fromRank]) == PAWN) && - ((mt->fromRank - mt->toRank == 2) || (mt->toRank - mt->fromRank == 2))) { - mt->doublePawn = mt->fromFile; - } else { - mt->doublePawn = -1; - } - if ((piecetype(gs->board[mt->fromFile][mt->fromRank]) == KING) && - (mt->fromFile == 4) && (mt->toFile == 2)) { - sprintf(mt->moveString, "o-o-o"); - } else if ((piecetype(gs->board[mt->fromFile][mt->fromRank]) == KING) && - (mt->fromFile == 4) && (mt->toFile == 6)) { - sprintf(mt->moveString, "o-o"); - } else { - sprintf(mt->moveString, "%s/%c%d-%c%d", - wpstring[piecetype(gs->board[mt->fromFile][mt->fromRank])], - mt->fromFile + 'a', mt->fromRank + 1, - mt->toFile + 'a', mt->toRank + 1); - } - } - /* Replace this with an algabraic de-parser */ + if (piecetype(gs->board[mt->fromFile][mt->fromRank]) == PAWN && + (mt->fromRank - mt->toRank == 2 || + mt->toRank - mt->fromRank == 2)) { + mt->doublePawn = mt->fromFile; + } else { + mt->doublePawn = -1; + } - sprintf(mt->algString, alg_unparse(gs, mt)); - fakeMove = *gs; - /* Calculates enPassant also */ - execute_move(&fakeMove, mt, 0); + if (piecetype(gs->board[mt->fromFile][mt->fromRank]) == KING && + mt->fromFile == 4 && + mt->toFile == 2) { + sprintf(mt->moveString, "o-o-o"); + } else if (piecetype(gs->board[mt->fromFile][mt->fromRank]) == KING && + mt->fromFile == 4 && + mt->toFile == 6) { + sprintf(mt->moveString, "o-o"); + } else { + sprintf(mt->moveString, "%s/%c%d-%c%d", + wpstring[piecetype(gs->board[mt->fromFile][mt->fromRank])], + mt->fromFile + 'a', + mt->fromRank + 1, + mt->toFile + 'a', + mt->toRank + 1); + } + } - /* Does making this move leave ME in check? */ - if (in_check(&fakeMove)) - return MOVE_ILLEGAL; - /* IanO: bughouse variants: drop cannot be check/checkmate */ + // Replace this with an algabraic de-parser + sprintf(mt->algString, alg_unparse(gs, mt)); + fakeMove = *gs; + execute_move(&fakeMove, mt, 0); // Calculates enPassant also - return MOVE_OK; + // Does making this move leave ME in check? + if (in_check(&fakeMove)) + return MOVE_ILLEGAL; + // IanO: bughouse variants: drop cannot be check/checkmate + + return MOVE_OK; } PUBLIC int legal_andcheck_move(game_state_t * gs, |