]> git.sesse.net Git - stockfish/commitdiff
Move all Contempt Factor code to search.cpp
authorMarco Costalba <mcostalba@gmail.com>
Sat, 13 Oct 2012 12:38:08 +0000 (14:38 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 13 Oct 2012 12:49:01 +0000 (14:49 +0200)
Where it is used.

No functional change.

src/evaluate.cpp
src/evaluate.h
src/search.cpp
src/ucioption.cpp

index 69f0e4c27fa75e4caff8b23db06d911e23819de6..b5b51d2cdc6ddecd295b0d1474b683436bbe1a82 100644 (file)
@@ -268,8 +268,6 @@ namespace {
 namespace Eval {
 
   Color RootColor;
 namespace Eval {
 
   Color RootColor;
-  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,11 +307,6 @@ namespace Eval {
         KingDangerTable[1][i] = apply_weight(make_score(t, 0), Weights[KingDangerUs]);
         KingDangerTable[0][i] = apply_weight(make_score(t, 0), Weights[KingDangerThem]);
     }
         KingDangerTable[1][i] = apply_weight(make_score(t, 0), Weights[KingDangerUs]);
         KingDangerTable[0][i] = apply_weight(make_score(t, 0), Weights[KingDangerThem]);
     }
-
-    if (Options["UCI_AnalyseMode"])
-        ContemptFactor = VALUE_ZERO;
-    else
-        ContemptFactor = Options["Contempt Factor"] * PawnValueMg / 100;
   }
 
 
   }
 
 
index 06ce9d48a631e8079bd3fc04c24e2ec998d2f89b..a0418b79d4760c84e07edd897b1ca183ea3ea1ff 100644 (file)
@@ -27,8 +27,6 @@ class Position;
 namespace Eval {
 
 extern Color RootColor;
 namespace Eval {
 
 extern Color RootColor;
-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 a3d8781889a690e15e0b91c4044c0243245f90d1..856c003a3654f758f44cc5523264fb84910255d7 100644 (file)
@@ -91,6 +91,7 @@ namespace {
   int BestMoveChanges;
   int SkillLevel;
   bool SkillLevelEnabled, Chess960;
   int BestMoveChanges;
   int SkillLevel;
   bool SkillLevelEnabled, Chess960;
+  Value DrawValue[2];
   History H;
 
   template <NodeType NT>
   History H;
 
   template <NodeType NT>
@@ -174,9 +175,6 @@ 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();
-  int scaledCF = Eval::ContemptFactor * MaterialTable::game_phase(pos) / PHASE_MIDGAME;
-  Eval::ValueDraw[ Eval::RootColor] = VALUE_DRAW - Value(scaledCF);
-  Eval::ValueDraw[~Eval::RootColor] = VALUE_DRAW + Value(scaledCF);
   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();
@@ -190,6 +188,16 @@ void Search::think() {
       goto finalize;
   }
 
       goto finalize;
   }
 
+  if (Options["Contempt Factor"] && !Options["UCI_AnalyseMode"])
+  {
+      int cf = Options["Contempt Factor"] * PawnValueMg / 100;  // In centipawns
+      cf = cf * MaterialTable::game_phase(pos) / PHASE_MIDGAME; // Scale down with phase
+      DrawValue[ Eval::RootColor] = VALUE_DRAW - Value(cf);
+      DrawValue[~Eval::RootColor] = VALUE_DRAW + Value(cf);
+  }
+  else
+      DrawValue[WHITE] = DrawValue[BLACK] = VALUE_DRAW;
+
   if (Options["OwnBook"] && !Limits.infinite)
   {
       Move bookMove = book.probe(pos, Options["Book File"], Options["Best Book Move"]);
   if (Options["OwnBook"] && !Limits.infinite)
   {
       Move bookMove = book.probe(pos, Options["Book File"], Options["Best Book Move"]);
@@ -516,7 +524,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::ValueDraw[pos.side_to_move()];
+            return DrawValue[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
@@ -577,7 +585,8 @@ namespace {
     else
     {
         refinedValue = ss->eval = evaluate(pos, ss->evalMargin);
     else
     {
         refinedValue = ss->eval = evaluate(pos, ss->evalMargin);
-        TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->eval, ss->evalMargin);
+        TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE,
+                 ss->eval, ss->evalMargin);
     }
 
     // Update gain for the parent non-capture move given the static position
     }
 
     // Update gain for the parent non-capture move given the static position
@@ -1083,7 +1092,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::ValueDraw[pos.side_to_move()];
+        return DrawValue[pos.side_to_move()];
 
     // Transposition table lookup. At PV nodes, we don't use the TT for
     // pruning, but only for move ordering.
 
     // Transposition table lookup. At PV nodes, we don't use the TT for
     // pruning, but only for move ordering.
@@ -1095,8 +1104,8 @@ split_point_start: // At split points actual search starts from here
     // 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
     // only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.
     // 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
     // only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.
-    ttDepth = inCheck || depth >= DEPTH_QS_CHECKS ? DEPTH_QS_CHECKS : DEPTH_QS_NO_CHECKS;
-
+    ttDepth = inCheck || depth >= DEPTH_QS_CHECKS ? DEPTH_QS_CHECKS
+                                                  : DEPTH_QS_NO_CHECKS;
     if (   tte && tte->depth() >= ttDepth
         && (           PvNode ?  tte->type() == BOUND_EXACT
             : ttValue >= beta ? (tte->type() & BOUND_LOWER)
     if (   tte && tte->depth() >= ttDepth
         && (           PvNode ?  tte->type() == BOUND_EXACT
             : ttValue >= beta ? (tte->type() & BOUND_LOWER)
@@ -1129,7 +1138,8 @@ split_point_start: // At split points actual search starts from here
         if (bestValue >= beta)
         {
             if (!tte)
         if (bestValue >= beta)
         {
             if (!tte)
-                TT.store(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER, DEPTH_NONE, MOVE_NONE, ss->eval, ss->evalMargin);
+                TT.store(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER,
+                         DEPTH_NONE, MOVE_NONE, ss->eval, ss->evalMargin);
 
             return bestValue;
         }
 
             return bestValue;
         }
index 1cdd4f2bb63dde0ab9f74af9e0666a0f5079dabf..f3af2f77fdb6886ce7d83693478957bd124b88f9 100644 (file)
@@ -64,7 +64,7 @@ void init(OptionsMap& o) {
   o["Search Log Filename"]         = Option("SearchLog.txt");
   o["Book File"]                   = Option("book.bin");
   o["Best Book Move"]              = Option(false);
   o["Search Log Filename"]         = Option("SearchLog.txt");
   o["Book File"]                   = Option("book.bin");
   o["Best Book Move"]              = Option(false);
-  o["Contempt Factor"]             = Option(0, -50,  50, on_eval);
+  o["Contempt Factor"]             = Option(0, -50,  50);
   o["Mobility (Middle Game)"]      = Option(100, 0, 200, on_eval);
   o["Mobility (Endgame)"]          = Option(100, 0, 200, on_eval);
   o["Passed Pawns (Middle Game)"]  = Option(100, 0, 200, on_eval);
   o["Mobility (Middle Game)"]      = Option(100, 0, 200, on_eval);
   o["Mobility (Endgame)"]          = Option(100, 0, 200, on_eval);
   o["Passed Pawns (Middle Game)"]  = Option(100, 0, 200, on_eval);