From cedbd3332a4a1574e701bda098a9df1153e299c6 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 6 Oct 2012 10:12:34 +0200 Subject: [PATCH 1/1] Fix Contempt Factor implementation First disable Contempt Factor during analysis, then calculate the modified draw score from the point of view of the player, so from the point of view of RootPosition color. Thanks to Ryan Taker for suggesting the fixes. No functional change. --- src/evaluate.cpp | 8 ++++++-- src/evaluate.h | 3 ++- src/search.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index fdfacc10..69f0e4c2 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -268,7 +268,8 @@ namespace { namespace Eval { Color RootColor; - Value ValueDrawContempt; + Value ContemptFactor; + Value ValueDraw[2]; /// evaluate() is the main evaluation function. It always computes two /// values, an endgame score and a middle game score, and interpolates @@ -309,7 +310,10 @@ namespace Eval { KingDangerTable[0][i] = apply_weight(make_score(t, 0), Weights[KingDangerThem]); } - ValueDrawContempt = VALUE_DRAW - Options["Contempt Factor"] * PawnValueMg / 100; + if (Options["UCI_AnalyseMode"]) + ContemptFactor = VALUE_ZERO; + else + ContemptFactor = Options["Contempt Factor"] * PawnValueMg / 100; } diff --git a/src/evaluate.h b/src/evaluate.h index 9c2b2a61..06ce9d48 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -27,7 +27,8 @@ class Position; namespace Eval { extern Color RootColor; -extern Value ValueDrawContempt; +extern Value ContemptFactor; +extern Value ValueDraw[2]; extern void init(); extern Value evaluate(const Position& pos, Value& margin); diff --git a/src/search.cpp b/src/search.cpp index c9a8f582..4d1a6af7 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -199,6 +199,8 @@ void Search::think() { Position& pos = RootPosition; Chess960 = pos.is_chess960(); Eval::RootColor = pos.side_to_move(); + Eval::ValueDraw[ Eval::RootColor] = VALUE_DRAW - Eval::ContemptFactor; + Eval::ValueDraw[~Eval::RootColor] = VALUE_DRAW + Eval::ContemptFactor; TimeMgr.init(Limits, pos.startpos_ply_counter(), pos.side_to_move()); TT.new_search(); H.clear(); @@ -538,7 +540,7 @@ namespace { { // Step 2. Check for aborted search and immediate draw if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY) - return Eval::ValueDrawContempt; + return Eval::ValueDraw[pos.side_to_move()]; // Step 3. Mate distance pruning. Even if we mate at the next move our score // would be at best mate_in(ss->ply+1), but if alpha is already bigger because @@ -1094,7 +1096,7 @@ split_point_start: // At split points actual search starts from here // Check for an instant draw or maximum ply reached if (pos.is_draw() || ss->ply > MAX_PLY) - return Eval::ValueDrawContempt; + return Eval::ValueDraw[pos.side_to_move()]; // Decide whether or not to include checks, this fixes also the type of // TT entry depth that we are going to use. Note that in qsearch we use -- 2.39.2