Skip to content

Commit

Permalink
Clamp history bonus to stats range
Browse files Browse the repository at this point in the history
Before, one always had to keep track of the bonus one assigns to a history to stop
the stats from overflowing. This is a quality of life improvement. Since this would often go unnoticed during benching.

Passed non-regression bounds:
https://tests.stockfishchess.org/tests/view/65ef2af40ec64f0526c44cbc
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 179232 W: 46513 L: 46450 D: 86269
Ptnml(0-2): 716, 20323, 47452, 20432, 693

closes #5116

No functional change
  • Loading branch information
Vizvezdenec authored and Disservin committed Mar 20, 2024
1 parent fb07281 commit ed60460
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/movepick.h
Expand Up @@ -19,17 +19,17 @@
#ifndef MOVEPICK_H_INCLUDED
#define MOVEPICK_H_INCLUDED

#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <type_traits> // IWYU pragma: keep

#include "movegen.h"
#include "types.h"
#include "position.h"
#include "types.h"

namespace Stockfish {

Expand Down Expand Up @@ -69,10 +69,11 @@ class StatsEntry {
operator const T&() const { return entry; }

void operator<<(int bonus) {
assert(std::abs(bonus) <= D); // Ensure range is [-D, D]
static_assert(D <= std::numeric_limits<T>::max(), "D overflows T");

entry += bonus - entry * std::abs(bonus) / D;
// Make sure that bonus is in range [-D, D]
int clampedBonus = std::clamp(bonus, -D, D);
entry += clampedBonus - entry * std::abs(clampedBonus) / D;

assert(std::abs(entry) <= D);
}
Expand Down

0 comments on commit ed60460

Please sign in to comment.