]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Add Tord's polynomial material balance
[stockfish] / src / evaluate.cpp
index 44ca040b5f393636f4cdbd2c90a7753cc949ec42..ecc73b3543d4963d17a1fa630231a1d4729b195d 100644 (file)
@@ -58,15 +58,15 @@ namespace {
   // parameters at 100, which looks prettier.
   //
   // Values modified by Joona Kiiski
-  const int WeightMobilityMidgameInternal      = 0x0FA;
-  const int WeightMobilityEndgameInternal      = 0x10A;
-  const int WeightPawnStructureMidgameInternal = 0x0EC;
-  const int WeightPawnStructureEndgameInternal = 0x0CD;
-  const int WeightPassedPawnsMidgameInternal   = 0x108;
-  const int WeightPassedPawnsEndgameInternal   = 0x109;
-  const int WeightKingSafetyInternal           = 0x0F7;
-  const int WeightKingOppSafetyInternal        = 0x101;
-  const int WeightSpaceInternal                = 0x02F;
+  const int WeightMobilityMidgameInternal      = 248;
+  const int WeightMobilityEndgameInternal      = 271;
+  const int WeightPawnStructureMidgameInternal = 233;
+  const int WeightPawnStructureEndgameInternal = 201;
+  const int WeightPassedPawnsMidgameInternal   = 252;
+  const int WeightPassedPawnsEndgameInternal   = 259;
+  const int WeightKingSafetyInternal           = 247;
+  const int WeightKingOppSafetyInternal        = 259;
+  const int WeightSpaceInternal                = 46;
 
   // Mobility and outposts bonus modified by Joona Kiiski
   //
@@ -284,7 +284,7 @@ namespace {
                                     EvalInfo &ei);
   void evaluate_trapped_bishop_a1h1(const Position &pos, Square s, Color us,
                                     EvalInfo &ei);
-
+  template<bool HasPopCnt>
   void evaluate_space(const Position &p, Color us, EvalInfo &ei);
   inline Value apply_weight(Value v, int w);
   Value scale_by_game_phase(Value mv, Value ev, Phase ph, const ScaleFactor sf[]);
@@ -326,8 +326,8 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
 
   // Probe the material hash table
   ei.mi = MaterialTable[threadID]->get_material_info(pos);
-  ei.mgValue += ei.mi->mg_value();
-  ei.egValue += ei.mi->eg_value();
+  ei.mgValue += ei.mi->material_value();
+  ei.egValue += ei.mi->material_value();
 
   // If we have a specialized evaluation function for the current material
   // configuration, call it and return
@@ -403,8 +403,8 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
     // Evaluate space for both sides
     if (ei.mi->space_weight() > 0)
     {
-        evaluate_space(pos, WHITE, ei);
-        evaluate_space(pos, BLACK, ei);
+        evaluate_space<HasPopCnt>(pos, WHITE, ei);
+        evaluate_space<HasPopCnt>(pos, BLACK, ei);
     }
   }
 
@@ -532,6 +532,14 @@ void read_weights(Color us) {
 
   WeightKingSafety[us]   = weight_option("Cowardice", WeightKingSafetyInternal);
   WeightKingSafety[them] = weight_option("Aggressiveness", WeightKingOppSafetyInternal);
+  // If running in analysis mode, make sure we use symmetrical king safety.
+  // We do this by replacing both WeightKingSafety[us] and 
+  // WeightKingSafety[them] by their average.
+  if (get_option_value_bool("UCI_AnalyseMode")) {
+      WeightKingSafety[us] = (WeightKingSafety[us] + WeightKingSafety[them]) / 2;
+      WeightKingSafety[them] = WeightKingSafety[us];
+  }
+
   WeightSpace = weight_option("Space", WeightSpaceInternal);
 
   init_safety();
@@ -1117,7 +1125,7 @@ namespace {
   // squares one, two or three squares behind a friendly pawn are counted
   // twice. Finally, the space bonus is scaled by a weight taken from the
   // material hash table.
-
+  template<bool HasPopCnt>
   void evaluate_space(const Position &pos, Color us, EvalInfo &ei) {
 
     Color them = opposite_color(us);
@@ -1145,8 +1153,8 @@ namespace {
         behindFriendlyPawns |= (behindFriendlyPawns << 16);
     }
 
-    int space =  count_1s_max_15(safeSquares)
-               + count_1s_max_15(behindFriendlyPawns & safeSquares);
+    int space =  count_1s_max_15<HasPopCnt>(safeSquares)
+               + count_1s_max_15<HasPopCnt>(behindFriendlyPawns & safeSquares);
 
     ei.mgValue += Sign[us] * apply_weight(Value(space * ei.mi->space_weight()), WeightSpace);
   }