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

Dynamic contempt #1394

Closed
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
2 changes: 1 addition & 1 deletion src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ namespace {

} // namespace

Score Eval::Contempt = SCORE_ZERO;
std::atomic<Score> Eval::Contempt;

/// evaluate() is the evaluator for the outer world. It returns a static evaluation
/// of the position from the point of view of the side to move.
Expand Down
3 changes: 2 additions & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef EVALUATE_H_INCLUDED
#define EVALUATE_H_INCLUDED

#include <atomic>
#include <string>

#include "types.h"
Expand All @@ -31,7 +32,7 @@ namespace Eval {

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

extern Score Contempt;
extern std::atomic<Score> Contempt;

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

Expand Down
20 changes: 15 additions & 5 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ void MainThread::search() {
Time.init(Limits, us, rootPos.game_ply());
TT.new_search();

int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns

Eval::Contempt = (us == WHITE ? make_score(contempt, contempt / 2)
: -make_score(contempt, contempt / 2));

if (rootMoves.empty())
{
rootMoves.emplace_back(MOVE_NONE);
Expand Down Expand Up @@ -306,6 +301,10 @@ void Thread::search() {

multiPV = std::min(multiPV, rootMoves.size());

int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
Eval::Contempt = (rootPos.side_to_move() == WHITE ? make_score(contempt, contempt / 2)
: -make_score(contempt, contempt / 2));

// Iterative deepening loop until requested to stop or the target depth is reached
while ( (rootDepth += ONE_PLY) < DEPTH_MAX
&& !Threads.stop
Expand Down Expand Up @@ -340,6 +339,17 @@ void Thread::search() {
delta = Value(18);
alpha = std::max(rootMoves[PVIdx].previousScore - delta,-VALUE_INFINITE);
beta = std::min(rootMoves[PVIdx].previousScore + delta, VALUE_INFINITE);

// Adjust contempt based on current situation

contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
contempt += bestValue > 2 * PawnValueEg ? PawnValueEg / 5: // Dynamic contempt
bestValue < -2 * PawnValueEg ? -PawnValueEg / 5:
bestValue/10;

Eval::Contempt = (rootPos.side_to_move() == WHITE ? make_score(contempt, contempt / 2)
: -make_score(contempt, contempt / 2));

}

// Start with a small aspiration window and, in the case of a fail
Expand Down
2 changes: 1 addition & 1 deletion src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void init(OptionsMap& o) {
const int MaxHashMB = Is64Bit ? 131072 : 2048;

o["Debug Log File"] << Option("", on_logger);
o["Contempt"] << Option(20, -100, 100);
o["Contempt"] << Option(18, -100, 100);
o["Threads"] << Option(1, 1, 512, on_threads);
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
o["Clear Hash"] << Option(on_clear_hash);
Expand Down