mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Use special handling for promotions in move_is_legal()
Simplifies a bit the code and the common case too. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
98b09b4038
commit
544adf7e41
1 changed files with 8 additions and 15 deletions
|
@ -335,7 +335,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
||||||
Piece pc = pos.piece_on(from);
|
Piece pc = pos.piece_on(from);
|
||||||
|
|
||||||
// Use a slower but simpler function for uncommon cases
|
// Use a slower but simpler function for uncommon cases
|
||||||
if (move_is_ep(m) || move_is_castle(m))
|
if (move_is_special(m))
|
||||||
return move_is_legal(pos, m);
|
return move_is_legal(pos, m);
|
||||||
|
|
||||||
// If the from square is not occupied by a piece belonging to the side to
|
// If the from square is not occupied by a piece belonging to the side to
|
||||||
|
@ -355,14 +355,9 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
||||||
if ((us == WHITE) != (direction > 0))
|
if ((us == WHITE) != (direction > 0))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// A pawn move is a promotion iff the destination square is
|
// We have already handled promotion moves, so destination
|
||||||
// on the 8/1th rank.
|
// cannot be on the 8/1th rank.
|
||||||
if (( (square_rank(to) == RANK_8 && us == WHITE)
|
if (square_rank(to) == RANK_8 || square_rank(to) == RANK_1)
|
||||||
||(square_rank(to) == RANK_1 && us != WHITE)) != bool(move_is_promotion(m)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// The promotion piece, if any, must be valid
|
|
||||||
if (move_promotion_piece(m) > QUEEN || move_promotion_piece(m) == PAWN)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Proceed according to the square delta between the origin and
|
// Proceed according to the square delta between the origin and
|
||||||
|
@ -409,14 +404,12 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// The move is pseudo-legal, check if it is also legal
|
|
||||||
return pos.is_check() ? pos.pl_move_is_evasion(m, pinned) : pos.pl_move_is_legal(m, pinned);
|
|
||||||
}
|
}
|
||||||
|
else if (!bit_is_set(pos.attacks_from(pc, from), to))
|
||||||
|
return false;
|
||||||
|
|
||||||
// Luckly we can handle all the other pieces in one go
|
// The move is pseudo-legal, check if it is also legal
|
||||||
return bit_is_set(pos.attacks_from(pc, from), to)
|
return pos.is_check() ? pos.pl_move_is_evasion(m, pinned) : pos.pl_move_is_legal(m, pinned);
|
||||||
&& (pos.is_check() ? pos.pl_move_is_evasion(m, pinned) : pos.pl_move_is_legal(m, pinned))
|
|
||||||
&& !move_is_promotion(m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue