]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Fix Contempt Factor implementation
[stockfish] / src / evaluate.cpp
index 46d9151ff1401add0287b416770108a729abf606..69f0e4c27fa75e4caff8b23db06d911e23819de6 100644 (file)
@@ -138,7 +138,7 @@ namespace {
     {}, {},
     { S(0, 0), S( 7, 39), S( 0,  0), S(24, 49), S(41,100), S(41,100) }, // KNIGHT
     { S(0, 0), S( 7, 39), S(24, 49), S( 0,  0), S(41,100), S(41,100) }, // BISHOP
-    { S(0, 0), S(-1, 29), S(15, 49), S(15, 49), S( 0,  0), S(24, 49) }, // ROOK
+    { S(0, 0), S( 0, 22), S(15, 49), S(15, 49), S( 0,  0), S(24, 49) }, // ROOK
     { S(0, 0), S(15, 39), S(15, 39), S(15, 39), S(15, 39), S( 0,  0) }  // QUEEN
   };
 
@@ -153,12 +153,16 @@ namespace {
   // Bonus for having the side to move (modified by Joona Kiiski)
   const Score Tempo = make_score(24, 11);
 
-  // Rooks and queens on the 7th rank (modified by Joona Kiiski)
-  const Score RookOn7thBonus  = make_score(47, 98);
-  const Score QueenOn7thBonus = make_score(27, 54);
+  // Rooks and queens on the 7th rank
+  const Score RookOn7thBonus  = make_score(3, 20);
+  const Score QueenOn7thBonus = make_score(1,  8);
+
+  // Rooks and queens attacking pawns on the same rank
+  const Score RookOnPawnBonus  = make_score(3, 48);
+  const Score QueenOnPawnBonus = make_score(1, 40);
 
   // Rooks on open files (modified by Joona Kiiski)
-  const Score RookOpenFileBonus = make_score(43, 21);
+  const Score RookOpenFileBonus     = make_score(43, 21);
   const Score RookHalfOpenFileBonus = make_score(19, 10);
 
   // Penalty for rooks trapped inside a friendly king which has lost the
@@ -264,6 +268,8 @@ namespace {
 namespace Eval {
 
   Color RootColor;
+  Value ContemptFactor;
+  Value ValueDraw[2];
 
   /// evaluate() is the main evaluation function. It always computes two
   /// values, an endgame score and a middle game score, and interpolates
@@ -303,6 +309,11 @@ namespace Eval {
         KingDangerTable[1][i] = apply_weight(make_score(t, 0), Weights[KingDangerUs]);
         KingDangerTable[0][i] = apply_weight(make_score(t, 0), Weights[KingDangerThem]);
     }
+
+    if (Options["UCI_AnalyseMode"])
+        ContemptFactor = VALUE_ZERO;
+    else
+        ContemptFactor = Options["Contempt Factor"] * PawnValueMg / 100;
   }
 
 
@@ -595,12 +606,18 @@ Value do_evaluate(const Position& pos, Value& margin) {
             && !(pos.pieces(Them, PAWN) & attack_span_mask(Us, s)))
             score += evaluate_outposts<Piece, Us>(pos, ei, s);
 
-        // Queen or rook on 7th rank
-        if (  (Piece == ROOK || Piece == QUEEN)
-            && relative_rank(Us, s) == RANK_7
-            && relative_rank(Us, pos.king_square(Them)) == RANK_8)
+        if ((Piece == ROOK || Piece == QUEEN) && relative_rank(Us, s) >= RANK_5)
         {
-            score += (Piece == ROOK ? RookOn7thBonus : QueenOn7thBonus);
+            // Major piece on 7th rank
+            if (   relative_rank(Us, s) == RANK_7
+                && relative_rank(Us, pos.king_square(Them)) == RANK_8)
+                score += (Piece == ROOK ? RookOn7thBonus : QueenOn7thBonus);
+
+            // Major piece attacking pawns on the same rank
+            Bitboard pawns = pos.pieces(Them, PAWN) & rank_bb(s);
+            if (pawns)
+                score += (Piece == ROOK ? RookOnPawnBonus
+                                        : QueenOnPawnBonus) * popcount<Max15>(pawns);
         }
 
         // Special extra evaluation for bishops