From ed436a36bade82422753f8be9c16d790232e9c91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ste=CC=81phane=20Nicolet?= Date: Wed, 16 Jun 2021 07:23:26 +0200 Subject: [PATCH] Remove the Contempt UCI option This patch removes the UCI option for setting Contempt in classical evaluation. It is exactly equivalent to using Contempt=0 for the UCI contempt value and keeping the dynamic part in the algo (renaming this dynamic part `trend` to better describe what it does). We have tried quite hard to implement a working Contempt feature for NNUE but nothing really worked, so it is probably time to give up. Interested chess fans wishing to keep playing with the UCI option for Contempt and use it with the classical eval are urged to download the version tagged "SF_Classical" of Stockfish (dated 31 July 2020), as it was the last version where our search algorithm was tuned for the classical eval and is probably our strongest classical player ever: https://github.com/official-stockfish/Stockfish/tags Passed STC: LLR: 2.95 (-2.94,2.94) <-2.50,0.50> Total: 72904 W: 6228 L: 6175 D: 60501 Ptnml(0-2): 221, 5006, 25971, 5007, 247 https://tests.stockfishchess.org/tests/view/60c98bf9457376eb8bcab18d Passed LTC: LLR: 2.93 (-2.94,2.94) <-2.50,0.50> Total: 45168 W: 1601 L: 1547 D: 42020 Ptnml(0-2): 38, 1331, 19786, 1397, 32 https://tests.stockfishchess.org/tests/view/60c9c7fa457376eb8bcab1bb closes https://github.com/official-stockfish/Stockfish/pull/3575 Bench: 4947716 --- README.md | 8 -------- src/evaluate.cpp | 4 ++-- src/search.cpp | 22 +++++----------------- src/thread.h | 2 +- src/ucioption.cpp | 2 -- 5 files changed, 8 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 0bbe4abb..79db8170 100644 --- a/README.md +++ b/README.md @@ -120,14 +120,6 @@ change them via a chess GUI. This is a list of available UCI options in Stockfis Limit Syzygy tablebase probing to positions with at most this many pieces left (including kings and pawns). - * #### Contempt - A positive value for contempt favors middle game positions and avoids draws, - effective for the classical evaluation only. - - * #### Analysis Contempt - By default, contempt is set to prefer the side to move. Set this option to "White" - or "Black" to analyse with contempt for that side, or "Off" to disable contempt. - * #### Move Overhead Assume a time delay of x ms due to network and GUI overheads. This is useful to avoid losses on time in those cases. diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 1366d0fb..6a032fc0 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -979,7 +979,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() + pos.this_thread()->contempt; + Score score = pos.psq_score() + me->imbalance() + pos.this_thread()->trend; // Probe the pawn hash table pe = Pawns::probe(pos); @@ -1139,7 +1139,7 @@ std::string Eval::trace(Position& pos) { std::memset(scores, 0, sizeof(scores)); - pos.this_thread()->contempt = SCORE_ZERO; // Reset any dynamic contempt + pos.this_thread()->trend = SCORE_ZERO; // Reset any dynamic contempt v = Evaluation(pos).value(); diff --git a/src/search.cpp b/src/search.cpp index 9bba563a..62f02d83 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -312,19 +312,7 @@ void Thread::search() { multiPV = std::min(multiPV, rootMoves.size()); ttHitAverage = TtHitAverageWindow * TtHitAverageResolution / 2; - int ct = int(Options["Contempt"]) * PawnValueEg / 100; // From centipawns - - // In analysis mode, adjust contempt in accordance with user preference - if (Limits.infinite || Options["UCI_AnalyseMode"]) - ct = Options["Analysis Contempt"] == "Off" ? 0 - : Options["Analysis Contempt"] == "Both" ? ct - : Options["Analysis Contempt"] == "White" && us == BLACK ? -ct - : Options["Analysis Contempt"] == "Black" && us == WHITE ? -ct - : ct; - - // Evaluation score is from the white point of view - contempt = (us == WHITE ? make_score(ct, ct / 2) - : -make_score(ct, ct / 2)); + trend = SCORE_ZERO; int searchAgainCounter = 0; @@ -370,11 +358,11 @@ 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 (dynamic contempt) - int dct = ct + (113 - ct / 2) * prev / (abs(prev) + 147); + // Adjust trend based on root move's previousScore (dynamic contempt) + int tr = 113 * prev / (abs(prev) + 147); - contempt = (us == WHITE ? make_score(dct, dct / 2) - : -make_score(dct, dct / 2)); + trend = (us == WHITE ? make_score(tr, tr / 2) + : -make_score(tr, tr / 2)); } // Start with a small aspiration window and, in the case of a fail diff --git a/src/thread.h b/src/thread.h index ae662880..5bfa2359 100644 --- a/src/thread.h +++ b/src/thread.h @@ -74,7 +74,7 @@ public: LowPlyHistory lowPlyHistory; CapturePieceToHistory captureHistory; ContinuationHistory continuationHistory[2][2]; - Score contempt; + Score trend; }; diff --git a/src/ucioption.cpp b/src/ucioption.cpp index d59c0100..07b3027d 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -61,8 +61,6 @@ void init(OptionsMap& o) { constexpr int MaxHashMB = Is64Bit ? 33554432 : 2048; o["Debug Log File"] << Option("", on_logger); - o["Contempt"] << Option(24, -100, 100); - o["Analysis Contempt"] << Option("Both var Off var White var Black var Both", "Both"); o["Threads"] << Option(1, 1, 512, on_threads); o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size); o["Clear Hash"] << Option(on_clear_hash); -- 2.39.2