Skip to content

Commit

Permalink
Assorted trivial cleanups
Browse files Browse the repository at this point in the history
Renaming doubleExtensions variable to multiExtensions, since now we have also triple extensions.

Some extra cleanups.

Recent tests used to measure the elo worth:
https://tests.stockfishchess.org/tests/view/659fd0c379aa8af82b96abc3
https://tests.stockfishchess.org/tests/view/65a8f3da79aa8af82b9751e3
https://tests.stockfishchess.org/tests/view/65b51824c865510db0272740
https://tests.stockfishchess.org/tests/view/65b58fbfc865510db0272f5b

closes #5032

No functional change
  • Loading branch information
FauziAkram authored and Disservin committed Feb 9, 2024
1 parent ededadc commit 59691d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/nnue/nnue_feature_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class FeatureTransformer {
reinterpret_cast<const vec_t*>(&(accumulation[perspectives[p]][HalfDimensions / 2]));
vec_t* out = reinterpret_cast<vec_t*>(output + offset);

for (IndexType j = 0; j < NumOutputChunks; j += 1)
for (IndexType j = 0; j < NumOutputChunks; ++j)
{
const vec_t sum0a = vec_max_16(vec_min_16(in0[j * 2 + 0], One), Zero);
const vec_t sum0b = vec_max_16(vec_min_16(in0[j * 2 + 1], One), Zero);
Expand Down Expand Up @@ -676,9 +676,7 @@ class FeatureTransformer {
update_accumulator_incremental<Perspective, 2>(pos, oldest_st, states_to_update);
}
else
{
update_accumulator_refresh<Perspective>(pos);
}
}

template<Color Perspective>
Expand Down
20 changes: 10 additions & 10 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ Value Search::Worker::search(
(ss + 1)->excludedMove = bestMove = Move::none();
(ss + 2)->killers[0] = (ss + 2)->killers[1] = Move::none();
(ss + 2)->cutoffCnt = 0;
ss->doubleExtensions = (ss - 1)->doubleExtensions;
ss->multipleExtensions = (ss - 1)->multipleExtensions;
Square prevSq = ((ss - 1)->currentMove).is_ok() ? ((ss - 1)->currentMove).to_sq() : SQ_NONE;
ss->statScore = 0;

Expand Down Expand Up @@ -1036,8 +1036,8 @@ Value Search::Worker::search(
{
extension = 1;

// Avoid search explosion by limiting the number of double extensions
if (!PvNode && ss->doubleExtensions <= 16)
// We make sure to limit the extensions in some way to avoid a search explosion
if (!PvNode && ss->multipleExtensions <= 16)
{
extension = 2 + (value < singularBeta - 78 && !ttCapture);
depth += depth < 16;
Expand Down Expand Up @@ -1090,7 +1090,7 @@ Value Search::Worker::search(

// Add extension to new depth
newDepth += extension;
ss->doubleExtensions = (ss - 1)->doubleExtensions + (extension >= 2);
ss->multipleExtensions = (ss - 1)->multipleExtensions + (extension >= 2);

// Speculative prefetch as early as possible
prefetch(tt.first_entry(pos.key_after(move)));
Expand Down Expand Up @@ -1142,15 +1142,15 @@ Value Search::Worker::search(
+ (*contHist[1])[movedPiece][move.to_sq()]
+ (*contHist[3])[movedPiece][move.to_sq()] - 4409;

// Decrease/increase reduction for moves with a good/bad history (~25 Elo)
// Decrease/increase reduction for moves with a good/bad history (~8 Elo)
r -= ss->statScore / 14894;

// Step 17. Late moves reduction / extension (LMR, ~117 Elo)
if (depth >= 2 && moveCount > 1 + rootNode)
{
// In general we want to cap the LMR depth search at newDepth, but when
// reduction is negative, we allow this move a limited search extension
// beyond the first move depth. This may lead to hidden double extensions.
// beyond the first move depth. This may lead to hidden multiple extensions.
// To prevent problems when the max value is less than the min value,
// std::clamp has been replaced by a more robust implementation.
Depth d = std::max(1, std::min(newDepth - r, newDepth + 1));
Expand Down Expand Up @@ -1371,8 +1371,8 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
assert(PvNode || (alpha == beta - 1));
assert(depth <= 0);

// Check if we have an upcoming move that draws by repetition, or
// if the opponent had an alternative move earlier to this position.
// Check if we have an upcoming move that draws by repetition, or if
// the opponent had an alternative move earlier to this position. (~1 Elo)
if (alpha < VALUE_DRAW && pos.has_game_cycle(ss->ply))
{
alpha = value_draw(this->nodes);
Expand Down Expand Up @@ -1520,15 +1520,15 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
futilityValue = futilityBase + PieceValue[pos.piece_on(move.to_sq())];

// If static eval + value of piece we are going to capture is much lower
// than alpha we can prune this move.
// than alpha we can prune this move. (~2 Elo)
if (futilityValue <= alpha)
{
bestValue = std::max(bestValue, futilityValue);
continue;
}

// If static eval is much lower than alpha and move is not winning material
// we can prune this move.
// we can prune this move. (~2 Elo)
if (futilityBase <= alpha && !pos.see_ge(move, VALUE_ZERO + 1))
{
bestValue = std::max(bestValue, futilityBase);
Expand Down
11 changes: 5 additions & 6 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Stack {
bool inCheck;
bool ttPv;
bool ttHit;
int doubleExtensions;
int multipleExtensions;
int cutoffCnt;
};

Expand Down Expand Up @@ -136,9 +136,8 @@ struct SharedState {

class Worker;

// Null Object Pattern, implement a common interface
// for the SearchManagers. A Null Object will be given to
// non-mainthread workers.
// Null Object Pattern, implement a common interface for the SearchManagers.
// A Null Object will be given to non-mainthread workers.
class ISearchManager {
public:
virtual ~ISearchManager() {}
Expand Down Expand Up @@ -185,8 +184,8 @@ class Worker {
// Reset histories, usually before a new game
void clear();

// Called when the program receives the UCI 'go'
// command. It searches from the root position and outputs the "bestmove".
// Called when the program receives the UCI 'go' command.
// It searches from the root position and outputs the "bestmove".
void start_searching();

bool is_mainthread() const { return thread_idx == 0; }
Expand Down

0 comments on commit 59691d4

Please sign in to comment.