mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Optimize generate_evasions()
Generate captures of checking piece and blocking evasions in one go. Also reduce of one indentation level early returning when we have a double check. Verified with perft no functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
483a257618
commit
53c2bf0697
1 changed files with 54 additions and 70 deletions
|
@ -246,14 +246,14 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
|||
// Generate evasions for other pieces only if not double check. We use a
|
||||
// simple bit twiddling hack here rather than calling count_1s in order to
|
||||
// save some time (we know that pos.checkers() has at most two nonzero bits).
|
||||
if (!(checkers & (checkers - 1))) // Only one bit set?
|
||||
{
|
||||
if (checkers & (checkers - 1)) // Two bits set?
|
||||
return mlist;
|
||||
|
||||
Square checksq = first_1(checkers);
|
||||
Bitboard target = squares_between(checksq, ksq);
|
||||
|
||||
assert(pos.color_of_piece_on(checksq) == them);
|
||||
|
||||
// Generate captures of the checking piece
|
||||
|
||||
// Pawn captures
|
||||
b1 = pos.attacks_from<PAWN>(checksq, them) & pos.pieces(PAWN, us) & ~pinned;
|
||||
while (b1)
|
||||
|
@ -269,33 +269,18 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
|||
(*mlist++).move = make_move(from, checksq);
|
||||
}
|
||||
|
||||
// Pieces captures
|
||||
b1 = ( (pos.attacks_from<KNIGHT>(checksq) & pos.pieces(KNIGHT, us))
|
||||
| (pos.attacks_from<BISHOP>(checksq) & pos.pieces(BISHOP, QUEEN, us))
|
||||
| (pos.attacks_from<ROOK>(checksq) & pos.pieces(ROOK, QUEEN, us)) ) & ~pinned;
|
||||
|
||||
while (b1)
|
||||
{
|
||||
from = pop_1st_bit(&b1);
|
||||
(*mlist++).move = make_move(from, checksq);
|
||||
}
|
||||
|
||||
// Blocking check evasions are possible only if the checking piece is a slider
|
||||
// Pawn blocking evasions (possible only if the checking piece is a slider)
|
||||
if (sliderAttacks)
|
||||
{
|
||||
Bitboard blockSquares = squares_between(checksq, ksq);
|
||||
mlist = generate_piece_evasions<PAWN>(pos, mlist, us, target, pinned);
|
||||
|
||||
assert((pos.occupied_squares() & blockSquares) == EmptyBoardBB);
|
||||
// Add the checking piece to the target squares
|
||||
target |= checkers;
|
||||
|
||||
if (blockSquares)
|
||||
{
|
||||
mlist = generate_piece_evasions<PAWN>(pos, mlist, us, blockSquares, pinned);
|
||||
mlist = generate_piece_evasions<KNIGHT>(pos, mlist, us, blockSquares, pinned);
|
||||
mlist = generate_piece_evasions<BISHOP>(pos, mlist, us, blockSquares, pinned);
|
||||
mlist = generate_piece_evasions<ROOK>(pos, mlist, us, blockSquares, pinned);
|
||||
mlist = generate_piece_evasions<QUEEN>(pos, mlist, us, blockSquares, pinned);
|
||||
}
|
||||
}
|
||||
// Captures and blocking evasions for the other pieces
|
||||
mlist = generate_piece_evasions<KNIGHT>(pos, mlist, us, target, pinned);
|
||||
mlist = generate_piece_evasions<BISHOP>(pos, mlist, us, target, pinned);
|
||||
mlist = generate_piece_evasions<ROOK>(pos, mlist, us, target, pinned);
|
||||
mlist = generate_piece_evasions<QUEEN>(pos, mlist, us, target, pinned);
|
||||
|
||||
// Finally, the special case of en passant captures. An en passant
|
||||
// capture can only be a check evasion if the check is not a discovered
|
||||
|
@ -322,7 +307,6 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
|||
(*mlist++).move = make_ep_move(from, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mlist;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue