Cleanup read_weights() in evaluate.cpp
authorMarco Costalba <mcostalba@gmail.com>
Wed, 24 Sep 2008 19:50:53 +0000 (20:50 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 24 Sep 2008 19:02:16 +0000 (21:02 +0200)
Exception to 80 colums rule here, but result
seems better.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/evaluate.cpp

index ed04aa54026722219ce4e71444163a287c2ad137..94e807f5d2aa5afc584b14d424ed4583d7dfd15e 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;
@@ -538,32 +539,24 @@ 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;
+int weight_option(const std::string& opt, int weight) {
+
+    return compute_weight(get_option_value_int(opt), weight);
+}
+
+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();
 }