Skip to content

Commit d706ae6

Browse files
FauziAkramvondele
authored andcommitted
New Imbalance Tables Tweak
Imbalance tables tweaked to contain MiddleGame and Endgame values, instead of a single value. The idea started from Fisherman, which requested my help to tune the values back in June/July, so I tuned the values back then, and we were able to accomplish good results, but not enough to pass both STC and LTC tests. So after the recent changes, I decided to give it another shot, and I am glad that it was a successful attempt. A special thanks goes also to mstembera, which notified me a simple way to let the patch perform a little better. Passed STC: LLR: 2.94 (-2.94,2.94) {-0.25,1.25} Total: 115976 W: 23124 L: 22695 D: 70157 Ptnml(0-2): 2074, 13652, 26285, 13725, 2252 https://tests.stockfishchess.org/tests/view/5fc92d2d42a050a89f02ccc8 Passed LTC: LLR: 2.94 (-2.94,2.94) {0.25,1.25} Total: 156304 W: 20617 L: 20024 D: 115663 Ptnml(0-2): 1138, 14647, 46084, 15050, 1233 https://tests.stockfishchess.org/tests/view/5fc9fee142a050a89f02cd3e closes official-stockfish/Stockfish#3255 Bench: 4278746
1 parent c7f0a76 commit d706ae6

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

src/evaluate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ namespace {
594594
int kingFlankDefense = popcount(b3);
595595

596596
kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them] // (~10 Elo)
597-
+ 185 * popcount(kingRing[Us] & weak) // (~15 Elo)
597+
+ 183 * popcount(kingRing[Us] & weak) // (~15 Elo)
598598
+ 148 * popcount(unsafeChecks) // (~4 Elo)
599599
+ 98 * popcount(pos.blockers_for_king(Us)) // (~2 Elo)
600600
+ 69 * kingAttacksCount[Them] // (~0.5 Elo)

src/material.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,34 @@
2525
using namespace std;
2626

2727
namespace {
28+
#define S(mg, eg) make_score(mg, eg)
2829

2930
// Polynomial material imbalance parameters
3031

31-
constexpr int QuadraticOurs[][PIECE_TYPE_NB] = {
32+
constexpr Score QuadraticOurs[][PIECE_TYPE_NB] = {
3233
// OUR PIECES
3334
// pair pawn knight bishop rook queen
34-
{1438 }, // Bishop pair
35-
{ 40, 38 }, // Pawn
36-
{ 32, 255, -62 }, // Knight OUR PIECES
37-
{ 0, 104, 4, 0 }, // Bishop
38-
{ -26, -2, 47, 105, -208 }, // Rook
39-
{-189, 24, 117, 133, -134, -6 } // Queen
35+
{S(1419, 1455) }, // Bishop pair
36+
{S( 101, 28), S( 37, 39) }, // Pawn
37+
{S( 57, 64), S(249, 187), S(-49, -62) }, // Knight OUR PIECES
38+
{S( 0, 0), S(118, 137), S( 10, 27), S( 0, 0) }, // Bishop
39+
{S( -63, -68), S( -5, 3), S(100, 81), S(132, 118), S(-246, -244) }, // Rook
40+
{S(-210, -211), S( 37, 14), S(147, 141), S(161, 105), S(-158, -174), S(-9,-31) } // Queen
4041
};
4142

42-
constexpr int QuadraticTheirs[][PIECE_TYPE_NB] = {
43+
constexpr Score QuadraticTheirs[][PIECE_TYPE_NB] = {
4344
// THEIR PIECES
4445
// pair pawn knight bishop rook queen
45-
{ }, // Bishop pair
46-
{ 36, }, // Pawn
47-
{ 9, 63, }, // Knight OUR PIECES
48-
{ 59, 65, 42, }, // Bishop
49-
{ 46, 39, 24, -24, }, // Rook
50-
{ 97, 100, -42, 137, 268, } // Queen
46+
{ }, // Bishop pair
47+
{S( 33, 30) }, // Pawn
48+
{S( 46, 18), S(106, 84) }, // Knight OUR PIECES
49+
{S( 75, 35), S( 59, 44), S( 60, 15) }, // Bishop
50+
{S( 26, 35), S( 6, 22), S( 38, 39), S(-12, -2) }, // Rook
51+
{S( 97, 93), S(100, 163), S(-58, -91), S(112, 192), S(276, 225) } // Queen
5152
};
5253

54+
#undef S
55+
5356
// Endgame evaluation and scaling functions are accessed directly and not through
5457
// the function maps because they correspond to more than one material hash key.
5558
Endgame<KXK> EvaluateKXK[] = { Endgame<KXK>(WHITE), Endgame<KXK>(BLACK) };
@@ -82,11 +85,11 @@ namespace {
8285
/// piece type for both colors.
8386

8487
template<Color Us>
85-
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
88+
Score imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
8689

8790
constexpr Color Them = ~Us;
8891

89-
int bonus = 0;
92+
Score bonus = SCORE_ZERO;
9093

9194
// Second-degree polynomial material imbalance, by Tord Romstad
9295
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)
@@ -213,7 +216,7 @@ Entry* probe(const Position& pos) {
213216
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
214217
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
215218

216-
e->value = int16_t((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
219+
e->score = (imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16;
217220
return e;
218221
}
219222

src/material.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace Material {
3737

3838
struct Entry {
3939

40-
Score imbalance() const { return make_score(value, value); }
41-
Phase game_phase() const { return gamePhase; }
40+
Score imbalance() const { return score; }
41+
Phase game_phase() const { return (Phase)gamePhase; }
4242
bool specialized_eval_exists() const { return evaluationFunction != nullptr; }
4343
Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
4444

@@ -57,9 +57,9 @@ struct Entry {
5757
const EndgameBase<Value>* evaluationFunction;
5858
const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
5959
// side (e.g. KPKP, KBPsK)
60-
int16_t value;
60+
Score score;
61+
int16_t gamePhase;
6162
uint8_t factor[COLOR_NB];
62-
Phase gamePhase;
6363
};
6464

6565
typedef HashTable<Entry, 8192> Table;

src/pawns.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace {
6666
{ V(-17), V( -13), V( 100), V( 4), V( 9), V(-16), V(-31) }
6767
};
6868

69+
6970
// KingOnFile[semi-open Us][semi-open Them] contains bonuses/penalties
7071
// for king when the king is on a semi-open or open file.
7172
constexpr Score KingOnFile[2][2] = {{ S(-19,12), S(-6, 7) },

0 commit comments

Comments
 (0)