mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Movegen: further simplify generate_move_if_legal
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
8be2c483a1
commit
c852a94009
1 changed files with 8 additions and 40 deletions
|
@ -712,9 +712,8 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) {
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
|
|
||||||
// Proceed according to the type of the moving piece.
|
// Proceed according to the type of the moving piece.
|
||||||
switch (type_of_piece(pc))
|
if (type_of_piece(pc) == PAWN)
|
||||||
{
|
{
|
||||||
case PAWN:
|
|
||||||
// If the destination square is on the 8/1th rank, the move must
|
// If the destination square is on the 8/1th rank, the move must
|
||||||
// be a promotion.
|
// be a promotion.
|
||||||
if ( ( (square_rank(to) == RANK_8 && us == WHITE)
|
if ( ( (square_rank(to) == RANK_8 && us == WHITE)
|
||||||
|
@ -768,43 +767,12 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) {
|
||||||
}
|
}
|
||||||
// The move is pseudo-legal. Return it if it is legal.
|
// The move is pseudo-legal. Return it if it is legal.
|
||||||
return (pos.move_is_legal(m) ? m : MOVE_NONE);
|
return (pos.move_is_legal(m) ? m : MOVE_NONE);
|
||||||
break;
|
}
|
||||||
|
|
||||||
case KNIGHT:
|
// Luckly we can handle all the other pieces in one go
|
||||||
return ( pos.knight_attacks_square(from, to)
|
return ( pos.piece_attacks_square(from, to)
|
||||||
&& pos.move_is_legal(m)
|
&& pos.move_is_legal(m)
|
||||||
&& !move_promotion(m) ? m : MOVE_NONE);
|
&& !move_promotion(m) ? m : MOVE_NONE);
|
||||||
break;
|
|
||||||
|
|
||||||
case BISHOP:
|
|
||||||
return ( pos.bishop_attacks_square(from, to)
|
|
||||||
&& pos.move_is_legal(m)
|
|
||||||
&& !move_promotion(m) ? m : MOVE_NONE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ROOK:
|
|
||||||
return ( pos.rook_attacks_square(from, to)
|
|
||||||
&& pos.move_is_legal(m)
|
|
||||||
&& !move_promotion(m) ? m : MOVE_NONE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QUEEN:
|
|
||||||
return ( pos.queen_attacks_square(from, to)
|
|
||||||
&& pos.move_is_legal(m)
|
|
||||||
&& !move_promotion(m) ? m : MOVE_NONE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KING:
|
|
||||||
return ( pos.king_attacks_square(from, to)
|
|
||||||
&& pos.move_is_legal(m)
|
|
||||||
&& !move_promotion(m) ? m : MOVE_NONE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
assert(false);
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue