Skip to content

Commit 9763c69

Browse files
committed
Simplify generate<EVASIONS>
Use the newly introduced LineBB[] to simplify this super hot-path function. Verified with perft we don't have any speed regression, although the number of squares removed is less than before in case of contact check. Insipred by DiscoCheck implementation. Perft numbers are the same, but we have an harmless functional change due to reorder of moves, because now some illegal moves are no more detected at generation time, but in the search. bench: 8331357
1 parent 555d9a8 commit 9763c69

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

src/movegen.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -364,26 +364,9 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* mlist) {
364364

365365
assert(color_of(pos.piece_on(checksq)) == ~us);
366366

367-
switch (type_of(pos.piece_on(checksq)))
368-
{
369-
case BISHOP: sliderAttacks |= PseudoAttacks[BISHOP][checksq]; break;
370-
case ROOK: sliderAttacks |= PseudoAttacks[ROOK][checksq]; break;
371-
case QUEEN:
372-
// If queen and king are far or not on a diagonal line we can safely
373-
// remove all the squares attacked in the other direction becuase are
374-
// not reachable by the king anyway.
375-
if (between_bb(ksq, checksq) || !(PseudoAttacks[BISHOP][checksq] & ksq))
376-
sliderAttacks |= PseudoAttacks[QUEEN][checksq];
377-
378-
// Otherwise we need to use real rook attacks to check if king is safe
379-
// to move in the other direction. For example: king in B2, queen in A1
380-
// a knight in B1, and we can safely move to C1.
381-
else
382-
sliderAttacks |= PseudoAttacks[BISHOP][checksq] | pos.attacks_from<ROOK>(checksq);
383-
384-
default:
385-
break;
386-
}
367+
if (type_of(pos.piece_on(checksq)) > KNIGHT) // A slider
368+
sliderAttacks |= LineBB[checksq][ksq] ^ checksq;
369+
387370
} while (b);
388371

389372
// Generate evasions for king, capture and non capture moves

0 commit comments

Comments
 (0)