From: Marco Costalba Date: Tue, 9 Apr 2013 21:18:28 +0000 (+0200) Subject: Simplify and speed up previous patch X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=a95cbca568ec393ea6b4b17ed86f89c75d7cbe57;hp=d23454854e72e1311363a8c98cd58a5d44c427f9 Simplify and speed up previous patch Use an optinal argument instead of a template parameter. Interestingly, not only is simpler, but also faster, perhaps due to less L1 instruction cache pressure because we don't duplicate the very used SEE code path. No functional change. --- diff --git a/src/position.cpp b/src/position.cpp index 1b2defa5..5193d20e 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1129,10 +1129,10 @@ void Position::undo_null_move() { /// Position::see() is a static exchange evaluator: It tries to estimate the -/// material gain or loss resulting from a move. There are three versions of -/// this function: One which takes a destination square as input, one takes a -/// move, and one which takes a 'from' and a 'to' square. The function does -/// not yet understand promotions captures. +/// material gain or loss resulting from a move. Parameter 'asymmThreshold' takes +/// tempi into account. If the side who initiated the capturing sequence does the +/// last capture, he loses a tempo and if the result is below 'asymmThreshold' +/// the capturing sequence is considered bad. int Position::see_sign(Move m) const { @@ -1147,22 +1147,7 @@ int Position::see_sign(Move m) const { return see(m); } -int Position::see(Move m) const { - return do_see(m, 0); -} - -/// Position::see_asymm() takes tempi into account. -/// If the side who initiated the capturing sequence does the last capture, -/// he loses a tempo. In this case if the result is below asymmThreshold -/// the capturing sequence is considered bad. - -int Position::see_asymm(Move m, int asymmThreshold) const -{ - return do_see(m, asymmThreshold); -} - -template -int Position::do_see(Move m, int asymmThreshold) const { +int Position::see(Move m, int asymmThreshold) const { Square from, to; Bitboard occupied, attackers, stmAttackers; @@ -1240,16 +1225,13 @@ int Position::do_see(Move m, int asymmThreshold) const { } while (stmAttackers); // If we are doing asymmetric SEE evaluation and the same side does the first - // and the last capture, he loses a tempo and gain must be at least worth "asymmThreshold". - // If not, we replace the score with a very low value, before negamaxing. - if (Asymmetric) - { - for (int i = 0; i < slIndex ; i += 2) - { + // and the last capture, he loses a tempo and gain must be at least worth + // 'asymmThreshold', otherwise we replace the score with a very low value, + // before negamaxing. + if (asymmThreshold) + for (int i = 0; i < slIndex; i += 2) if (swapList[i] < asymmThreshold) - swapList[i] = - QueenValueMg * 16; - } - } + swapList[i] = - QueenValueMg * 16; // Having built the swap list, we negamax through it to find the best // achievable score from the point of view of the side to move. diff --git a/src/position.h b/src/position.h index 0951b466..c41d31cf 100644 --- a/src/position.h +++ b/src/position.h @@ -158,9 +158,8 @@ public: void undo_null_move(); // Static exchange evaluation - int see(Move m) const; + int see(Move m, int asymmThreshold = 0) const; int see_sign(Move m) const; - int see_asymm(Move m, int asymmThreshold) const; // Accessing hash keys Key key() const; @@ -194,7 +193,6 @@ private: // Helper functions void do_castle(Square kfrom, Square kto, Square rfrom, Square rto); - template int do_see(Move m, int asymmThreshold) const; template Bitboard hidden_checkers() const; // Computing hash keys from scratch (for initialization and debugging) diff --git a/src/search.cpp b/src/search.cpp index 5abbafbc..f58baf39 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1225,11 +1225,11 @@ split_point_start: // At split points actual search starts from here continue; } - // Prune moves with negative or equal SEE. - // Also prune moves with positive SEE where capturing loses a tempo and SEE < beta - futilityBase. + // Prune moves with negative or equal SEE and also moves with positive + // SEE where capturing piece loses a tempo and SEE < beta - futilityBase. if ( futilityBase < beta && depth < DEPTH_ZERO - && pos.see_asymm(move, beta - futilityBase) <= 0) + && pos.see(move, beta - futilityBase) <= 0) { bestValue = std::max(bestValue, futilityBase); continue;