Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use per-thread dynamic contempt #1515

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#include "evaluate.h"
#include "material.h"
#include "pawns.h"

std::atomic<Score> Eval::Contempt;
#include "thread.h"

namespace Trace {

Expand Down Expand Up @@ -844,7 +843,7 @@ namespace {
// Initialize score by reading the incrementally updated scores included in
// the position object (material + piece square tables) and the material
// imbalance. Score is computed internally from the white point of view.
Score score = pos.psq_score() + me->imbalance() + Eval::Contempt;
Score score = pos.psq_score() + me->imbalance() + pos.this_thread()->contemptScore;

// Probe the pawn hash table
pe = Pawns::probe(pos);
Expand Down Expand Up @@ -915,7 +914,7 @@ std::string Eval::trace(const Position& pos) {

std::memset(scores, 0, sizeof(scores));

Eval::Contempt = SCORE_ZERO; // Reset any dynamic contempt
pos.this_thread()->contemptScore = SCORE_ZERO; // Reset any dynamic contempt

Value v = Evaluation<TRACE>(pos).value();

Expand Down
2 changes: 0 additions & 2 deletions src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace Eval {

constexpr Value Tempo = Value(20); // Must be visible to search

extern std::atomic<Score> Contempt;

std::string trace(const Position& pos);

Value evaluate(const Position& pos);
Expand Down
8 changes: 4 additions & 4 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ void Thread::search() {
multiPV = std::min(multiPV, rootMoves.size());

int ct = Options["Contempt"] * PawnValueEg / 100; // From centipawns
Eval::Contempt = (us == WHITE ? make_score(ct, ct / 2)
: -make_score(ct, ct / 2));
contemptScore = (us == WHITE ? make_score(ct, ct / 2)
: -make_score(ct, ct / 2));

// Iterative deepening loop until requested to stop or the target depth is reached
while ( (rootDepth += ONE_PLY) < DEPTH_MAX
Expand Down Expand Up @@ -353,8 +353,8 @@ void Thread::search() {
// Adjust contempt based on root move's previousScore (dynamic contempt)
ct += int(std::round(48 * atan(float(previousScore) / 128)));

Eval::Contempt = (us == WHITE ? make_score(ct, ct / 2)
: -make_score(ct, ct / 2));
contemptScore = (us == WHITE ? make_score(ct, ct / 2)
: -make_score(ct, ct / 2));
}

// Start with a small aspiration window and, in the case of a fail
Expand Down
1 change: 1 addition & 0 deletions src/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Thread {
ButterflyHistory mainHistory;
CapturePieceToHistory captureHistory;
ContinuationHistory contHistory;
Score contemptScore;
};


Expand Down