Merge official-stockfish/master
authorFabian Fichter <ianfab@users.noreply.github.com>
Mon, 21 Dec 2020 12:19:42 +0000 (13:19 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Mon, 21 Dec 2020 12:19:42 +0000 (13:19 +0100)
bench: 4525008

1  2 
src/evaluate.cpp
src/material.cpp
src/material.h
src/pawns.cpp

@@@ -764,22 -593,18 +764,22 @@@ namespace 
      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)
@@@ -28,31 -29,32 +29,33 @@@ namespace 
  
    // 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) };
@@@ -91,7 -85,7 +94,7 @@@
    /// 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;
  
@@@ -242,7 -216,7 +245,7 @@@ Entry* probe(const Position& pos) 
    { 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;
  }
  
diff --cc src/material.h
@@@ -43,6 -42,6 +42,8 @@@ struct Entry 
    bool specialized_eval_exists() const { return evaluationFunction != nullptr; }
    Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
  
++  int material_density() const { return materialDensity; }
++
    // scale_factor() takes a position and a color as input and returns a scale factor
    // for the given color. We have to provide the position in addition to the color
    // because the scale factor may also be a function which should be applied to
    const EndgameBase<Value>* evaluationFunction;
    const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
                                                               // side (e.g. KPKP, KBPsK)
-   int16_t value;
+   Score score;
+   int16_t gamePhase;
    uint8_t factor[COLOR_NB];
-   Phase gamePhase;
++
 +  int materialDensity;
  };
  
  typedef HashTable<Entry, 8192> Table;
diff --cc src/pawns.cpp
Simple merge