Merge official-stockfish/master
authorFabian Fichter <ianfab@users.noreply.github.com>
Sun, 18 Jul 2021 11:51:44 +0000 (13:51 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 18 Jul 2021 11:51:44 +0000 (13:51 +0200)
bench: 4890740

1  2 
README.md
src/evaluate.cpp
src/evaluate.h
src/nnue/nnue_feature_transformer.h
src/search.cpp

diff --cc README.md
Simple merge
@@@ -241,14 -214,13 +241,13 @@@ using namespace Trace
  namespace {
  
    // Threshold for lazy and space evaluation
-   constexpr Value LazyThreshold1 =  Value(1565);
-   constexpr Value LazyThreshold2 =  Value(1102);
-   constexpr Value SpaceThreshold = Value(11551);
-   constexpr Value NNUEThreshold1 =   Value(682);
-   constexpr Value NNUEThreshold2 =   Value(176);
+   constexpr Value LazyThreshold1    =  Value(1565);
+   constexpr Value LazyThreshold2    =  Value(1102);
+   constexpr Value SpaceThreshold    = Value(11551);
+   constexpr Value NNUEThreshold1    =   Value(800);
  
    // KingAttackWeights[PieceType] contains king attack weights by piece type
 -  constexpr int KingAttackWeights[PIECE_TYPE_NB] = { 0, 0, 81, 52, 44, 10 };
 +  constexpr int KingAttackWeights[PIECE_TYPE_NB] = { 0, 0, 81, 52, 44, 10, 40 };
  
    // SafeCheck[PieceType][single/multiple] contains safe check bonus by piece type,
    // higher if multiple safe checks are possible for that piece type.
@@@ -1614,31 -1126,14 +1613,15 @@@ Value Eval::evaluate(const Position& po
           return nnue;
        };
  
-       // If there is PSQ imbalance we use the classical eval. We also introduce
-       // a small probability of using the classical eval when PSQ imbalance is small.
+       // If there is PSQ imbalance we use the classical eval.
        Value psq = Value(abs(eg_value(pos.psq_score())));
        int   r50 = 16 + pos.rule50_count();
 -      bool  largePsq = psq * 16 > (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50;
 +      bool  pure = !pos.check_counting();
 +      bool  largePsq = psq * 16 > (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50 && !pure;
-       bool  classical = largePsq;
-       // Use classical evaluation for really low piece endgames.
-       // One critical case is the draw for bishop + A/H file pawn vs naked king.
-       bool lowPieceEndgame =   pos.non_pawn_material() == BishopValueMg
-                             || (pos.non_pawn_material() < 2 * RookValueMg && pos.count<PAWN>() < 2);
-       v = classical || lowPieceEndgame ? Evaluation<NO_TRACE>(pos).value()
-                                        : adjusted_NNUE();
-       // If the classical eval is small and imbalance large, use NNUE nevertheless.
-       // For the case of opposite colored bishops, switch to NNUE eval with small
-       // probability if the classical eval is less than the threshold.
-       if (    largePsq
-           && !lowPieceEndgame
-           && (   abs(v) * 16 < NNUEThreshold2 * r50
-               || (   pos.opposite_bishops()
-                   && abs(v) * 16 < (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50)))
-           v = adjusted_NNUE();
+       v = largePsq ? Evaluation<NO_TRACE>(pos).value()  // classical
+                    : adjusted_NNUE();                   // NNUE
    }
  
    // Damp down the evaluation linearly when shuffling
diff --cc src/evaluate.h
Simple merge
@@@ -166,8 -163,10 +164,10 @@@ namespace Stockfish::Eval::NNUE 
      bool write_parameters(std::ostream& stream) const {
        for (std::size_t i = 0; i < HalfDimensions; ++i)
          write_little_endian<BiasType>(stream, biases[i]);
 -      for (std::size_t i = 0; i < HalfDimensions * InputDimensions; ++i)
 +      for (std::size_t i = 0; i < HalfDimensions * FeatureSet::get_dimensions(); ++i)
          write_little_endian<WeightType>(stream, weights[i]);
 -      for (std::size_t i = 0; i < PSQTBuckets * InputDimensions; ++i)
++      for (std::size_t i = 0; i < PSQTBuckets * FeatureSet::get_dimensions(); ++i)
+         write_little_endian<PSQTWeightType>(stream, psqtWeights[i]);
        return !stream.fail();
      }
  
diff --cc src/search.cpp
@@@ -1240,13 -1098,11 +1241,17 @@@ moves_loop: // When in check, search st
                    return beta;
            }
        }
+       else if (   givesCheck
+                && depth > 6
+                && abs(ss->staticEval) > Value(100))
+           extension = 1;
  
 +      // Losing chess capture extension
 +      else if (    pos.must_capture()
 +               &&  pos.capture(move)
 +               &&  (ss->inCheck || MoveList<CAPTURES>(pos).size() == 1))
 +          extension = 1;
 +
        // Add extension to new depth
        newDepth += extension;
  
        // cases where we extend a son if it has good chances to be "interesting".
        if (    depth >= 3
            &&  moveCount > 1 + 2 * rootNode
 +          && !(pos.must_capture() && pos.has_capture())
            && (  !captureOrPromotion
-               || cutNode
-               || (!PvNode && !formerPv))
+               || (cutNode && (ss-1)->moveCount > 1)
+               || !ss->ttPv)
            && (!PvNode || ss->ply > 1 || thisThread->id() % 4 != 3))
        {
            Depth r = reduction(improving, depth, moveCount);
                if (ttCapture)
                    r++;
  
-               // Increase reduction for cut nodes (~3 Elo)
-               if (cutNode)
-                   r += 2;
                ss->statScore =  thisThread->mainHistory[us][from_to(move)]
 -                             + (*contHist[0])[movedPiece][to_sq(move)]
 -                             + (*contHist[1])[movedPiece][to_sq(move)]
 -                             + (*contHist[3])[movedPiece][to_sq(move)]
 +                             + (*contHist[0])[history_slot(movedPiece)][to_sq(move)]
 +                             + (*contHist[1])[history_slot(movedPiece)][to_sq(move)]
 +                             + (*contHist[3])[history_slot(movedPiece)][to_sq(move)]
                               - 4923;
  
                // Decrease/increase reduction for moves with a good/bad history (~30 Elo)