Skip to content

Commit

Permalink
Merge branch 'official-stockfish:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
RainRat authored May 18, 2024
2 parents 4933d8c + 4edd1a3 commit 3753bba
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
8 changes: 7 additions & 1 deletion src/bitboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@ Bitboard sliding_attack(PieceType pt, Square sq, Bitboard occupied) {
for (Direction d : (pt == ROOK ? RookDirections : BishopDirections))
{
Square s = sq;
while (safe_destination(s, d) && !(occupied & s))
while (safe_destination(s, d))
{
attacks |= (s += d);
if (occupied & s)
{
break;
}
}
}

return attacks;
Expand Down
14 changes: 9 additions & 5 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ int Eval::simple_eval(const Position& pos, Color c) {
+ (pos.non_pawn_material(c) - pos.non_pawn_material(~c));
}

bool Eval::use_smallnet(const Position& pos) {
int simpleEval = simple_eval(pos, pos.side_to_move());
return std::abs(simpleEval) > 1126 + 6 * pos.count<PAWN>();
}

// Evaluate is the evaluator for the outer world. It returns a static evaluation
// of the position from the point of view of the side to move.
Expand All @@ -55,7 +59,7 @@ Value Eval::evaluate(const Eval::NNUE::Networks& networks,
assert(!pos.checkers());

int simpleEval = simple_eval(pos, pos.side_to_move());
bool smallNet = std::abs(simpleEval) > SmallNetThreshold + 6 * pos.count<PAWN>();
bool smallNet = use_smallnet(pos);
int nnueComplexity;
int v;

Expand All @@ -68,23 +72,23 @@ Value Eval::evaluate(const Eval::NNUE::Networks& networks,
smallNet = false;
}

const auto adjustEval = [&](int pawnCountMul, int shufflingConstant) {
const auto adjustEval = [&](int shufflingConstant) {
// Blend optimism and eval with nnue complexity and material imbalance
optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / 584;
nnue -= nnue * (nnueComplexity * 5 / 3) / 32395;

int npm = pos.non_pawn_material() / 64;
v = (nnue * (npm + 943 + pawnCountMul * pos.count<PAWN>()) + optimism * (npm + 140)) / 1058;
v = (nnue * (npm + 943 + 11 * pos.count<PAWN>()) + optimism * (npm + 140)) / 1058;

// Damp down the evaluation linearly when shuffling
int shuffling = pos.rule50_count();
v = v * (shufflingConstant - shuffling) / 207;
};

if (!smallNet)
adjustEval(11, 178);
adjustEval(178);
else
adjustEval(9, 206);
adjustEval(206);

// Guarantee evaluation does not hit the tablebase range
v = std::clamp(v, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);
Expand Down
5 changes: 2 additions & 3 deletions src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ class Position;

namespace Eval {

constexpr inline int SmallNetThreshold = 1126;

// The default net name MUST follow the format nn-[SHA256 first 12 digits].nnue
// for the build process (profile-build and fishtest) to work. Do not change the
// name of the macro or the location where this macro is defined, as it is used
// in the Makefile/Fishtest.
#define EvalFileDefaultNameBig "nn-ae6a388e4a1a.nnue"
#define EvalFileDefaultNameBig "nn-c721dfca8cd3.nnue"
#define EvalFileDefaultNameSmall "nn-baff1ede1f90.nnue"

namespace NNUE {
Expand All @@ -46,6 +44,7 @@ struct AccumulatorCaches;
std::string trace(Position& pos, const Eval::NNUE::Networks& networks);

int simple_eval(const Position& pos, Color c);
bool use_smallnet(const Position& pos);
Value evaluate(const NNUE::Networks& networks,
const Position& pos,
Eval::NNUE::AccumulatorCaches& caches,
Expand Down
4 changes: 1 addition & 3 deletions src/nnue/nnue_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ constexpr std::string_view PieceToChar(" PNBRQK pnbrqk");
void hint_common_parent_position(const Position& pos,
const Networks& networks,
AccumulatorCaches& caches) {

int simpleEvalAbs = std::abs(simple_eval(pos, pos.side_to_move()));
if (simpleEvalAbs > Eval::SmallNetThreshold + 6 * pos.count<PAWN>())
if (Eval::use_smallnet(pos))
networks.small.hint_common_access(pos, &caches.small);
else
networks.big.hint_common_access(pos, &caches.big);
Expand Down
6 changes: 2 additions & 4 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ Value Search::Worker::search(
assert(eval - beta >= 0);

// Null move dynamic reduction based on depth and eval
Depth R = std::min(int(eval - beta) / 144, 6) + depth / 3 + 4;
Depth R = std::min(int(eval - beta) / 144, 6) + depth / 3 + 5;

ss->currentMove = Move::null();
ss->continuationHistory = &thisThread->continuationHistory[0][0][NO_PIECE][0];
Expand Down Expand Up @@ -1053,11 +1053,9 @@ Value Search::Worker::search(
int doubleMargin = 285 * PvNode - 228 * !ttCapture;
int tripleMargin =
121 + 238 * PvNode - 259 * !ttCapture + 117 * (ss->ttPv || !ttCapture);
int quadMargin = 471 + 343 * PvNode - 281 * !ttCapture + 217 * ss->ttPv;

extension = 1 + (value < singularBeta - doubleMargin)
+ (value < singularBeta - tripleMargin)
+ (value < singularBeta - quadMargin);
+ (value < singularBeta - tripleMargin);

depth += ((!PvNode) && (depth < 14));
}
Expand Down
2 changes: 1 addition & 1 deletion src/tt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Stockfish {
void TTEntry::save(
Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev, uint8_t generation8) {

// Preserve any existing move for the same position
// Preserve the old ttmove if we don't have a new one
if (m || uint16_t(k) != key16)
move16 = m;

Expand Down

0 comments on commit 3753bba

Please sign in to comment.