Skip to content

Commit

Permalink
PSQT only try 2
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaCat-OuO committed Mar 3, 2024
1 parent 5204c98 commit 0093433
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ int Eval::simple_eval(const Position& pos, Color c) {

// 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.
Value Eval::evaluate(const Position& pos, int optimism) {
Value Eval::evaluate(const Position& pos, int optimism, Value alpha, Value beta) {

assert(!pos.checkers());

int v;
Color stm = pos.side_to_move();
int shuffling = pos.rule60_count();
int simpleEval = simple_eval(pos, stm);
bool psqtOnly = std::abs(simpleEval) > 2500;
bool psqtOnly = alpha - std::abs(simpleEval) > 2500 || std::abs(simpleEval) - beta > 2500;

int nnueComplexity;
Value nnue = NNUE::evaluate(pos, true, &nnueComplexity, psqtOnly);
Expand Down Expand Up @@ -177,7 +177,7 @@ std::string Eval::trace(Position& pos) {
v = pos.side_to_move() == WHITE ? v : -v;
ss << "NNUE evaluation " << 0.01 * UCI::to_cp(v) << " (white side)\n";

v = evaluate(pos, VALUE_ZERO);
v = evaluate(pos, VALUE_ZERO, -VALUE_NONE, VALUE_NONE);
v = pos.side_to_move() == WHITE ? v : -v;
ss << "Final evaluation " << 0.01 * UCI::to_cp(v) << " (white side)";
ss << " [with scaled NNUE, ...]";
Expand Down
2 changes: 1 addition & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Eval {
std::string trace(Position& pos);

int simple_eval(const Position& pos, Color c);
Value evaluate(const Position& pos, int optimism);
Value evaluate(const Position& pos, int optimism, Value alpha, Value beta);

// 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
Expand Down
15 changes: 8 additions & 7 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,9 @@ Value Search::Worker::search(
}

if (threads.stop.load(std::memory_order_relaxed) || ss->ply >= MAX_PLY)
return (ss->ply >= MAX_PLY && !ss->inCheck) ? evaluate(pos, thisThread->optimism[us])
: value_draw(thisThread->nodes);
return (ss->ply >= MAX_PLY && !ss->inCheck)
? evaluate(pos, thisThread->optimism[us], alpha, beta)
: value_draw(thisThread->nodes);

// Step 3. Mate distance pruning. Even if we mate at the next move our score
// would be at best mate_in(ss->ply + 1), but if alpha is already bigger because
Expand Down Expand Up @@ -603,7 +604,7 @@ Value Search::Worker::search(
// Never assume anything about values stored in TT
unadjustedStaticEval = tte->eval();
if (unadjustedStaticEval == VALUE_NONE)
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]);
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us], alpha, beta);
else if (PvNode)
Eval::NNUE::hint_common_parent_position(pos);

Expand All @@ -615,7 +616,7 @@ Value Search::Worker::search(
}
else
{
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]);
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us], alpha, beta);
ss->staticEval = eval = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);

// Static evaluation is saved as it was before adjustment by correction history
Expand Down Expand Up @@ -1304,7 +1305,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
}

if (ss->ply >= MAX_PLY)
return !ss->inCheck ? evaluate(pos, thisThread->optimism[us]) : VALUE_DRAW;
return !ss->inCheck ? evaluate(pos, thisThread->optimism[us], alpha, beta) : VALUE_DRAW;

assert(0 <= ss->ply && ss->ply < MAX_PLY);

Expand Down Expand Up @@ -1335,7 +1336,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
// Never assume anything about values stored in TT
unadjustedStaticEval = tte->eval();
if (unadjustedStaticEval == VALUE_NONE)
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]);
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us], alpha, beta);
ss->staticEval = bestValue =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);

Expand All @@ -1348,7 +1349,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
{
// In case of null move search, use previous static eval with a different sign
unadjustedStaticEval = (ss - 1)->currentMove != Move::null()
? evaluate(pos, thisThread->optimism[us])
? evaluate(pos, thisThread->optimism[us], alpha, beta)
: -(ss - 1)->staticEval;
ss->staticEval = bestValue =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
Expand Down

0 comments on commit 0093433

Please sign in to comment.