]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Fix a small bug in rook pawn evaluation
[stockfish] / src / evaluate.cpp
index 6a6f98732d8bd87b777aaf881ae86d63d431c7f0..4b98a13c5fc5cfe0f26f0e52798f45db9547882c 100644 (file)
@@ -937,7 +937,7 @@ namespace {
             ebonus += Value(square_distance(theirKingSq, blockSq) * 6 * tr);
 
             // If the pawn is free to advance, increase bonus
-            if (pos.square_is_empty(blockSq))
+            if (tr != 0 && pos.square_is_empty(blockSq))
             {
                 b2 = squares_in_front_of(us, s);
                 b3 = b2 & ei.attacked_by(them);
@@ -1018,8 +1018,8 @@ namespace {
             // value if the other side has a rook or queen.
             if (square_file(s) == FILE_A || square_file(s) == FILE_H)
             {
-                if(   pos.non_pawn_material(them) == KnightValueMidgame // FIXME should be <= ???
-                   && pos.piece_count(them, KNIGHT) == 1)
+                if(   pos.non_pawn_material(them) <= KnightValueMidgame
+                   && pos.piece_count(them, KNIGHT) <= 1)
                     ebonus += ebonus / 4;
                 else if(pos.rooks_and_queens(them))
                     ebonus -= ebonus / 4;
@@ -1067,7 +1067,6 @@ namespace {
 
   void evaluate_trapped_bishop_a7h7(const Position &pos, Square s, Color us,
                                     EvalInfo &ei) {
-
     assert(square_is_ok(s));
     assert(pos.piece_on(s) == bishop_of_color(us));
 
@@ -1098,31 +1097,33 @@ namespace {
     assert(square_is_ok(s));
     assert(pos.piece_on(s) == bishop_of_color(us));
 
-    if(square_file(s) == FILE_A) {
-      b2 = relative_square(us, SQ_B2);
-      b3 = relative_square(us, SQ_B3);
-      c3 = relative_square(us, SQ_C3);
+    if (square_file(s) == FILE_A)
+    {
+        b2 = relative_square(us, SQ_B2);
+        b3 = relative_square(us, SQ_B3);
+        c3 = relative_square(us, SQ_C3);
     }
-    else {
-      b2 = relative_square(us, SQ_G2);
-      b3 = relative_square(us, SQ_G3);
-      c3 = relative_square(us, SQ_F3);
+    else
+    {
+        b2 = relative_square(us, SQ_G2);
+        b3 = relative_square(us, SQ_G3);
+        c3 = relative_square(us, SQ_F3);
     }
 
-    if(pos.piece_on(b2) == pawn) {
-      Value penalty;
+    if (pos.piece_on(b2) == pawn)
+    {
+        Value penalty;
 
-      if(!pos.square_is_empty(b3))
-        penalty = 2*TrappedBishopA1H1Penalty;
-      else if(pos.piece_on(c3) == pawn)
-        penalty = TrappedBishopA1H1Penalty;
-      else
-        penalty = TrappedBishopA1H1Penalty / 2;
+        if (!pos.square_is_empty(b3))
+            penalty = 2*TrappedBishopA1H1Penalty;
+        else if (pos.piece_on(c3) == pawn)
+            penalty = TrappedBishopA1H1Penalty;
+        else
+            penalty = TrappedBishopA1H1Penalty / 2;
 
-      ei.mgValue -= Sign[us] * penalty;
-      ei.egValue -= Sign[us] * penalty;
+        ei.mgValue -= Sign[us] * penalty;
+        ei.egValue -= Sign[us] * penalty;
     }
-
   }
 
 
@@ -1138,31 +1139,32 @@ namespace {
     Color them = opposite_color(us);
 
     // Find the safe squares for our pieces inside the area defined by
-    // SpaceMask[us].  A square is unsafe it is attacked by an enemy
+    // SpaceMask[us]. A square is unsafe it is attacked by an enemy
     // pawn, or if it is undefended and attacked by an enemy piece.
 
-    Bitboard safeSquares =
-      SpaceMask[us] & ~pos.pawns(us) & ~ei.attacked_by(them, PAWN)
-      & ~(~ei.attacked_by(us) & ei.attacked_by(them));
+    Bitboard safeSquares =   SpaceMask[us]
+                          & ~pos.pawns(us)
+                          & ~ei.attacked_by(them, PAWN)
+                          & ~(~ei.attacked_by(us) & ei.attacked_by(them));
 
     // Find all squares which are at most three squares behind some friendly
     // pawn.
     Bitboard behindFriendlyPawns = pos.pawns(us);
-    if(us == WHITE) {
-      behindFriendlyPawns |= (behindFriendlyPawns >> 8);
-      behindFriendlyPawns |= (behindFriendlyPawns >> 16);
+    if (us == WHITE)
+    {
+        behindFriendlyPawns |= (behindFriendlyPawns >> 8);
+        behindFriendlyPawns |= (behindFriendlyPawns >> 16);
     }
-    else {
-      behindFriendlyPawns |= (behindFriendlyPawns << 8);
-      behindFriendlyPawns |= (behindFriendlyPawns << 16);
+    else
+    {
+        behindFriendlyPawns |= (behindFriendlyPawns << 8);
+        behindFriendlyPawns |= (behindFriendlyPawns << 16);
     }
 
-    int space =
-      count_1s_max_15(safeSquares)
-      + count_1s_max_15(behindFriendlyPawns & safeSquares);
+    int space =  count_1s_max_15(safeSquares)
+               + count_1s_max_15(behindFriendlyPawns & safeSquares);
 
-    ei.mgValue += Sign[us] *
-      apply_weight(Value(space * ei.mi->space_weight()), WeightSpace);
+    ei.mgValue += Sign[us] * apply_weight(Value(space * ei.mi->space_weight()), WeightSpace);
   }
 
 
@@ -1203,6 +1205,7 @@ namespace {
   // an UCI-configurable weight with an internal weight.
 
   int compute_weight(int uciWeight, int internalWeight) {
+
     uciWeight = (uciWeight * 0x100) / 100;
     return (uciWeight * internalWeight) / 0x100;
   }
@@ -1255,5 +1258,4 @@ namespace {
             SafetyTable[i] = Value(peak);
     }
   }
-
 }