Skip to content

Commit 95ba7f7

Browse files
protonspringmcostalba
authored andcommitted
Use simple array for Pawns Connected bonus #2061
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.
1 parent 76f1807 commit 95ba7f7

File tree

3 files changed

+8
-27
lines changed

3 files changed

+8
-27
lines changed

src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ int main(int argc, char* argv[]) {
4242
Position::init();
4343
Bitbases::init();
4444
Search::init();
45-
Pawns::init();
4645
Threads.set(Options["Threads"]);
4746
Search::clear(); // After threads are up
4847

src/pawns.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace {
3535
constexpr Score Doubled = S(11, 56);
3636
constexpr Score Isolated = S( 5, 15);
3737

38-
// Connected pawn bonus by opposed, phalanx, #support and rank
39-
Score Connected[2][2][3][RANK_NB];
38+
// Connected pawn bonus
39+
constexpr int Connected[RANK_NB] = { 0, 13, 24, 18, 65, 100, 175, 330 };
4040

4141
// Strength of pawn shelter for our king by [distance from edge][rank].
4242
// RANK_1 = 0 is used for files where we have no pawn, or pawn is behind our king.
@@ -128,8 +128,12 @@ namespace {
128128

129129
// Score this pawn
130130
if (support | phalanx)
131-
score += Connected[opposed][bool(phalanx)][popcount(support)][relative_rank(Us, s)];
132-
131+
{
132+
int r = relative_rank(Us, s);
133+
int v = phalanx ? Connected[r] + Connected[r + 1] : 2 * Connected[r];
134+
v = 17 * popcount(support) + (v >> (opposed + 1));
135+
score += make_score(v, v * (r - 2) / 4);
136+
}
133137
else if (!neighbours)
134138
score -= Isolated, e->weakUnopposed[Us] += !opposed;
135139

@@ -147,27 +151,6 @@ namespace {
147151

148152
namespace Pawns {
149153

150-
/// Pawns::init() initializes some tables needed by evaluation. Instead of using
151-
/// hard-coded tables, when makes sense, we prefer to calculate them with a formula
152-
/// to reduce independent parameters and to allow easier tuning and better insight.
153-
154-
void init() {
155-
156-
static constexpr int Seed[RANK_NB] = { 0, 13, 24, 18, 65, 100, 175, 330 };
157-
158-
for (int opposed = 0; opposed <= 1; ++opposed)
159-
for (int phalanx = 0; phalanx <= 1; ++phalanx)
160-
for (int support = 0; support <= 2; ++support)
161-
for (Rank r = RANK_2; r < RANK_8; ++r)
162-
{
163-
int v = 17 * support;
164-
v += (Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0)) >> opposed;
165-
166-
Connected[opposed][phalanx][support][r] = make_score(v, v * (r - 2) / 4);
167-
}
168-
}
169-
170-
171154
/// Pawns::probe() looks up the current position's pawns configuration in
172155
/// the pawns hash table. It returns a pointer to the Entry if the position
173156
/// is found. Otherwise a new Entry is computed and stored there, so we don't

src/pawns.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ struct Entry {
7676

7777
typedef HashTable<Entry, 16384> Table;
7878

79-
void init();
8079
Entry* probe(const Position& pos);
8180

8281
} // namespace Pawns

0 commit comments

Comments
 (0)