From 4cea2a01f02948ef7617cf4c4cb2fa67d14db10c Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sun, 18 Nov 2018 20:58:52 +0100 Subject: [PATCH] Speed up move generation Simplify move generation for piece promotions, and fix quiet check piece promotions. To compensate additionally generated quiet checks, enable normal SEE calculation for piece promotions. No functional change for variants without piece promotions. --- src/movegen.cpp | 35 +++++++++++++++++++++++------------ src/position.cpp | 2 +- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index 1d79d67..296105b 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -285,23 +285,34 @@ namespace { if (Checks && (pos.blockers_for_king(~us) & from)) continue; - Bitboard b = ( (pos.attacks_from(us, pt, from) & pos.pieces()) - | (pos.moves_from(us, pt, from) & ~pos.pieces())) & target; + Bitboard b1 = ( (pos.attacks_from(us, pt, from) & pos.pieces()) + | (pos.moves_from(us, pt, from) & ~pos.pieces())) & target; + PieceType pt_promotion = pos.promoted_piece_type(pt); + Bitboard b2 = pt_promotion ? b1 : 0; if (Checks) - b &= pos.check_squares(pt); + { + b1 &= pos.check_squares(pt); + if (pt_promotion) + b2 &= pos.check_squares(pt_promotion); + } - while (b) + // Restrict target squares considering promotion zone + if (pt_promotion) { - Square s = pop_lsb(&b); - bool piece_promotion = pos.promoted_piece_type(pt) != NO_PIECE_TYPE - && (promotion_zone_bb(us, pos.promotion_rank(), pos.max_rank()) & (SquareBB[from] | s)); - if (!piece_promotion || !pos.mandatory_piece_promotion()) - *moveList++ = make_move(from, s); - // Shogi-style piece promotions - if (piece_promotion) - *moveList++ = make(from, s); + Bitboard promotion_zone = promotion_zone_bb(us, pos.promotion_rank(), pos.max_rank()); + if (pos.mandatory_piece_promotion()) + b1 &= promotion_zone & from ? 0 : ~promotion_zone; + if (!(promotion_zone & from)) + b2 &= promotion_zone; } + + while (b1) + *moveList++ = make_move(from, pop_lsb(&b1)); + + // Shogi-style piece promotions + while (b2) + *moveList++ = make(from, pop_lsb(&b2)); } return moveList; diff --git a/src/position.cpp b/src/position.cpp index c487707..6fa8f9f 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1402,7 +1402,7 @@ bool Position::see_ge(Move m, Value threshold) const { assert(is_ok(m)); // Only deal with normal moves, assume others pass a simple see - if (type_of(m) != NORMAL && type_of(m) != DROP) + if (type_of(m) != NORMAL && type_of(m) != DROP && type_of(m) != PIECE_PROMOTION) return VALUE_ZERO >= threshold; Bitboard stmAttackers; -- 1.7.0.4