int kingFlankAttack = popcount(b1) + popcount(b2);
int kingFlankDefense = popcount(b3);
- kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them] // (~10 Elo)
- + 183 * popcount(kingRing[Us] & weak) // (~15 Elo)
- + 148 * popcount(unsafeChecks) // (~4 Elo)
- + 98 * popcount(pos.blockers_for_king(Us)) // (~2 Elo)
- + 69 * kingAttacksCount[Them] // (~0.5 Elo)
- + 3 * kingFlankAttack * kingFlankAttack / 8 // (~0.5 Elo)
- + mg_value(mobility[Them] - mobility[Us]) // (~0.5 Elo)
- - 873 * !pos.count<QUEEN>(Them) // (~24 Elo)
- - 100 * bool(attackedBy[Us][KNIGHT] & attackedBy[Us][KING]) // (~5 Elo)
- - 6 * mg_value(score) / 8 // (~8 Elo)
- - 4 * kingFlankDefense // (~5 Elo)
- + 37; // (~0.5 Elo)
+ kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them]
+ + kingAttackersCountInHand[Them] * kingAttackersWeight[Them]
+ + kingAttackersCount[Them] * kingAttackersWeightInHand[Them]
- + 185 * popcount(kingRing[Us] & (weak | ~pos.board_bb(Us, KING))) * (1 + pos.captures_to_hand() + pos.check_counting())
++ + 183 * popcount(kingRing[Us] & (weak | ~pos.board_bb(Us, KING))) * (1 + pos.captures_to_hand() + pos.check_counting())
+ + 148 * popcount(unsafeChecks) * (1 + pos.check_counting())
+ + 98 * popcount(pos.blockers_for_king(Us))
+ + 69 * kingAttacksCount[Them] * (2 + 8 * pos.check_counting() + pos.captures_to_hand()) / 2
+ + 3 * kingFlankAttack * kingFlankAttack / 8
+ + mg_value(mobility[Them] - mobility[Us])
+ - 873 * !(pos.major_pieces(Them) || pos.captures_to_hand())
+ * 2 / (2 + 2 * pos.check_counting() + 2 * pos.two_boards() + 2 * pos.makpong()
+ + (pos.king_type() != KING) * (pos.diagonal_lines() ? 1 : 2))
+ - 100 * bool(attackedBy[Us][KNIGHT] & attackedBy[Us][KING])
+ - 6 * mg_value(score) / 8
+ - 4 * kingFlankDefense
+ + 37;
// Transform the kingDanger units into a Score, and subtract it from the evaluation
if (kingDanger > 100)
// Polynomial material imbalance parameters
- constexpr int QuadraticOurs[][PIECE_TYPE_NB] = {
+ constexpr Score QuadraticOurs[][PIECE_TYPE_NB] = {
// OUR PIECES
// pair pawn knight bishop rook queen
- {1438 }, // Bishop pair
- { 40, 38 }, // Pawn
- { 32, 255, -62 }, // Knight OUR PIECES
- { 0, 104, 4, 0 }, // Bishop
- { -26, -2, 47, 105, -208 }, // Rook
- {-189, 24, 117, 133, -134, -6 } // Queen
+ {S(1419, 1455) }, // Bishop pair
+ {S( 101, 28), S( 37, 39) }, // Pawn
+ {S( 57, 64), S(249, 187), S(-49, -62) }, // Knight OUR PIECES
+ {S( 0, 0), S(118, 137), S( 10, 27), S( 0, 0) }, // Bishop
+ {S( -63, -68), S( -5, 3), S(100, 81), S(132, 118), S(-246, -244) }, // Rook
+ {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
// pair pawn knight bishop rook queen
- { }, // Bishop pair
- { 36, }, // Pawn
- { 9, 63, }, // Knight OUR PIECES
- { 59, 65, 42, }, // Bishop
- { 46, 39, 24, -24, }, // Rook
- { 97, 100, -42, 137, 268, } // Queen
+ { }, // Bishop pair
+ {S( 33, 30) }, // Pawn
+ {S( 46, 18), S(106, 84) }, // Knight OUR PIECES
+ {S( 75, 35), S( 59, 44), S( 60, 15) }, // Bishop
+ {S( 26, 35), S( 6, 22), S( 38, 39), S(-12, -2) }, // Rook
+ {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
// the function maps because they correspond to more than one material hash key.
+ Endgame<KFsPsK> EvaluateKFsPsK[] = { Endgame<KFsPsK>(WHITE), Endgame<KFsPsK>(BLACK) };
Endgame<KXK> EvaluateKXK[] = { Endgame<KXK>(WHITE), Endgame<KXK>(BLACK) };
Endgame<KBPsK> ScaleKBPsK[] = { Endgame<KBPsK>(WHITE), Endgame<KBPsK>(BLACK) };
/// piece type for both colors.
template<Color Us>
- int imbalance(const Position& pos, const int pieceCount[][PIECE_TYPE_NB]) {
- Score imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
++ Score imbalance(const Position& pos, const int pieceCount[][PIECE_TYPE_NB]) {
constexpr Color Them = ~Us;
{ 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) } };
- e->value = int16_t((imbalance<WHITE>(pos, pieceCount) - imbalance<BLACK>(pos, pieceCount)) / 16);
- e->score = (imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16;
++ e->score = (imbalance<WHITE>(pos, pieceCount) - imbalance<BLACK>(pos, pieceCount)) / 16;
return e;
}