]> git.sesse.net Git - stockfish/blobdiff - src/pawns.cpp
Remove the now redundant TT prefetch call from Position::do_move.
[stockfish] / src / pawns.cpp
index 64c8e4b6182f2133108e69d1e3bf6bdb87ee1a82..401977bdf52980975576ece727f5fe824140bc4d 100644 (file)
@@ -57,6 +57,11 @@ namespace {
     S( 0, 0), S( 6, 13), S(6,13), S(14,29),
     S(34,68), S(83,166), S(0, 0), S( 0, 0) };
 
+  // Levers bonus by rank
+  const Score Lever[RANK_NB] = {
+    S( 0, 0), S( 0, 0), S(0, 0), S(0, 0),
+    S(20,20), S(40,40), S(0, 0), S(0, 0) };
+
   // Bonus for file distance of the two outermost pawns
   const Score PawnsFileSpan = S(0, 15);
 
@@ -69,10 +74,10 @@ namespace {
 
   // Danger of enemy pawns moving toward our king indexed by
   // [no friendly pawn | pawn unblocked | pawn blocked][rank of enemy pawn]
-  const Value StormDanger[3][RANK_NB] = {
+  const Value StormDanger[][RANK_NB] = {
   { V( 0),  V(64), V(128), V(51), V(26) },
   { V(26),  V(32), V( 96), V(38), V(20) },
-  { V( 0),  V( 0), V( 64), V(25), V(13) } };
+  { V( 0),  V( 0), V(160), V(25), V(13) } };
 
   // Max bonus for king safety. Corresponds to start position with all the pawns
   // in front of the king and no enemy pawn on the horizon.
@@ -92,11 +97,12 @@ namespace {
     Bitboard b, p, doubled;
     Square s;
     File f;
-    bool passed, isolated, opposed, connected, backward, candidate, unsupported;
+    bool passed, isolated, opposed, connected, backward, candidate, unsupported, lever;
     Score value = SCORE_ZERO;
     const Square* pl = pos.list<PAWN>(Us);
+    const Bitboard* pawnAttacksBB = StepAttacksBB[make_piece(Us, PAWN)];
 
-    Bitboard ourPawns = pos.pieces(Us, PAWN);
+    Bitboard ourPawns   = pos.pieces(Us  , PAWN);
     Bitboard theirPawns = pos.pieces(Them, PAWN);
 
     e->passedPawns[Us] = e->candidatePawns[Us] = 0;
@@ -130,6 +136,7 @@ namespace {
         doubled     =   ourPawns   & forward_bb(Us, s);
         opposed     =   theirPawns & forward_bb(Us, s);
         passed      = !(theirPawns & passed_pawn_mask(Us, s));
+        lever       =   theirPawns & pawnAttacksBB[s];
 
         // Test for backward pawn.
         // If the pawn is passed, isolated, or connected it cannot be
@@ -185,6 +192,9 @@ namespace {
         if (connected)
             value += Connected[f][relative_rank(Us, s)];
 
+        if (lever)
+            value += Lever[relative_rank(Us, s)];
+
         if (candidate)
         {
             value += CandidatePassed[relative_rank(Us, s)];
@@ -194,13 +204,12 @@ namespace {
         }
     }
 
+    b = e->semiopenFiles[Us] ^ 0xFF;
+    e->pawnSpan[Us] = b ? int(msb(b) - lsb(b)) : 0;
+
     // In endgame it's better to have pawns on both wings. So give a bonus according
     // to file distance between left and right outermost pawns.
-    if (pos.count<PAWN>(Us) > 1)
-    {
-        b = e->semiopenFiles[Us] ^ 0xFF;
-        value += PawnsFileSpan * int(msb(b) - lsb(b));
-    }
+    value += PawnsFileSpan * e->pawnSpan[Us];
 
     return value;
   }
@@ -213,20 +222,19 @@ namespace Pawns {
 
 void init() {
 
-  const int bonusesByFile[8] = { 1, 3, 3, 4, 4, 3, 3, 1 };
-  int bonus;
+  const int bonusByFile[] = { 1, 3, 3, 4, 4, 3, 3, 1 };
 
   for (Rank r = RANK_1; r < RANK_8; ++r)
       for (File f = FILE_A; f <= FILE_H; ++f)
       {
-          bonus = r * (r-1) * (r-2) + bonusesByFile[f] * (r/2 + 1);
+          int bonus = r * (r - 1) * (r - 2) + bonusByFile[f] * (r / 2 + 1);
           Connected[f][r] = make_score(bonus, bonus);
       }
 }
 
 
-/// probe() takes a position object as input, computes a Entry object, and returns
-/// pointer to it. The result is also stored in a hash table, so we don't have
+/// probe() takes a position as input, computes a Entry object, and returns a
+/// pointer to it. The result is also stored in a hash table, so we don't have
 /// to recompute everything when the same pawn structure occurs again.
 
 Entry* probe(const Position& pos, Table& entries) {
@@ -250,30 +258,30 @@ template<Color Us>
 Value Entry::shelter_storm(const Position& pos, Square ksq) {
 
   const Color Them = (Us == WHITE ? BLACK : WHITE);
-  static const Bitboard MiddleEdges = (FileABB | FileHBB) & (Rank2BB | Rank3BB);
+  const Bitboard Edges = (FileABB | FileHBB) & (Rank2BB | Rank3BB);
 
-  Value safety = MaxSafetyBonus;
   Bitboard b = pos.pieces(PAWN) & (in_front_bb(Us, rank_of(ksq)) | rank_bb(ksq));
   Bitboard ourPawns = b & pos.pieces(Us);
   Bitboard theirPawns = b & pos.pieces(Them);
-  Rank rkUs, rkThem;
+  Value safety = MaxSafetyBonus;
   File kf = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));
 
   for (File f = kf - File(1); f <= kf + File(1); ++f)
   {
       b = ourPawns & file_bb(f);
-      rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
+      Rank rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
 
       b  = theirPawns & file_bb(f);
-      rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
+      Rank rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
 
-      if (   (MiddleEdges & make_square(f, rkThem))
+      if (   (Edges & make_square(f, rkThem))
           && file_of(ksq) == f
           && relative_rank(Us, ksq) == rkThem - 1)
-          safety += Value(200);
+          safety += 200;
       else
-          safety -= ShelterWeakness[rkUs]
-                  + StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem];
+          safety -=  ShelterWeakness[rkUs]
+                   + StormDanger[rkUs   == RANK_1   ? 0 :
+                                 rkThem != rkUs + 1 ? 1 : 2][rkThem];
   }
 
   return safety;