Skip to content

Commit

Permalink
Simplify generate<EVASIONS>
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mcostalba committed Nov 11, 2013
1 parent 555d9a8 commit 9763c69
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,9 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* mlist) {

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

switch (type_of(pos.piece_on(checksq)))
{
case BISHOP: sliderAttacks |= PseudoAttacks[BISHOP][checksq]; break;
case ROOK: sliderAttacks |= PseudoAttacks[ROOK][checksq]; break;
case QUEEN:
// If queen and king are far or not on a diagonal line we can safely
// remove all the squares attacked in the other direction becuase are
// not reachable by the king anyway.
if (between_bb(ksq, checksq) || !(PseudoAttacks[BISHOP][checksq] & ksq))
sliderAttacks |= PseudoAttacks[QUEEN][checksq];

// Otherwise we need to use real rook attacks to check if king is safe
// to move in the other direction. For example: king in B2, queen in A1
// a knight in B1, and we can safely move to C1.
else
sliderAttacks |= PseudoAttacks[BISHOP][checksq] | pos.attacks_from<ROOK>(checksq);

default:
break;
}
if (type_of(pos.piece_on(checksq)) > KNIGHT) // A slider
sliderAttacks |= LineBB[checksq][ksq] ^ checksq;

} while (b);

// Generate evasions for king, capture and non capture moves
Expand Down

0 comments on commit 9763c69

Please sign in to comment.