Fix bug in evaluate_passed_pawns()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 30 Apr 2011 12:02:56 +0000 (13:02 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 3 May 2011 11:10:53 +0000 (12:10 +0100)
If blockSq is already on rank 8, blockSq + pawn_push(Us) is on rank 9,
outside of board. It does not make sense to measure king distance to
a field outside the board.

Bug spotted by Fruity:
http://open-chess.org/viewtopic.php?f=5&t=1156&start=10

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/evaluate.cpp

index 71335c1bf3e3a9c52492aca1d7db949a5378ec6e..77821a3ad3dde342e5981638dab3862cf6680110 100644 (file)
@@ -812,9 +812,12 @@ namespace {
             Square blockSq = s + pawn_push(Us);
 
             // Adjust bonus based on kings proximity
-            ebonus -= Value(square_distance(pos.king_square(Us), blockSq) * 3 * rr);
-            ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr);
             ebonus += Value(square_distance(pos.king_square(Them), blockSq) * 6 * rr);
+            ebonus -= Value(square_distance(pos.king_square(Us), blockSq) * 3 * rr);
+
+            // If blockSq is not the queening square then consider also a second push
+            if (square_rank(blockSq) != (Us == WHITE ? RANK_8 : RANK_1))
+                ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr);
 
             // If the pawn is free to advance, increase bonus
             if (pos.square_is_empty(blockSq))