Skip to content

Commit

Permalink
Speed up draw detection (#475)
Browse files Browse the repository at this point in the history
Elo   | 5.35 +- 3.98 (95%)
SPRT  | 5.0+0.05s Threads=1 Hash=16MB
LLR   | 2.90 (-2.25, 2.89) [-3.00, 1.00]
Games | N: 7604 W: 1922 L: 1805 D: 3877
Penta | [30, 802, 2027, 907, 36]

Bench: 6174848
  • Loading branch information
PGG106 authored Oct 12, 2024
1 parent 8bf2e69 commit 01aab3e
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,25 @@ int Negamax(int alpha, int beta, int depth, const bool cutNode, ThreadData* td,
if (ss->ply > info->seldepth)
info->seldepth = ss->ply;

// Check for early return conditions
if (!rootNode) {
// If position is a draw return a draw score
if (IsDraw(pos))
return 0;

// Upcoming repetition detection
if (alpha < 0 && hasGameCycle(pos,ss->ply))
{
alpha = 0;
if (alpha >= beta)
return alpha;
}

// If we reached maxdepth we return a static evaluation of the position
if (ss->ply >= MAXDEPTH - 1)
return inCheck ? 0 : EvalPosition(pos);
}

// recursion escape condition
if (depth <= 0)
return Quiescence<pvNode>(alpha, beta, td, ss);
Expand All @@ -401,29 +420,12 @@ int Negamax(int alpha, int beta, int depth, const bool cutNode, ThreadData* td,
return 0;
}

// Check for early return conditions
if (!rootNode) {
// If position is a draw return a draw score
if (IsDraw(pos))
return 0;

// If we reached maxdepth we return a static evaluation of the position
if (ss->ply >= MAXDEPTH - 1)
return inCheck ? 0 : EvalPosition(pos);

// Mate distance pruning
alpha = std::max(alpha, -MATE_SCORE + ss->ply);
beta = std::min(beta, MATE_SCORE - ss->ply - 1);
if (alpha >= beta)
return alpha;

// Upcoming repetition detection
if (alpha < 0 && hasGameCycle(pos,ss->ply))
{
alpha = 0;
if (alpha >= beta)
return alpha;
}
}

// Probe the TT for useful previous search informations, we avoid doing so if we are searching a singular extension
Expand Down Expand Up @@ -839,7 +841,7 @@ int Quiescence(int alpha, int beta, ThreadData* td, SearchStack* ss) {
}

// If position is a draw return a draw score
if (IsDraw(pos))
if (MaterialDraw(pos))
return 0;

// If we reached maxdepth we return a static evaluation of the position
Expand Down

0 comments on commit 01aab3e

Please sign in to comment.