]> git.sesse.net Git - stockfish/commitdiff
Fix Contempt Factor implementation
authorMarco Costalba <mcostalba@gmail.com>
Sat, 6 Oct 2012 08:12:34 +0000 (10:12 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 6 Oct 2012 08:12:34 +0000 (10:12 +0200)
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
src/evaluate.h
src/search.cpp

index fdfacc10b910f71d0a7a802afd8f0d8d33efda46..69f0e4c27fa75e4caff8b23db06d911e23819de6 100644 (file)
@@ -268,7 +268,8 @@ namespace {
 namespace Eval {
 
   Color RootColor;
 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
 
   /// 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]);
     }
 
         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;
   }
 
 
   }
 
 
index 9c2b2a61b0439abea503bbf8fd4ec6e794f57b6d..06ce9d48a631e8079bd3fc04c24e2ec998d2f89b 100644 (file)
@@ -27,7 +27,8 @@ class Position;
 namespace Eval {
 
 extern Color RootColor;
 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);
 
 extern void init();
 extern Value evaluate(const Position& pos, Value& margin);
index c9a8f58204a4dc9ecddce0f4c3013e1f21b64afd..4d1a6af784d1e41217df9b29c3676c20a55dc6cd 100644 (file)
@@ -199,6 +199,8 @@ void Search::think() {
   Position& pos = RootPosition;
   Chess960 = pos.is_chess960();
   Eval::RootColor = pos.side_to_move();
   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();
   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<false>() || ss->ply > MAX_PLY)
     {
         // Step 2. Check for aborted search and immediate draw
         if (Signals.stop || pos.is_draw<false>() || 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
 
         // 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<true>() || ss->ply > MAX_PLY)
 
     // Check for an instant draw or maximum ply reached
     if (pos.is_draw<true>() || 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
 
     // 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