Skip to content

Commit

Permalink
Improve LMR logic separation (#301)
Browse files Browse the repository at this point in the history
Bench: 7592451
  • Loading branch information
PGG106 authored Jan 9, 2024
1 parent fa48fed commit 6431144
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ int Negamax(int alpha, int beta, int depth, const bool cutNode, S_ThreadData* td
// increment nodes count
info->nodes++;
uint64_t nodesBeforeSearch = info->nodes;
bool doFullSearch = false;
int depthReduction = 0;
// Conditions to consider LMR. Calculate how much we should reduce the search depth.
if (movesSearched >= 2 + 2 * pvNode && depth >= 3 && (isQuiet || !ttPv)) {
Expand Down Expand Up @@ -625,26 +624,22 @@ int Negamax(int alpha, int beta, int depth, const bool cutNode, S_ThreadData* td
depthReduction = std::clamp(depthReduction, 0, newDepth - 1);
// search current move with reduced depth:
score = -Negamax<false>(-alpha - 1, -alpha, newDepth - depthReduction, true, td, ss + 1);

// if we failed high on a reduced node we'll search with a reduced window and full depth
doFullSearch = score > alpha && depthReduction;
}
else
// If we skipped LMR and this isn't the first move of the node we'll search with a reduced window and full depth
doFullSearch = !pvNode || movesSearched > 0;
if (score > alpha && depthReduction) {
// SF yoink, based on the value returned by our reduced search see if we should search deeper, this is an exact yoink of what SF and frankly i don't care lmao
const bool doDeeperSearch = score > (bestScore + 53 + 2 * newDepth);
score = -Negamax<false>(-alpha - 1, -alpha, newDepth + doDeeperSearch, !cutNode, td, ss + 1);

// Search every move (excluding the first of every node) that skipped or failed LMR with full depth but a reduced window
if (doFullSearch)
{
// SF yoink, based on the value returned by our reduced search see if we should search deeper, this is an exact yoink of what SF and frankly i don't care lmao
const bool doDeeperSearch = depthReduction && score > (bestScore + 53 + 2 * newDepth);
score = -Negamax<false>(-alpha - 1, -alpha, newDepth + doDeeperSearch, !cutNode, td, ss + 1);
if (depthReduction)
{
// define the conthist bonus
int bonus = std::min(16 * (depth + 1) * (depth + 1), 1200);
updateCHScore(sd, ss, move, score > alpha ? bonus : -bonus);
}
}
// If we skipped LMR and this isn't the first move of the node we'll search with a reduced window and full depth
else if (!pvNode || movesSearched > 0) {
score = -Negamax<false>(-alpha - 1, -alpha, newDepth, !cutNode, td, ss + 1);
}

// PVS Search: Search the first move and every move that beat alpha with full depth and a full window
if (pvNode && (movesSearched == 0 || score > alpha))
Expand Down

0 comments on commit 6431144

Please sign in to comment.