mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Small micro optimization in generate_evasions()
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
a7cb05b1eb
commit
746bcb348f
1 changed files with 10 additions and 11 deletions
|
@ -225,6 +225,8 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Color them = opposite_color(us);
|
Color them = opposite_color(us);
|
||||||
Square ksq = pos.king_square(us);
|
Square ksq = pos.king_square(us);
|
||||||
|
Bitboard sliderAttacks = EmptyBoardBB;
|
||||||
|
Bitboard checkers = pos.checkers();
|
||||||
|
|
||||||
assert(pos.piece_on(ksq) == piece_of_color_and_type(us, KING));
|
assert(pos.piece_on(ksq) == piece_of_color_and_type(us, KING));
|
||||||
|
|
||||||
|
@ -236,30 +238,28 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
||||||
// remove them from king evasions set so to avoid a couple
|
// remove them from king evasions set so to avoid a couple
|
||||||
// of cycles in the slow king evasions legality check loop
|
// of cycles in the slow king evasions legality check loop
|
||||||
// and to be able to use attackers_to().
|
// and to be able to use attackers_to().
|
||||||
Bitboard checkers = pos.checkers();
|
|
||||||
Bitboard checkersAttacks = EmptyBoardBB;
|
|
||||||
Bitboard b = checkers & pos.pieces(BISHOP, QUEEN);
|
Bitboard b = checkers & pos.pieces(BISHOP, QUEEN);
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
from = pop_1st_bit(&b);
|
from = pop_1st_bit(&b);
|
||||||
checkersAttacks |= bishop_attacks_bb(from, b_noKing);
|
sliderAttacks |= bishop_attacks_bb(from, b_noKing);
|
||||||
}
|
}
|
||||||
|
|
||||||
b = checkers & pos.pieces(ROOK, QUEEN);
|
b = checkers & pos.pieces(ROOK, QUEEN);
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
from = pop_1st_bit(&b);
|
from = pop_1st_bit(&b);
|
||||||
checkersAttacks |= rook_attacks_bb(from, b_noKing);
|
sliderAttacks |= rook_attacks_bb(from, b_noKing);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate evasions for king
|
// Generate evasions for king, both captures and non captures
|
||||||
Bitboard b1 = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~checkersAttacks;
|
Bitboard b1 = pos.attacks_from<KING>(ksq) & ~pos.pieces_of_color(us) & ~sliderAttacks;
|
||||||
Bitboard enemy = pos.pieces_of_color(them);
|
Bitboard enemy = pos.pieces_of_color(them);
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
to = pop_1st_bit(&b1);
|
to = pop_1st_bit(&b1);
|
||||||
// Note that we can use attackers_to() only because we
|
// Note that we can use attackers_to() only because we
|
||||||
// have already removed slider checkers.
|
// have already removed slider checkers attacked squares.
|
||||||
if (!(pos.attackers_to(to) & enemy))
|
if (!(pos.attackers_to(to) & enemy))
|
||||||
(*mlist++).move = make_move(ksq, to);
|
(*mlist++).move = make_move(ksq, to);
|
||||||
}
|
}
|
||||||
|
@ -301,15 +301,14 @@ MoveStack* generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pin
|
||||||
(*mlist++).move = make_move(from, checksq);
|
(*mlist++).move = make_move(from, checksq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blocking check evasions are possible only if the checking piece is
|
// Blocking check evasions are possible only if the checking piece is a slider
|
||||||
// a slider.
|
if (sliderAttacks)
|
||||||
if (checkers & (pos.pieces(BISHOP) | pos.pieces(ROOK) | pos.pieces(QUEEN)))
|
|
||||||
{
|
{
|
||||||
Bitboard blockSquares = squares_between(checksq, ksq);
|
Bitboard blockSquares = squares_between(checksq, ksq);
|
||||||
|
|
||||||
assert((pos.occupied_squares() & blockSquares) == EmptyBoardBB);
|
assert((pos.occupied_squares() & blockSquares) == EmptyBoardBB);
|
||||||
|
|
||||||
if (blockSquares != EmptyBoardBB)
|
if (blockSquares)
|
||||||
{
|
{
|
||||||
mlist = generate_piece_moves<PAWN>(pos, mlist, us, blockSquares, pinned);
|
mlist = generate_piece_moves<PAWN>(pos, mlist, us, blockSquares, pinned);
|
||||||
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, blockSquares, pinned);
|
mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, blockSquares, pinned);
|
||||||
|
|
Loading…
Add table
Reference in a new issue