Skip to content

Commit

Permalink
Reintroduce Contempt
Browse files Browse the repository at this point in the history
Bench 2771721
Attempt something similar to XintheDark
 contempt_reintro1a contempt_reintro1b
@cj5716
cj5716 committed
  • Loading branch information
Zerbinati committed Jun 23, 2023
1 parent 1a41bed commit bfcc0ea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,12 +1070,15 @@ Value Eval::evaluate(const Position& pos) {

Color stm = pos.side_to_move();
Value optimism = pos.this_thread()->optimism[stm];
Value contempt = stm == WHITE ? -pos.this_thread()->contempt : pos.this_thread()->contempt;


Value nnue = NNUE::evaluate(pos, true, &nnueComplexity);

// Blend optimism with nnue complexity and (semi)classical complexity
optimism += optimism * (nnueComplexity + abs(psq - nnue)) / 512;
v = (nnue * (945 + npm) + optimism * (150 + npm)) / 1024;
v += v * (stm == WHITE ? 1 : -1) >= 0 ? contempt : 0;
}

// Damp down the evaluation linearly when shuffling
Expand Down
4 changes: 4 additions & 0 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ void Thread::search() {

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

int ct = Options["Contempt"] * PawnValueEg / 100;
int searchAgainCounter = 0;

// Iterative deepening loop until requested to stop or the target depth is reached
Expand Down Expand Up @@ -522,6 +523,9 @@ void Thread::search() {
alpha = std::max(prev - delta,-VALUE_INFINITE);
beta = std::min(prev + delta, VALUE_INFINITE);

// Adjust contempt based on root move's previousScore
contempt = Value(ct) + 88 * prev / (std::abs(prev) + 200);

// Adjust optimism based on root move's previousScore
int opt = 109 * prev / (std::abs(prev) + 141);
optimism[ us] = Value(opt);
Expand Down
2 changes: 1 addition & 1 deletion src/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Thread {
size_t pvIdx, pvLast;
std::atomic<uint64_t> nodes, tbHits, bestMoveChanges;
int selDepth, nmpMinPly;
Value bestValue, optimism[COLOR_NB];
Value bestValue, optimism[COLOR_NB], contempt;

Position rootPos;
StateInfo rootState;
Expand Down
3 changes: 1 addition & 2 deletions src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ static void on_book1(const Option& o) { Book::on_book(0, (string)o); }
static void on_book2(const Option& o) { Book::on_book(1, (string)o); }
static void on_book3(const Option& o) { Book::on_book(2, (string)o); }
static void on_tb_path(const Option& o) { Tablebases::init(o); }
static void on_predicted_S(const Option&) { Search::init(); }
static void on_predicted_F(const Option&) { Search::init(); }
static void on_exp_enabled(const Option& /*o*/) { Experience::init(); }
static void on_exp_file(const Option& /*o*/) { Experience::init(); }
static void on_use_NNUE(const Option&) { Eval::NNUE::init(); }
Expand Down Expand Up @@ -78,6 +76,7 @@ void init(OptionsMap& o) {
o["Ponder"] << Option(false);
o["MultiPV"] << Option(1, 1, 500);
o["Skill Level"] << Option(20, 0, 20);
o["Contempt"] << Option(20, -100, 100);
o["Move Overhead"] << Option(10, 0, 5000);
o["Minimum Thinking Time"] << Option(100, 0, 5000);
o["Slow Mover"] << Option(100, 10, 1000);
Expand Down

0 comments on commit bfcc0ea

Please sign in to comment.