From 9763c69fa5683accd7e81786977be4b195370a7b Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Mon, 11 Nov 2013 19:48:29 +0100 Subject: [PATCH] Simplify generate 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 --- src/movegen.cpp | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index a254590b..a3623a69 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -364,26 +364,9 @@ ExtMove* generate(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(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 -- 2.39.2