mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Speed-up generate<LEGAL>
The trick here is to check for legality only in the (rare) cases we have pinned pieces or a king move or an en-passant. This trick is able to increase the speed of perft of more then 20%! No functional change.
This commit is contained in:
parent
1598a3edf8
commit
e0bd0f250b
1 changed files with 3 additions and 1 deletions
|
@ -420,11 +420,13 @@ MoveStack* generate<LEGAL>(const Position& pos, MoveStack* mlist) {
|
||||||
|
|
||||||
MoveStack *end, *cur = mlist;
|
MoveStack *end, *cur = mlist;
|
||||||
Bitboard pinned = pos.pinned_pieces();
|
Bitboard pinned = pos.pinned_pieces();
|
||||||
|
Square ksq = pos.king_square(pos.side_to_move());
|
||||||
|
|
||||||
end = pos.in_check() ? generate<EVASIONS>(pos, mlist)
|
end = pos.in_check() ? generate<EVASIONS>(pos, mlist)
|
||||||
: generate<NON_EVASIONS>(pos, mlist);
|
: generate<NON_EVASIONS>(pos, mlist);
|
||||||
while (cur != end)
|
while (cur != end)
|
||||||
if (!pos.pl_move_is_legal(cur->move, pinned))
|
if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT)
|
||||||
|
&& !pos.pl_move_is_legal(cur->move, pinned))
|
||||||
cur->move = (--end)->move;
|
cur->move = (--end)->move;
|
||||||
else
|
else
|
||||||
cur++;
|
cur++;
|
||||||
|
|
Loading…
Add table
Reference in a new issue