Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LMR logic separation #301

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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