Further simplify previous patch
authorMarco Costalba <mcostalba@gmail.com>
Sat, 4 May 2013 09:42:34 +0000 (11:42 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 4 May 2013 10:15:31 +0000 (12:15 +0200)
No functional change.

src/evaluate.cpp
src/pawns.h

index 1a1334fe1e4e3f8858ba70f245c23a1b875f5851..108f6c8a39e68bf74370b437a1a52b3d58182ff9 100644 (file)
@@ -648,25 +648,13 @@ Value do_evaluate(const Position& pos, Value& margin) {
                 continue;
 
             ksq = pos.king_square(Us);
+            bool left = file_of(ksq) < FILE_E;
 
-            if (    file_of(ksq) >= FILE_E
-                &&  file_of(s) > file_of(ksq)
+            if (   ((left && file_of(s) < file_of(ksq)) || (!left && file_of(s) > file_of(ksq)))
                 && (relative_rank(Us, ksq) == RANK_1 || rank_of(ksq) == rank_of(s))
-                && !ei.pi->has_open_file_to_right(Us, file_of(ksq)))
-            {
-                // Is there a half-open file between the king and the edge of the board?
-                    score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
-                                                           : (TrappedRookPenalty - mob * 16), 0);
-            }
-            else if (    file_of(ksq) <= FILE_D
-                     &&  file_of(s) < file_of(ksq)
-                     && (relative_rank(Us, ksq) == RANK_1 || rank_of(ksq) == rank_of(s))
-                     && !ei.pi->has_open_file_to_left(Us, file_of(ksq)))
-            {
-                // Is there a half-open file between the king and the edge of the board?
-                    score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
-                                                           : (TrappedRookPenalty - mob * 16), 0);
-            }
+                && (!ei.pi->has_open_file_on_side(Us, file_of(ksq), left)))
+                score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
+                                                       : (TrappedRookPenalty - mob * 16), 0);
         }
     }
 
index 293869bc777c6ed39c4d42d7f78858c18345de44..39fc9e3f16aa94c0acdebe3191448ca32178c0b4 100644 (file)
@@ -38,9 +38,10 @@ struct Entry {
   Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
   Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
   int file_is_half_open(Color c, File f) const { return halfOpenFiles[c] & (1 << int(f)); }
-  int has_open_file_to_left(Color c, File f) const { return halfOpenFiles[c] & ((1 << int(f)) - 1); }
-  int has_open_file_to_right(Color c, File f) const { return halfOpenFiles[c] & ~((1 << int(f+1)) - 1); }
   int pawns_on_same_color_squares(Color c, Square s) const { return pawnsOnSquares[c][!!(BlackSquares & s)]; }
+  int has_open_file_on_side(Color c, File f, bool left) const {
+    return halfOpenFiles[c] & (left ? ((1 << int(f)) - 1) : ~((1 << int(f+1)) - 1));
+  }
 
   template<Color Us>
   Score king_safety(const Position& pos, Square ksq)  {