]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Revert "Retire eval margin and gains"
[stockfish] / src / evaluate.cpp
index 71120fde8fb20ca99ff4e9d691ad7d31889258b7..594809af9d74274c7b6d3e2a2076836a2b50ab5e 100644 (file)
@@ -83,6 +83,8 @@ namespace {
     // king is on g8 and there's a white knight on g5, this knight adds
     // 2 to kingAdjacentZoneAttacksCount[BLACK].
     int kingAdjacentZoneAttacksCount[COLOR_NB];
+
+    Bitboard pinnedPieces[COLOR_NB];
   };
 
   // Evaluation grain size, must be a power of 2
@@ -172,6 +174,7 @@ namespace {
   const Score RookOpenFile     = make_score(43, 21);
   const Score RookSemiopenFile = make_score(19, 10);
   const Score BishopPawns      = make_score( 8, 12);
+  const Score KnightPawns      = make_score( 8,  4);
   const Score MinorBehindPawn  = make_score(16,  0);
   const Score UndefendedMinor  = make_score(25, 10);
   const Score TrappedRook      = make_score(90,  0);
@@ -200,12 +203,12 @@ namespace {
   const int KingAttackWeights[] = { 0, 0, 2, 2, 3, 5 };
 
   // Bonuses for enemy's safe checks
-  const int QueenContactCheck = 12;
-  const int RookContactCheck  = 8;
-  const int QueenCheck        = 6;
-  const int RookCheck         = 4;
-  const int BishopCheck       = 1;
-  const int KnightCheck       = 2;
+  const int QueenContactCheck = 24;
+  const int RookContactCheck  = 16;
+  const int QueenCheck        = 12;
+  const int RookCheck         = 8;
+  const int BishopCheck       = 2;
+  const int KnightCheck       = 3;
 
   // KingExposed[Square] contains penalties based on the position of the
   // defending king, indexed by king's square (from white's point of view).
@@ -433,6 +436,8 @@ Value do_evaluate(const Position& pos, Value& margin) {
     const Color  Them = (Us == WHITE ? BLACK : WHITE);
     const Square Down = (Us == WHITE ? DELTA_S : DELTA_N);
 
+    ei.pinnedPieces[Us] = pos.pinned_pieces(Us);
+
     Bitboard b = ei.attackedBy[Them][KING] = pos.attacks_from<KING>(pos.king_square(Them));
     ei.attackedBy[Us][PAWN] = ei.pi->pawn_attacks(Us);
 
@@ -497,6 +502,9 @@ Value do_evaluate(const Position& pos, Value& margin) {
           : Piece ==   ROOK ? attacks_bb<  ROOK>(s, pos.pieces() ^ pos.pieces(Us, ROOK, QUEEN))
                             : pos.attacks_from<Piece>(s);
 
+        if (ei.pinnedPieces[Us] & s)
+            b &= PseudoAttacks[QUEEN][pos.king_square(Us)];
+
         ei.attackedBy[Us][Piece] |= b;
 
         if (b & ei.kingRing[Them])
@@ -529,6 +537,10 @@ Value do_evaluate(const Position& pos, Value& margin) {
         if (Piece == BISHOP)
             score -= BishopPawns * ei.pi->pawns_on_same_color_squares(Us, s);
 
+        // Penalty for knight when there are few enemy pawns
+        if (Piece == KNIGHT)
+            score -= KnightPawns * std::max(5 - pos.count<PAWN>(Them), 0);
+
         if (Piece == BISHOP || Piece == KNIGHT)
         {
             // Bishop and knight outposts squares
@@ -878,9 +890,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
                 ebonus -= ebonus / 4;
         }
 
-        // Increase the bonus if we have more non-pawn pieces
-        if (pos.count<ALL_PIECES>(  Us) - pos.count<PAWN>(  Us) >
-            pos.count<ALL_PIECES>(Them) - pos.count<PAWN>(Them))
+        if (pos.count<PAWN>(Us) < pos.count<PAWN>(Them))
             ebonus += ebonus / 4;
 
         score += make_score(mbonus, ebonus);