]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Increase QueenContactCheckBonus
[stockfish] / src / evaluate.cpp
index 9ff554cde1f76fa1e400bc4b0b3974190e97c59c..1c215dc0d4a19b586189676331751e7e43845c9b 100644 (file)
@@ -45,6 +45,11 @@ namespace {
     // Pointer to pawn hash table entry
     PawnInfo* pi;
 
+    // updateKingTables[color] is set to true if we have enough material
+    // to trigger the opponent's king safety calculation. When is false we
+    // skip the time consuming update of the king attackers tables.
+    bool updateKingTables[2];
+
     // attackedBy[color][piece type] is a bitboard representing all squares
     // attacked by a given color and piece type, attackedBy[color][0] contains
     // all squares attacked by the given color.
@@ -194,9 +199,9 @@ namespace {
   const int KingAttackWeights[] = { 0, 0, 2, 2, 3, 5 };
 
   // Bonuses for enemy's safe checks
-  const int QueenContactCheckBonus = 3;
-  const int QueenCheckBonus        = 2;
-  const int RookCheckBonus         = 1;
+  const int QueenContactCheckBonus = 6;
+  const int QueenCheckBonus        = 3;
+  const int RookCheckBonus         = 2;
   const int BishopCheckBonus       = 1;
   const int KnightCheckBonus       = 1;
 
@@ -336,26 +341,11 @@ Value do_evaluate(const Position& pos, Value margins[]) {
 
   Phase phase = mi->game_phase();
 
-  // Middle-game specific evaluation terms
-  if (phase > PHASE_ENDGAME)
+  // Evaluate space for both sides, only in middle-game.
+  if (phase > PHASE_ENDGAME && mi->space_weight() > 0)
   {
-      // Evaluate pawn storms in positions with opposite castling
-      if (   square_file(pos.king_square(WHITE)) >= FILE_E
-          && square_file(pos.king_square(BLACK)) <= FILE_D)
-
-          bonus += make_score(ei.pi->queenside_storm_value(WHITE) - ei.pi->kingside_storm_value(BLACK), 0);
-
-      else if (   square_file(pos.king_square(WHITE)) <= FILE_D
-               && square_file(pos.king_square(BLACK)) >= FILE_E)
-
-          bonus += make_score(ei.pi->kingside_storm_value(WHITE) - ei.pi->queenside_storm_value(BLACK), 0);
-
-      // Evaluate space for both sides
-      if (mi->space_weight() > 0)
-      {
-          int s = evaluate_space<WHITE, HasPopCnt>(pos, ei) - evaluate_space<BLACK, HasPopCnt>(pos, ei);
-          bonus += apply_weight(make_score(s * mi->space_weight(), 0), Weights[Space]);
-      }
+      int s = evaluate_space<WHITE, HasPopCnt>(pos, ei) - evaluate_space<BLACK, HasPopCnt>(pos, ei);
+      bonus += apply_weight(make_score(s * mi->space_weight(), 0), Weights[Space]);
   }
 
   // If we don't already have an unusual scale factor, check for opposite
@@ -466,9 +456,13 @@ namespace {
     Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from<KING>(pos.king_square(Them));
     ei.kingZone[Us] = (b | (Us == WHITE ? b >> 8 : b << 8));
     ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us);
-    b &= ei.attackedBy[Us][PAWN];
-    ei.kingAttackersCount[Us] = b ? count_1s_max_15<HasPopCnt>(b) / 2 : EmptyBoardBB;
-    ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = EmptyBoardBB;
+    ei.updateKingTables[Us] = pos.piece_count(Us, QUEEN) && pos.non_pawn_material(Us) >= QueenValueMidgame + RookValueMidgame;
+    if (ei.updateKingTables[Us])
+    {
+        b &= ei.attackedBy[Us][PAWN];
+        ei.kingAttackersCount[Us] = b ? count_1s_max_15<HasPopCnt>(b) / 2 : EmptyBoardBB;
+        ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = EmptyBoardBB;
+    }
   }
 
 
@@ -530,7 +524,7 @@ namespace {
         ei.attackedBy[Us][Piece] |= b;
 
         // King attacks
-        if (b & ei.kingZone[Us])
+        if (ei.updateKingTables[Us] && (b & ei.kingZone[Us]))
         {
             ei.kingAttackersCount[Us]++;
             ei.kingAttackersWeight[Us] += KingAttackWeights[Piece];
@@ -677,13 +671,12 @@ namespace {
     const Square ksq = pos.king_square(Us);
 
     // King shelter
-    Score bonus = ei.pi->king_shelter(pos, Us, ksq);
+    Score bonus = ei.pi->king_shelter<Us>(pos, ksq);
 
     // King safety. This is quite complicated, and is almost certainly far
     // from optimally tuned.
-    if (   ei.kingAttackersCount[Them]  >= 2
-        && pos.non_pawn_material(Them)  >= QueenValueMidgame + RookValueMidgame
-        && pos.piece_count(Them, QUEEN) >= 1
+    if (   ei.updateKingTables[Them]
+        && ei.kingAttackersCount[Them] >= 2
         && ei.kingAdjacentZoneAttacksCount[Them])
     {
         // Find the attacked squares around the king which has no defenders
@@ -701,7 +694,7 @@ namespace {
         attackUnits =  Min(25, (ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) / 2)
                      + 3 * (ei.kingAdjacentZoneAttacksCount[Them] + count_1s_max_15<HasPopCnt>(undefended))
                      + InitKingDanger[relative_square(Us, ksq)]
-                     - mg_value(ei.pi->king_shelter(pos, Us, ksq)) / 32;
+                     - mg_value(ei.pi->king_shelter<Us>(pos, ksq)) / 32;
 
         // Analyse enemy's safe queen contact checks. First find undefended
         // squares around the king attacked by enemy queen...