]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Evaluate: weight_option() is static
[stockfish] / src / evaluate.cpp
index ed04aa54026722219ce4e71444163a287c2ad137..f44173445bac916afc72090d68d5a217b0d4cc2d 100644 (file)
@@ -63,6 +63,7 @@ namespace {
   const int WeightPassedPawnsMidgameInternal   = 0x100;
   const int WeightPassedPawnsEndgameInternal   = 0x100;
   const int WeightKingSafetyInternal           = 0x100;
+  const int WeightKingOppSafetyInternal        = 0x100;
 
   // Visually better to define tables constants
   typedef Value V;
@@ -274,6 +275,7 @@ namespace {
   int count_1s_8bit(Bitboard b);
 
   int compute_weight(int uciWeight, int internalWeight);
+  int weight_option(const std::string& opt, int weight);
   void init_safety();
 
 }
@@ -538,32 +540,19 @@ void quit_eval() {
 /// read_weights() reads evaluation weights from the corresponding UCI
 /// parameters.
 
-void read_weights(Color sideToMove) {
-  WeightMobilityMidgame =
-    compute_weight(get_option_value_int("Mobility (Middle Game)"),
-                   WeightMobilityMidgameInternal);
-  WeightMobilityEndgame =
-    compute_weight(get_option_value_int("Mobility (Endgame)"),
-                   WeightMobilityEndgameInternal);
-  WeightPawnStructureMidgame =
-    compute_weight(get_option_value_int("Pawn Structure (Middle Game)"),
-                   WeightPawnStructureMidgameInternal);
-  WeightPawnStructureEndgame =
-    compute_weight(get_option_value_int("Pawn Structure (Endgame)"),
-                   WeightPawnStructureEndgameInternal);
-  WeightPassedPawnsMidgame =
-    compute_weight(get_option_value_int("Passed Pawns (Middle Game)"),
-                   WeightPassedPawnsMidgameInternal);
-  WeightPassedPawnsEndgame =
-    compute_weight(get_option_value_int("Passed Pawns (Endgame)"),
-                   WeightPassedPawnsEndgameInternal);
-  WeightKingSafety[sideToMove] =
-    compute_weight(get_option_value_int("Cowardice"), WeightKingSafetyInternal);
-  WeightKingSafety[opposite_color(sideToMove)] =
-    compute_weight(get_option_value_int("Aggressiveness"),
-                   WeightKingSafetyInternal);
-  WeightKingSafety[opposite_color(sideToMove)] =
-    (get_option_value_int("Aggressiveness") * 0x100) / 100;
+void read_weights(Color us) {
+
+  WeightMobilityMidgame      = weight_option("Mobility (Middle Game)", WeightMobilityMidgameInternal);
+  WeightMobilityEndgame      = weight_option("Mobility (Endgame)", WeightMobilityEndgameInternal);
+  WeightPawnStructureMidgame = weight_option("Pawn Structure (Middle Game)", WeightPawnStructureMidgameInternal);
+  WeightPawnStructureEndgame = weight_option("Pawn Structure (Endgame)", WeightPawnStructureEndgameInternal);
+  WeightPassedPawnsMidgame   = weight_option("Passed Pawns (Middle Game)", WeightPassedPawnsMidgameInternal);
+  WeightPassedPawnsEndgame   = weight_option("Passed Pawns (Endgame)", WeightPassedPawnsEndgameInternal);
+
+  Color them = opposite_color(us);
+
+  WeightKingSafety[us]   = weight_option("Cowardice", WeightKingSafetyInternal);
+  WeightKingSafety[them] = weight_option("Aggressiveness", WeightKingOppSafetyInternal);
 
   init_safety();
 }
@@ -688,7 +677,7 @@ namespace {
     // king has lost right to castle
     if (mob > 6 || ei.pi->file_is_half_open(us, f))
         return;
-    
+
     Square ksq = p.king_square(us);
 
     if (    square_file(ksq) >= FILE_E
@@ -1154,6 +1143,13 @@ namespace {
   }
 
 
+  // helper used in read_weights()
+  int weight_option(const std::string& opt, int weight) {
+
+    return compute_weight(get_option_value_int(opt), weight);
+  }
+
+
   // init_safety() initizes the king safety evaluation, based on UCI
   // parameters.  It is called from read_weights().