mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Unify black and white code in generate_move_if_legal()
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
158911425b
commit
8be2c483a1
1 changed files with 78 additions and 106 deletions
|
@ -712,15 +712,14 @@ 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)) {
|
switch (type_of_piece(pc))
|
||||||
|
|
||||||
case PAWN:
|
|
||||||
// Pawn moves, as usual, are somewhat messy.
|
|
||||||
if (us == WHITE)
|
|
||||||
{
|
{
|
||||||
// If the destination square is on the 8th rank, the move must
|
case PAWN:
|
||||||
|
// 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 && !move_promotion(m))
|
if ( ( (square_rank(to) == RANK_8 && us == WHITE)
|
||||||
|
||(square_rank(to) == RANK_1 && us != WHITE))
|
||||||
|
&& !move_promotion(m))
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
|
|
||||||
// Proceed according to the square delta between the source and
|
// Proceed according to the square delta between the source and
|
||||||
|
@ -729,43 +728,6 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) {
|
||||||
{
|
{
|
||||||
case DELTA_NW:
|
case DELTA_NW:
|
||||||
case DELTA_NE:
|
case DELTA_NE:
|
||||||
// Capture. The destination square must be occupied by an enemy
|
|
||||||
// piece (en passant captures was handled earlier).
|
|
||||||
if (pos.color_of_piece_on(to) != them)
|
|
||||||
return MOVE_NONE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DELTA_N:
|
|
||||||
// Pawn push. The destination square must be empty.
|
|
||||||
if (!pos.square_is_empty(to))
|
|
||||||
return MOVE_NONE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DELTA_NN:
|
|
||||||
// Double pawn push. The destination square must be on the fourth
|
|
||||||
// rank, and both the destination square and the square between the
|
|
||||||
// source and destination squares must be empty.
|
|
||||||
if ( square_rank(to) != RANK_4
|
|
||||||
|| !pos.square_is_empty(to)
|
|
||||||
|| !pos.square_is_empty(from + DELTA_N))
|
|
||||||
return MOVE_NONE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return MOVE_NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // (us == BLACK)
|
|
||||||
{
|
|
||||||
// If the destination square is on the 1th rank, the move must
|
|
||||||
// be a promotion.
|
|
||||||
if (square_rank(to) == RANK_1 && !move_promotion(m))
|
|
||||||
return MOVE_NONE;
|
|
||||||
|
|
||||||
// Proceed according to the square delta between the source and
|
|
||||||
// destionation squares.
|
|
||||||
switch (to - from)
|
|
||||||
{
|
|
||||||
case DELTA_SW:
|
case DELTA_SW:
|
||||||
case DELTA_SE:
|
case DELTA_SE:
|
||||||
// Capture. The destination square must be occupied by an enemy
|
// Capture. The destination square must be occupied by an enemy
|
||||||
|
@ -774,14 +736,25 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) {
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DELTA_N:
|
||||||
case DELTA_S:
|
case DELTA_S:
|
||||||
// Pawn push. The destination square must be empty.
|
// Pawn push. The destination square must be empty.
|
||||||
if (!pos.square_is_empty(to))
|
if (!pos.square_is_empty(to))
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DELTA_NN:
|
||||||
|
// Double white pawn push. The destination square must be on the fourth
|
||||||
|
// rank, and both the destination square and the square between the
|
||||||
|
// source and destination squares must be empty.
|
||||||
|
if ( square_rank(to) != RANK_4
|
||||||
|
|| !pos.square_is_empty(to)
|
||||||
|
|| !pos.square_is_empty(from + DELTA_N))
|
||||||
|
return MOVE_NONE;
|
||||||
|
break;
|
||||||
|
|
||||||
case DELTA_SS:
|
case DELTA_SS:
|
||||||
// Double pawn push. The destination square must be on the fifth
|
// Double black pawn push. The destination square must be on the fifth
|
||||||
// rank, and both the destination square and the square between the
|
// rank, and both the destination square and the square between the
|
||||||
// source and destination squares must be empty.
|
// source and destination squares must be empty.
|
||||||
if ( square_rank(to) != RANK_5
|
if ( square_rank(to) != RANK_5
|
||||||
|
@ -793,7 +766,6 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) {
|
||||||
default:
|
default:
|
||||||
return MOVE_NONE;
|
return MOVE_NONE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 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;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue