]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Evaluate: weight_option() is static
[stockfish] / src / evaluate.cpp
index 879eb686c67c1d7bb2512a020fbf6749c7ef63c8..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();
 
 }
@@ -328,19 +330,19 @@ Value evaluate(const Position &pos, EvalInfo &ei, int threadID) {
   // Initialize king attack bitboards and king attack zones for both sides:
   ei.attackedBy[WHITE][KING] = pos.king_attacks(pos.king_square(WHITE));
   ei.attackedBy[BLACK][KING] = pos.king_attacks(pos.king_square(BLACK));
-  ei.attackZone[WHITE] =
+  ei.kingZone[WHITE] =
     ei.attackedBy[BLACK][KING] | (ei.attackedBy[BLACK][KING] >> 8);
-  ei.attackZone[BLACK] =
+  ei.kingZone[BLACK] =
     ei.attackedBy[WHITE][KING] | (ei.attackedBy[WHITE][KING] << 8);
 
   // Initialize pawn attack bitboards for both sides:
   ei.attackedBy[WHITE][PAWN] =
     ((pos.pawns(WHITE) << 9) & ~FileABB) | ((pos.pawns(WHITE) << 7) & ~FileHBB);
-  ei.attackCount[WHITE] +=
+  ei.kingAttackersCount[WHITE] +=
     count_1s_max_15(ei.attackedBy[WHITE][PAWN] & ei.attackedBy[BLACK][KING])/2;
   ei.attackedBy[BLACK][PAWN] =
     ((pos.pawns(BLACK) >> 7) & ~FileABB) | ((pos.pawns(BLACK) >> 9) & ~FileHBB);
-  ei.attackCount[BLACK] +=
+  ei.kingAttackersCount[BLACK] +=
     count_1s_max_15(ei.attackedBy[BLACK][PAWN] & ei.attackedBy[WHITE][KING])/2;
 
   // Evaluate pieces:
@@ -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();
 }
@@ -580,13 +569,13 @@ namespace {
     Color them = opposite_color(us);
 
     // King attack
-    if (b & ei.attackZone[us])
+    if (b & ei.kingZone[us])
     {
-      ei.attackCount[us]++;
-      ei.attackWeight[us] += AttackWeight;
+      ei.kingAttackersCount[us]++;
+      ei.kingAttackersWeight[us] += AttackWeight;
       Bitboard bb = (b & ei.attackedBy[them][KING]);
       if (bb)
-          ei.attacked[us] += count_1s_max_15(bb);
+          ei.kingZoneAttacksCount[us] += count_1s_max_15(bb);
     }
 
     // Mobility
@@ -688,8 +677,9 @@ 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
         &&  square_file(s) > square_file(ksq)
         && (relative_rank(us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
@@ -754,9 +744,9 @@ namespace {
     // King safety.  This is quite complicated, and is almost certainly far
     // from optimally tuned.
     Color them = opposite_color(us);
-    if(p.queen_count(them) >= 1 && ei.attackCount[them] >= 2
+    if(p.queen_count(them) >= 1 && ei.kingAttackersCount[them] >= 2
        && p.non_pawn_material(them) >= QueenValueMidgame + RookValueMidgame
-       && ei.attacked[them]) {
+       && ei.kingZoneAttacksCount[them]) {
 
       // Is it the attackers turn to move?
       bool sente = (them == p.side_to_move());
@@ -776,8 +766,8 @@ namespace {
       // undefended squares around the king, the square of the king, and the
       // quality of the pawn shelter.
       int attackUnits =
-        Min((ei.attackCount[them] * ei.attackWeight[them]) / 2, 25)
-        + (ei.attacked[them] + count_1s_max_15(undefended)) * 3
+        Min((ei.kingAttackersCount[them] * ei.kingAttackersWeight[them]) / 2, 25)
+        + (ei.kingZoneAttacksCount[them] + count_1s_max_15(undefended)) * 3
         + InitKingDanger[relative_square(us, s)] - shelter / 32;
 
       // Analyse safe queen contact checks:
@@ -1153,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().