]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Clarify we want Score and Value to be integers
[stockfish] / src / evaluate.cpp
index 3fc6bd5c4c3dcadb961094651aadb03a82b331c6..fe964935c828282490b53a3927cc18c471f263d1 100644 (file)
@@ -168,6 +168,11 @@ namespace {
   // right to castle.
   const Value TrappedRookPenalty = Value(180);
 
+  // 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.
+  const Score TrappedBishopA1H1Penalty = make_score(100, 100);
+
   // The SpaceMask[Color] contains the area of the board which is considered
   // by the space evaluation. In the middle game, each side is given a bonus
   // based on how many squares inside this area are safe and available for
@@ -414,7 +419,7 @@ void quit_eval() {
 
 /// read_weights() reads evaluation weights from the corresponding UCI parameters
 
-void read_weights(Color us) {
+void read_evaluation_uci_options(Color us) {
 
   // King safety is asymmetrical. Our king danger level is weighted by
   // "Cowardice" UCI parameter, instead the opponent one by "Aggressiveness".
@@ -556,6 +561,28 @@ namespace {
             bonus += (Piece == ROOK ? RookOn7thBonus : QueenOn7thBonus);
         }
 
+        // Special extra evaluation for bishops
+        if (Piece == BISHOP && pos.is_chess960())
+        {
+            // An important Chess960 pattern: A cornered bishop blocked by
+            // a friendly pawn diagonally in front of it is a very serious
+            // problem, especially when that pawn is also blocked.
+            if (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1))
+            {
+                SquareDelta d = pawn_push(Us) 
+                   + (square_file(s) == FILE_A ? DELTA_E : DELTA_W);
+                if (pos.piece_on(s + d) == piece_of_color_and_type(Us, PAWN))
+                {
+                    if (!pos.square_is_empty(s + d + pawn_push(Us)))
+                        bonus -= 2*TrappedBishopA1H1Penalty;
+                    else if (pos.piece_on(s + 2*d) == piece_of_color_and_type(Us, PAWN))
+                        bonus -= TrappedBishopA1H1Penalty;
+                    else
+                        bonus -= TrappedBishopA1H1Penalty / 2;
+                }
+            }
+        }
+
         // Special extra evaluation for rooks
         if (Piece == ROOK)
         {