Skip to content

Commit a95cbca

Browse files
committed
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.
1 parent d234548 commit a95cbca

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

src/position.cpp

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,10 @@ void Position::undo_null_move() {
11291129

11301130

11311131
/// Position::see() is a static exchange evaluator: It tries to estimate the
1132-
/// material gain or loss resulting from a move. There are three versions of
1133-
/// this function: One which takes a destination square as input, one takes a
1134-
/// move, and one which takes a 'from' and a 'to' square. The function does
1135-
/// not yet understand promotions captures.
1132+
/// material gain or loss resulting from a move. Parameter 'asymmThreshold' takes
1133+
/// tempi into account. If the side who initiated the capturing sequence does the
1134+
/// last capture, he loses a tempo and if the result is below 'asymmThreshold'
1135+
/// the capturing sequence is considered bad.
11361136

11371137
int Position::see_sign(Move m) const {
11381138

@@ -1147,22 +1147,7 @@ int Position::see_sign(Move m) const {
11471147
return see(m);
11481148
}
11491149

1150-
int Position::see(Move m) const {
1151-
return do_see<false>(m, 0);
1152-
}
1153-
1154-
/// Position::see_asymm() takes tempi into account.
1155-
/// If the side who initiated the capturing sequence does the last capture,
1156-
/// he loses a tempo. In this case if the result is below asymmThreshold
1157-
/// the capturing sequence is considered bad.
1158-
1159-
int Position::see_asymm(Move m, int asymmThreshold) const
1160-
{
1161-
return do_see<true>(m, asymmThreshold);
1162-
}
1163-
1164-
template <bool Asymmetric>
1165-
int Position::do_see(Move m, int asymmThreshold) const {
1150+
int Position::see(Move m, int asymmThreshold) const {
11661151

11671152
Square from, to;
11681153
Bitboard occupied, attackers, stmAttackers;
@@ -1240,16 +1225,13 @@ int Position::do_see(Move m, int asymmThreshold) const {
12401225
} while (stmAttackers);
12411226

12421227
// If we are doing asymmetric SEE evaluation and the same side does the first
1243-
// and the last capture, he loses a tempo and gain must be at least worth "asymmThreshold".
1244-
// If not, we replace the score with a very low value, before negamaxing.
1245-
if (Asymmetric)
1246-
{
1247-
for (int i = 0; i < slIndex ; i += 2)
1248-
{
1228+
// and the last capture, he loses a tempo and gain must be at least worth
1229+
// 'asymmThreshold', otherwise we replace the score with a very low value,
1230+
// before negamaxing.
1231+
if (asymmThreshold)
1232+
for (int i = 0; i < slIndex; i += 2)
12491233
if (swapList[i] < asymmThreshold)
1250-
swapList[i] = - QueenValueMg * 16;
1251-
}
1252-
}
1234+
swapList[i] = - QueenValueMg * 16;
12531235

12541236
// Having built the swap list, we negamax through it to find the best
12551237
// achievable score from the point of view of the side to move.

src/position.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ class Position {
158158
void undo_null_move();
159159

160160
// Static exchange evaluation
161-
int see(Move m) const;
161+
int see(Move m, int asymmThreshold = 0) const;
162162
int see_sign(Move m) const;
163-
int see_asymm(Move m, int asymmThreshold) const;
164163

165164
// Accessing hash keys
166165
Key key() const;
@@ -194,7 +193,6 @@ class Position {
194193

195194
// Helper functions
196195
void do_castle(Square kfrom, Square kto, Square rfrom, Square rto);
197-
template<bool Asymmetric> int do_see(Move m, int asymmThreshold) const;
198196
template<bool FindPinned> Bitboard hidden_checkers() const;
199197

200198
// Computing hash keys from scratch (for initialization and debugging)

src/search.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,11 +1225,11 @@ namespace {
12251225
continue;
12261226
}
12271227

1228-
// Prune moves with negative or equal SEE.
1229-
// Also prune moves with positive SEE where capturing loses a tempo and SEE < beta - futilityBase.
1228+
// Prune moves with negative or equal SEE and also moves with positive
1229+
// SEE where capturing piece loses a tempo and SEE < beta - futilityBase.
12301230
if ( futilityBase < beta
12311231
&& depth < DEPTH_ZERO
1232-
&& pos.see_asymm(move, beta - futilityBase) <= 0)
1232+
&& pos.see(move, beta - futilityBase) <= 0)
12331233
{
12341234
bestValue = std::max(bestValue, futilityBase);
12351235
continue;

0 commit comments

Comments
 (0)