1
0
Fork 0
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:
Marco Costalba 2012-09-11 20:00:58 +02:00
parent 1598a3edf8
commit e0bd0f250b

View file

@ -420,11 +420,13 @@ MoveStack* generate<LEGAL>(const Position& pos, MoveStack* mlist) {
MoveStack *end, *cur = mlist;
Bitboard pinned = pos.pinned_pieces();
Square ksq = pos.king_square(pos.side_to_move());
end = pos.in_check() ? generate<EVASIONS>(pos, mlist)
: generate<NON_EVASIONS>(pos, mlist);
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;
else
cur++;