]> git.sesse.net Git - stockfish/commitdiff
Use simple array for Pawns Connected bonus #2061
authorprotonspring <mike@whiteley.org>
Mon, 25 Mar 2019 19:04:14 +0000 (13:04 -0600)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 31 Mar 2019 09:28:48 +0000 (11:28 +0200)
Simplification which removes the pawns connected array.
Instead of storing the values in an array, the values are
calculated real-time. This is about 1.6% faster on my machines.

Performance:
master ave nps: 159,248,672
patch ave nps: 161,905,592

STC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 20363 W: 4579 L: 4455 D: 11329
http://tests.stockfishchess.org/tests/view/5c9925ba0ebc5925cfff79a6

Non functional change.

src/main.cpp
src/pawns.cpp
src/pawns.h

index a093b5bf0a234d644f1f15a34c0329c0008322a4..fc78b38c1cdedb630cfbae50353194b51822db80 100644 (file)
@@ -42,7 +42,6 @@ int main(int argc, char* argv[]) {
   Position::init();
   Bitbases::init();
   Search::init();
-  Pawns::init();
   Threads.set(Options["Threads"]);
   Search::clear(); // After threads are up
 
index c9c9e5992dbaf83cca00876317e3c3d9456647a1..7edaa6e1bb786bfa42ff341352f3d153b280e417 100644 (file)
@@ -35,8 +35,8 @@ namespace {
   constexpr Score Doubled  = S(11, 56);
   constexpr Score Isolated = S( 5, 15);
 
-  // Connected pawn bonus by opposed, phalanx, #support and rank
-  Score Connected[2][2][3][RANK_NB];
+  // Connected pawn bonus
+  constexpr int Connected[RANK_NB] = { 0, 13, 24, 18, 65, 100, 175, 330 };
 
   // Strength of pawn shelter for our king by [distance from edge][rank].
   // RANK_1 = 0 is used for files where we have no pawn, or pawn is behind our king.
@@ -128,8 +128,12 @@ namespace {
 
         // Score this pawn
         if (support | phalanx)
-            score += Connected[opposed][bool(phalanx)][popcount(support)][relative_rank(Us, s)];
-
+        {
+            int r = relative_rank(Us, s);
+            int v = phalanx ? Connected[r] + Connected[r + 1] : 2 * Connected[r];
+            v = 17 * popcount(support) + (v >> (opposed + 1));
+            score += make_score(v, v * (r - 2) / 4);
+        }
         else if (!neighbours)
             score -= Isolated, e->weakUnopposed[Us] += !opposed;
 
@@ -147,27 +151,6 @@ namespace {
 
 namespace Pawns {
 
-/// Pawns::init() initializes some tables needed by evaluation. Instead of using
-/// hard-coded tables, when makes sense, we prefer to calculate them with a formula
-/// to reduce independent parameters and to allow easier tuning and better insight.
-
-void init() {
-
-  static constexpr int Seed[RANK_NB] = { 0, 13, 24, 18, 65, 100, 175, 330 };
-
-  for (int opposed = 0; opposed <= 1; ++opposed)
-      for (int phalanx = 0; phalanx <= 1; ++phalanx)
-          for (int support = 0; support <= 2; ++support)
-              for (Rank r = RANK_2; r < RANK_8; ++r)
-  {
-      int v = 17 * support;
-      v += (Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0)) >> opposed;
-
-      Connected[opposed][phalanx][support][r] = make_score(v, v * (r - 2) / 4);
-  }
-}
-
-
 /// Pawns::probe() looks up the current position's pawns configuration in
 /// the pawns hash table. It returns a pointer to the Entry if the position
 /// is found. Otherwise a new Entry is computed and stored there, so we don't
index 0426ec3683d68de129f9fcea19357720fcb6d522..71d18ee899e1c1507a59800d341594d23fd5de50 100644 (file)
@@ -76,7 +76,6 @@ struct Entry {
 
 typedef HashTable<Entry, 16384> Table;
 
-void init();
 Entry* probe(const Position& pos);
 
 } // namespace Pawns