Skip to content

Commit

Permalink
Eval tune
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaCat-OuO committed Jul 24, 2024
1 parent 7f62ac8 commit 770f34f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "nnue/nnue_accumulator.h"

namespace Stockfish {
int evaluate_48_0 = 1024, evaluate_48_1 = 1024, evaluate_48_2 = 1024, evaluate_52_0 = 372, evaluate_53_0 = 11013, evaluate_55_0 = 31, evaluate_56_0 = 576, evaluate_56_1 = 107, evaluate_56_2 = 535, evaluate_62_0 = 279;
TUNE(evaluate_48_0, evaluate_48_1, evaluate_48_2, evaluate_52_0, evaluate_53_0, evaluate_55_0, evaluate_56_0, evaluate_56_1, evaluate_56_2, evaluate_62_0);

// 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 @@ -46,21 +48,21 @@ Value Eval::evaluate(const Eval::NNUE::Network& network,
assert(!pos.checkers());

auto [psqt, positional] = network.evaluate(pos, &caches.cache);
Value nnue = psqt + positional;
Value nnue = ((evaluate_48_0) * psqt + (evaluate_48_1) * positional) / (evaluate_48_2);
int nnueComplexity = std::abs(psqt - positional);

// Blend optimism and eval with nnue complexity
optimism += optimism * nnueComplexity / 372;
nnue -= nnue * nnueComplexity / 11013;
optimism += optimism * nnueComplexity / (evaluate_52_0);
nnue -= nnue * nnueComplexity / (evaluate_53_0);

int mm = pos.major_material() / 31;
int v = (nnue * (576 + mm) + optimism * (107 + mm)) / 535;
int mm = pos.major_material() / (evaluate_55_0);
int v = (nnue * ((evaluate_56_0) + mm) + optimism * ((evaluate_56_1) + mm)) / (evaluate_56_2);

// Evaluation grain (to get more alpha-beta cuts) with randomization (for robustness)
v = (v / 16) * 16 - 1 + (pos.key() & 0x2);

// Damp down the evaluation linearly when shuffling
v -= (v * pos.rule60_count()) / 279;
v -= (v * pos.rule60_count()) / (evaluate_62_0);

// Guarantee evaluation does not hit the mate range
v = std::clamp(v, VALUE_MATED_IN_MAX_PLY + 1, VALUE_MATE_IN_MAX_PLY - 1);
Expand Down

0 comments on commit 770f34f

Please sign in to comment.