diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 45658798..c8656fc2 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -199,33 +199,24 @@ Value Eval::evaluate(const Position& pos, int optimism) { assert(!pos.checkers()); - int v; - Color stm = pos.side_to_move(); - int shuffling = pos.rule50_count(); - int simpleEval = simple_eval(pos, stm); + int simpleEval = simple_eval(pos, pos.side_to_move()); + bool smallNet = std::abs(simpleEval) > 1050; - bool lazy = std::abs(simpleEval) > 2550; - if (lazy) - v = simpleEval; - else - { - bool smallNet = std::abs(simpleEval) > 1050; + int nnueComplexity; - int nnueComplexity; + Value nnue = smallNet ? NNUE::evaluate(pos, true, &nnueComplexity) + : NNUE::evaluate(pos, true, &nnueComplexity); - Value nnue = smallNet ? NNUE::evaluate(pos, true, &nnueComplexity) - : NNUE::evaluate(pos, true, &nnueComplexity); + // Blend optimism and eval with nnue complexity and material imbalance + optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / 512; + nnue -= nnue * (nnueComplexity + std::abs(simpleEval - nnue)) / 32768; - // Blend optimism and eval with nnue complexity and material imbalance - optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / 512; - nnue -= nnue * (nnueComplexity + std::abs(simpleEval - nnue)) / 32768; - - int npm = pos.non_pawn_material() / 64; - v = (nnue * (915 + npm + 9 * pos.count()) + optimism * (154 + npm)) / 1024; - } + int npm = pos.non_pawn_material() / 64; + int v = (nnue * (915 + npm + 9 * pos.count()) + optimism * (154 + npm)) / 1024; // Damp down the evaluation linearly when shuffling - v = v * (200 - shuffling) / 214; + int shuffling = pos.rule50_count(); + v = v * (200 - shuffling) / 214; // Guarantee evaluation does not hit the tablebase range v = std::clamp(int(v), VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);