1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

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 https://github.com/official-stockfish/Stockfish/pull/3255

Bench: 4278746
This commit is contained in:
FauziAkram 2020-12-07 19:28:47 +02:00 committed by Joost VandeVondele
parent c7f0a768cb
commit d706ae62d7
4 changed files with 26 additions and 22 deletions

View file

@ -594,7 +594,7 @@ namespace {
int kingFlankDefense = popcount(b3); int kingFlankDefense = popcount(b3);
kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them] // (~10 Elo) kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them] // (~10 Elo)
+ 185 * popcount(kingRing[Us] & weak) // (~15 Elo) + 183 * popcount(kingRing[Us] & weak) // (~15 Elo)
+ 148 * popcount(unsafeChecks) // (~4 Elo) + 148 * popcount(unsafeChecks) // (~4 Elo)
+ 98 * popcount(pos.blockers_for_king(Us)) // (~2 Elo) + 98 * popcount(pos.blockers_for_king(Us)) // (~2 Elo)
+ 69 * kingAttacksCount[Them] // (~0.5 Elo) + 69 * kingAttacksCount[Them] // (~0.5 Elo)

View file

@ -25,31 +25,34 @@
using namespace std; using namespace std;
namespace { namespace {
#define S(mg, eg) make_score(mg, eg)
// Polynomial material imbalance parameters // Polynomial material imbalance parameters
constexpr int QuadraticOurs[][PIECE_TYPE_NB] = { constexpr Score QuadraticOurs[][PIECE_TYPE_NB] = {
// OUR PIECES // OUR PIECES
// pair pawn knight bishop rook queen // pair pawn knight bishop rook queen
{1438 }, // Bishop pair {S(1419, 1455) }, // Bishop pair
{ 40, 38 }, // Pawn {S( 101, 28), S( 37, 39) }, // Pawn
{ 32, 255, -62 }, // Knight OUR PIECES {S( 57, 64), S(249, 187), S(-49, -62) }, // Knight OUR PIECES
{ 0, 104, 4, 0 }, // Bishop {S( 0, 0), S(118, 137), S( 10, 27), S( 0, 0) }, // Bishop
{ -26, -2, 47, 105, -208 }, // Rook {S( -63, -68), S( -5, 3), S(100, 81), S(132, 118), S(-246, -244) }, // Rook
{-189, 24, 117, 133, -134, -6 } // Queen {S(-210, -211), S( 37, 14), S(147, 141), S(161, 105), S(-158, -174), S(-9,-31) } // Queen
}; };
constexpr int QuadraticTheirs[][PIECE_TYPE_NB] = { constexpr Score QuadraticTheirs[][PIECE_TYPE_NB] = {
// THEIR PIECES // THEIR PIECES
// pair pawn knight bishop rook queen // pair pawn knight bishop rook queen
{ }, // Bishop pair { }, // Bishop pair
{ 36, }, // Pawn {S( 33, 30) }, // Pawn
{ 9, 63, }, // Knight OUR PIECES {S( 46, 18), S(106, 84) }, // Knight OUR PIECES
{ 59, 65, 42, }, // Bishop {S( 75, 35), S( 59, 44), S( 60, 15) }, // Bishop
{ 46, 39, 24, -24, }, // Rook {S( 26, 35), S( 6, 22), S( 38, 39), S(-12, -2) }, // Rook
{ 97, 100, -42, 137, 268, } // Queen {S( 97, 93), S(100, 163), S(-58, -91), S(112, 192), S(276, 225) } // Queen
}; };
#undef S
// Endgame evaluation and scaling functions are accessed directly and not through // Endgame evaluation and scaling functions are accessed directly and not through
// the function maps because they correspond to more than one material hash key. // the function maps because they correspond to more than one material hash key.
Endgame<KXK> EvaluateKXK[] = { Endgame<KXK>(WHITE), Endgame<KXK>(BLACK) }; Endgame<KXK> EvaluateKXK[] = { Endgame<KXK>(WHITE), Endgame<KXK>(BLACK) };
@ -82,11 +85,11 @@ namespace {
/// piece type for both colors. /// piece type for both colors.
template<Color Us> template<Color Us>
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) { Score imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
constexpr Color Them = ~Us; constexpr Color Them = ~Us;
int bonus = 0; Score bonus = SCORE_ZERO;
// Second-degree polynomial material imbalance, by Tord Romstad // Second-degree polynomial material imbalance, by Tord Romstad
for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1) for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)
@ -213,7 +216,7 @@ Entry* probe(const Position& pos) {
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK), { pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } }; pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
e->value = int16_t((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16); e->score = (imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16;
return e; return e;
} }

View file

@ -37,8 +37,8 @@ namespace Material {
struct Entry { struct Entry {
Score imbalance() const { return make_score(value, value); } Score imbalance() const { return score; }
Phase game_phase() const { return gamePhase; } Phase game_phase() const { return (Phase)gamePhase; }
bool specialized_eval_exists() const { return evaluationFunction != nullptr; } bool specialized_eval_exists() const { return evaluationFunction != nullptr; }
Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); } Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
@ -57,9 +57,9 @@ struct Entry {
const EndgameBase<Value>* evaluationFunction; const EndgameBase<Value>* evaluationFunction;
const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
// side (e.g. KPKP, KBPsK) // side (e.g. KPKP, KBPsK)
int16_t value; Score score;
int16_t gamePhase;
uint8_t factor[COLOR_NB]; uint8_t factor[COLOR_NB];
Phase gamePhase;
}; };
typedef HashTable<Entry, 8192> Table; typedef HashTable<Entry, 8192> Table;

View file

@ -66,6 +66,7 @@ namespace {
{ V(-17), V( -13), V( 100), V( 4), V( 9), V(-16), V(-31) } { V(-17), V( -13), V( 100), V( 4), V( 9), V(-16), V(-31) }
}; };
// KingOnFile[semi-open Us][semi-open Them] contains bonuses/penalties // KingOnFile[semi-open Us][semi-open Them] contains bonuses/penalties
// for king when the king is on a semi-open or open file. // for king when the king is on a semi-open or open file.
constexpr Score KingOnFile[2][2] = {{ S(-19,12), S(-6, 7) }, constexpr Score KingOnFile[2][2] = {{ S(-19,12), S(-6, 7) },