]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Skip a couple of popcount in previous patch
[stockfish] / src / evaluate.cpp
index 85fac61e6bac504dd9cc6f5b59939ce88398a5cb..aeaae07f10720114be0986e93b91d37f6ee41200 100644 (file)
@@ -75,8 +75,8 @@ namespace {
   const int GrainSize = 8;
 
   // Evaluation weights, initialized from UCI options
-  enum { Mobility, PassedPawns, Space };
-  Score Weights[3];
+  enum { Mobility, PassedPawns, Space, KingDangerUs, KingDangerThem };
+  Score Weights[6];
 
   typedef Value V;
   #define S(mg, eg) make_score(mg, eg)
@@ -88,7 +88,7 @@ namespace {
   //
   // Values modified by Joona Kiiski
   const Score WeightsInternal[] = {
-      S(252, 344), S(216, 266), S(46, 0)
+      S(289, 344), S(221, 273), S(46, 0), S(271, 0), S(307, 0)
   };
 
   // MobilityBonus[PieceType][attacked] contains mobility bonuses for middle and
@@ -171,6 +171,9 @@ namespace {
   // right to castle.
   const Value TrappedRookPenalty = Value(180);
 
+  // Penalty for bishop with pawns on the same coloured squares
+  const Score BishopPawnsPenalty = make_score(8, 12);
+
   // Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by
   // a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only
   // happen in Chess960 games.
@@ -197,10 +200,6 @@ namespace {
   // the strength of the enemy attack are added up into an integer, which
   // is used as an index to KingDangerTable[].
   //
-  // King safety evaluation is asymmetrical and different for us (root color)
-  // and for our opponent. These values are used to init KingDangerTable.
-  const int KingDangerWeights[] = { 259, 247 };
-
   // KingAttackWeights[PieceType] contains king attack weights by piece type
   const int KingAttackWeights[] = { 0, 0, 2, 2, 3, 5 };
 
@@ -287,16 +286,11 @@ namespace Eval {
 
   void init() {
 
-    Weights[Mobility]    = weight_option("Mobility (Middle Game)", "Mobility (Endgame)", WeightsInternal[Mobility]);
-    Weights[PassedPawns] = weight_option("Passed Pawns (Middle Game)", "Passed Pawns (Endgame)", WeightsInternal[PassedPawns]);
-    Weights[Space]       = weight_option("Space", "Space", WeightsInternal[Space]);
-
-    int KingDanger[] = { KingDangerWeights[0], KingDangerWeights[1] };
-
-    // If running in analysis mode, make sure we use symmetrical king safety.
-    // We do so by replacing both KingDanger weights by their average.
-    if (Options["UCI_AnalyseMode"])
-        KingDanger[0] = KingDanger[1] = (KingDanger[0] + KingDanger[1]) / 2;
+    Weights[Mobility]       = weight_option("Mobility (Middle Game)", "Mobility (Endgame)", WeightsInternal[Mobility]);
+    Weights[PassedPawns]    = weight_option("Passed Pawns (Middle Game)", "Passed Pawns (Endgame)", WeightsInternal[PassedPawns]);
+    Weights[Space]          = weight_option("Space", "Space", WeightsInternal[Space]);
+    Weights[KingDangerUs]   = weight_option("Cowardice", "Cowardice", WeightsInternal[KingDangerUs]);
+    Weights[KingDangerThem] = weight_option("Aggressiveness", "Aggressiveness", WeightsInternal[KingDangerThem]);
 
     const int MaxSlope = 30;
     const int Peak = 1280;
@@ -305,8 +299,8 @@ namespace Eval {
     {
         t = std::min(Peak, std::min(int(0.4 * i * i), t + MaxSlope));
 
-        KingDangerTable[0][i] = apply_weight(make_score(t, 0), make_score(KingDanger[0], 0));
-        KingDangerTable[1][i] = apply_weight(make_score(t, 0), make_score(KingDanger[1], 0));
+        KingDangerTable[1][i] = apply_weight(make_score(t, 0), Weights[KingDangerUs]);
+        KingDangerTable[0][i] = apply_weight(make_score(t, 0), Weights[KingDangerThem]);
     }
   }
 
@@ -591,6 +585,10 @@ Value do_evaluate(const Position& pos, Value& margin) {
                  && !more_than_one(BetweenBB[s][pos.king_square(Them)] & pos.pieces()))
                  score += BishopPinBonus;
 
+        // Penalty for bishop with same coloured pawns
+        if (Piece == BISHOP)
+            score -= BishopPawnsPenalty * ei.pi->pawns_on_same_color_squares(Us, s);
+
         // Bishop and knight outposts squares
         if (    (Piece == BISHOP || Piece == KNIGHT)
             && !(pos.pieces(Them, PAWN) & attack_span_mask(Us, s)))