Skip to content

Commit

Permalink
Big tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaCat-OuO committed Feb 12, 2024
1 parent 89b8f3a commit d008bec
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 82 deletions.
12 changes: 7 additions & 5 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "ucioption.h"

namespace Stockfish {
int evaluate_cpp_142_0 = 708, evaluate_cpp_143_0 = 32858, evaluate_cpp_145_0 = 42, evaluate_cpp_146_0 = 545, evaluate_cpp_146_1 = 128, evaluate_cpp_146_2 = 1312, evaluate_cpp_149_0 = 263, evaluate_cpp_149_1 = 192;
TUNE(evaluate_cpp_142_0, evaluate_cpp_143_0, evaluate_cpp_145_0, evaluate_cpp_146_0, evaluate_cpp_146_1, evaluate_cpp_146_2, evaluate_cpp_149_0, evaluate_cpp_149_1);

namespace Eval {

Expand Down Expand Up @@ -140,14 +142,14 @@ Value Eval::evaluate(const Position& pos, int optimism) {
Value nnue = NNUE::evaluate(pos, true, &nnueComplexity);

// Blend optimism and eval with nnue complexity and material imbalance
optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / 708;
nnue -= nnue * (nnueComplexity + std::abs(simpleEval - nnue)) / 32858;
optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / (evaluate_cpp_142_0);
nnue -= nnue * (nnueComplexity + std::abs(simpleEval - nnue)) / (evaluate_cpp_143_0);

int mm = pos.major_material() / 42;
v = (nnue * (545 + mm) + optimism * (128 + mm)) / 1312;
int mm = pos.major_material() / (evaluate_cpp_145_0);
v = (nnue * ((evaluate_cpp_146_0) + mm) + optimism * ((evaluate_cpp_146_1) + mm)) / (evaluate_cpp_146_2);

// Damp down the evaluation linearly when shuffling
v = v * (263 - shuffling) / 192;
v = v * ((evaluate_cpp_149_0) - shuffling) / (evaluate_cpp_149_1);

// 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
13 changes: 13 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
#include "uci.h"

using namespace Stockfish;
static void post_update() {
auto f = [&](PieceType pt, Value v) {
PieceValue[make_piece(WHITE, pt)] = PieceValue[make_piece(BLACK, pt)] = v;
};
f(ROOK, RookValue);
f(ADVISOR, AdvisorValue);
f(CANNON, CannonValue);
f(PAWN, PawnValue);
f(KNIGHT, KnightValue);
f(BISHOP, BishopValue);
}

TUNE(RookValue, AdvisorValue, CannonValue, PawnValue, KnightValue, BishopValue, post_update);

int main(int argc, char* argv[]) {

Expand Down
4 changes: 3 additions & 1 deletion src/nnue/evaluate_nnue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include "nnue_common.h"

namespace Stockfish::Eval::NNUE {
int evaluate_nnue_cpp_183_0 = 1414, evaluate_nnue_cpp_183_1 = 1448, evaluate_nnue_cpp_183_2 = 860;
TUNE(evaluate_nnue_cpp_183_0, evaluate_nnue_cpp_183_1, evaluate_nnue_cpp_183_2);

// Input feature converter
LargePagePtr<FeatureTransformer> featureTransformer;
Expand Down Expand Up @@ -181,7 +183,7 @@ Value evaluate(const Position& pos, bool adjusted, int* complexity) {

// Adjust psqt and positional ratio in evaluation when adjusted flag is set
if (adjusted)
return static_cast<Value>((1414 * psqt + 1448 * positional) / (860 * OutputScale));
return static_cast<Value>(((evaluate_nnue_cpp_183_0) * psqt + (evaluate_nnue_cpp_183_1) * positional) / ((evaluate_nnue_cpp_183_2) * OutputScale));
else
return static_cast<Value>((psqt + positional) / OutputScale);
}
Expand Down
Loading

0 comments on commit d008bec

Please sign in to comment.