mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-20 17:16:33 +08:00
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.
This commit is contained in:
@@ -1129,10 +1129,10 @@ void Position::undo_null_move() {
|
|||||||
|
|
||||||
|
|
||||||
/// Position::see() is a static exchange evaluator: It tries to estimate the
|
/// 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
|
/// material gain or loss resulting from a move. Parameter 'asymmThreshold' takes
|
||||||
/// this function: One which takes a destination square as input, one takes a
|
/// tempi into account. If the side who initiated the capturing sequence does the
|
||||||
/// move, and one which takes a 'from' and a 'to' square. The function does
|
/// last capture, he loses a tempo and if the result is below 'asymmThreshold'
|
||||||
/// not yet understand promotions captures.
|
/// the capturing sequence is considered bad.
|
||||||
|
|
||||||
int Position::see_sign(Move m) const {
|
int Position::see_sign(Move m) const {
|
||||||
|
|
||||||
@@ -1147,22 +1147,7 @@ int Position::see_sign(Move m) const {
|
|||||||
return see(m);
|
return see(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Position::see(Move m) const {
|
int Position::see(Move m, int asymmThreshold) const {
|
||||||
return do_see<false>(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<true>(m, asymmThreshold);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <bool Asymmetric>
|
|
||||||
int Position::do_see(Move m, int asymmThreshold) const {
|
|
||||||
|
|
||||||
Square from, to;
|
Square from, to;
|
||||||
Bitboard occupied, attackers, stmAttackers;
|
Bitboard occupied, attackers, stmAttackers;
|
||||||
@@ -1240,16 +1225,13 @@ int Position::do_see(Move m, int asymmThreshold) const {
|
|||||||
} while (stmAttackers);
|
} while (stmAttackers);
|
||||||
|
|
||||||
// If we are doing asymmetric SEE evaluation and the same side does the first
|
// 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".
|
// and the last capture, he loses a tempo and gain must be at least worth
|
||||||
// If not, we replace the score with a very low value, before negamaxing.
|
// 'asymmThreshold', otherwise we replace the score with a very low value,
|
||||||
if (Asymmetric)
|
// before negamaxing.
|
||||||
{
|
if (asymmThreshold)
|
||||||
for (int i = 0; i < slIndex ; i += 2)
|
for (int i = 0; i < slIndex; i += 2)
|
||||||
{
|
|
||||||
if (swapList[i] < asymmThreshold)
|
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
|
// 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.
|
// achievable score from the point of view of the side to move.
|
||||||
|
|||||||
@@ -158,9 +158,8 @@ public:
|
|||||||
void undo_null_move();
|
void undo_null_move();
|
||||||
|
|
||||||
// Static exchange evaluation
|
// Static exchange evaluation
|
||||||
int see(Move m) const;
|
int see(Move m, int asymmThreshold = 0) const;
|
||||||
int see_sign(Move m) const;
|
int see_sign(Move m) const;
|
||||||
int see_asymm(Move m, int asymmThreshold) const;
|
|
||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key key() const;
|
Key key() const;
|
||||||
@@ -194,7 +193,6 @@ private:
|
|||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
void do_castle(Square kfrom, Square kto, Square rfrom, Square rto);
|
void do_castle(Square kfrom, Square kto, Square rfrom, Square rto);
|
||||||
template<bool Asymmetric> int do_see(Move m, int asymmThreshold) const;
|
|
||||||
template<bool FindPinned> Bitboard hidden_checkers() const;
|
template<bool FindPinned> Bitboard hidden_checkers() const;
|
||||||
|
|
||||||
// Computing hash keys from scratch (for initialization and debugging)
|
// Computing hash keys from scratch (for initialization and debugging)
|
||||||
|
|||||||
@@ -1225,11 +1225,11 @@ split_point_start: // At split points actual search starts from here
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prune moves with negative or equal SEE.
|
// Prune moves with negative or equal SEE and also moves with positive
|
||||||
// Also prune moves with positive SEE where capturing loses a tempo and SEE < beta - futilityBase.
|
// SEE where capturing piece loses a tempo and SEE < beta - futilityBase.
|
||||||
if ( futilityBase < beta
|
if ( futilityBase < beta
|
||||||
&& depth < DEPTH_ZERO
|
&& depth < DEPTH_ZERO
|
||||||
&& pos.see_asymm(move, beta - futilityBase) <= 0)
|
&& pos.see(move, beta - futilityBase) <= 0)
|
||||||
{
|
{
|
||||||
bestValue = std::max(bestValue, futilityBase);
|
bestValue = std::max(bestValue, futilityBase);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user