summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/search.c')
-rwxr-xr-xsrc/search.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/search.c b/src/search.c
index 28f6f3d..29bbc66 100755
--- a/src/search.c
+++ b/src/search.c
@@ -383,6 +383,13 @@ Search(IN SEARCHER_THREAD_CONTEXT *ctx,
ASSERT(!InCheck(pos, pos->uToMove));
GenerateMoves(ctx, mvHash, GENERATE_ALL_MOVES);
}
+
+ // The threat/multi-check/no-legal-king-move bonuses above
+ // are independent and can stack past ONE_PLY; clamp the
+ // combined per-position extension to what the rest of the
+ // code (e.g. split.c's HelpSearch) assumes is the max for
+ // a single node.
+ iOrigExtend = MIN(iOrigExtend, ONE_PLY);
// fall through
case PREPARE_TO_TRY_MOVES:
@@ -527,6 +534,16 @@ Search(IN SEARCHER_THREAD_CONTEXT *ctx,
uDepth,
&iExtend);
+ // Cap how many extension plies this line may spend in total
+ // (root to here) so that a chain of checks/threats/etc. can't
+ // stall uDepth's descent indefinitely and burn the entire
+ // MAX_PLY_PER_SEARCH ply budget on one forcing sequence.
+ if (iExtend > 0)
+ {
+ iExtend = MIN(iExtend,
+ MAX(MAX_EXTEND_PER_LINE - pf->iCumulativeExtend, 0));
+ }
+
// Decide whether or not to do history pruning
if (TRUE == WeShouldDoHistoryPruning(iRoughEval,
iAlpha,
@@ -561,6 +578,7 @@ Search(IN SEARCHER_THREAD_CONTEXT *ctx,
// Compute the next search depth for this move/subtree.
uNextDepth = uDepth - ONE_PLY + iExtend;
if (uNextDepth >= MAX_DEPTH_PER_SEARCH) uNextDepth = 0;
+ pf->iCumulativeExtend += iExtend;
ASSERT(pf->fAvoidNullmove == FALSE);
if (iBestScore == -INFINITY)
{
@@ -586,6 +604,7 @@ Search(IN SEARCHER_THREAD_CONTEXT *ctx,
iScore = -Search(ctx, -iBeta, -iAlpha, uNextDepth);
}
UnmakeMove(ctx, mv);
+ pf->iCumulativeExtend -= iExtend;
ASSERT(PositionsAreEquivalent(pos, &pi->sPosition));
if (WE_SHOULD_STOP_SEARCHING)
{
@@ -1327,6 +1346,7 @@ QSearch(IN SEARCHER_THREAD_CONTEXT *ctx,
-iAlpha);
pf->uQsearchDepth--;
UnmakeMove(ctx, mv);
+ if (WE_SHOULD_STOP_SEARCHING) goto end;
if (iScore > iBestScore)
{
@@ -1360,7 +1380,6 @@ QSearch(IN SEARCHER_THREAD_CONTEXT *ctx,
}
}
}
- if (WE_SHOULD_STOP_SEARCHING) goto end;
}
}
ASSERT(iBestScore > -NMATE);