Skip to content

Commit a55fb76

Browse files
committed
Simplify aspiration window code
Here the main difference is that now we center aspiration window on last returned score. This allows to simplify handling of mate scores. We have done a reversed SPRT tests, where we wanted to verify if master is stronger than this patch. Long TC: master vs this patch (reverse test) LLR: -2.95 (-2.94,2.94) Total: 37992 W: 7012 L: 6920 D: 24060 bench: 4507288
1 parent 838255e commit a55fb76

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

src/search.cpp

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,12 @@ namespace {
296296
Value bestValue, alpha, beta, delta;
297297

298298
memset(ss-1, 0, 4 * sizeof(Stack));
299-
depth = BestMoveChanges = 0;
300-
bestValue = delta = -VALUE_INFINITE;
301299
(ss-1)->currentMove = MOVE_NULL; // Hack to skip update gains
300+
301+
depth = BestMoveChanges = 0;
302+
bestValue = delta = alpha = -VALUE_INFINITE;
303+
beta = VALUE_INFINITE;
304+
302305
TT.new_search();
303306
History.clear();
304307
Gains.clear();
@@ -328,17 +331,12 @@ namespace {
328331
// MultiPV loop. We perform a full root search for each PV line
329332
for (PVIdx = 0; PVIdx < PVSize; PVIdx++)
330333
{
331-
// Set aspiration window default width
332-
if (depth >= 5 && abs(RootMoves[PVIdx].prevScore) < VALUE_KNOWN_WIN)
334+
// Reset aspiration window starting size
335+
if (depth >= 5)
333336
{
334337
delta = Value(16);
335-
alpha = RootMoves[PVIdx].prevScore - delta;
336-
beta = RootMoves[PVIdx].prevScore + delta;
337-
}
338-
else
339-
{
340-
alpha = -VALUE_INFINITE;
341-
beta = VALUE_INFINITE;
338+
alpha = std::max(RootMoves[PVIdx].prevScore - delta,-VALUE_INFINITE);
339+
beta = std::min(RootMoves[PVIdx].prevScore + delta, VALUE_INFINITE);
342340
}
343341

344342
// Start with a small aspiration window and, in case of fail high/low,
@@ -366,35 +364,28 @@ namespace {
366364
if (Signals.stop)
367365
return;
368366

369-
// In case of failing high/low increase aspiration window and
367+
// In case of failing low/high increase aspiration window and
370368
// research, otherwise exit the loop.
371-
if (bestValue > alpha && bestValue < beta)
372-
break;
373-
374-
// Give some update (without cluttering the UI) before to research
375-
if (Time::now() - SearchTime > 3000)
376-
sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
377-
378-
if (abs(bestValue) >= VALUE_KNOWN_WIN)
369+
if (bestValue <= alpha)
379370
{
380-
alpha = -VALUE_INFINITE;
381-
beta = VALUE_INFINITE;
371+
alpha = std::max(bestValue - delta, -VALUE_INFINITE);
372+
373+
Signals.failedLowAtRoot = true;
374+
Signals.stopOnPonderhit = false;
382375
}
383376
else if (bestValue >= beta)
384-
{
385-
beta += delta;
386-
delta += delta / 2;
387-
}
377+
beta = std::min(bestValue + delta, VALUE_INFINITE);
378+
388379
else
389-
{
390-
Signals.failedLowAtRoot = true;
391-
Signals.stopOnPonderhit = false;
380+
break;
392381

393-
alpha -= delta;
394-
delta += delta / 2;
395-
}
382+
delta += delta / 2;
396383

397384
assert(alpha >= -VALUE_INFINITE && beta <= VALUE_INFINITE);
385+
386+
// Give some update (without cluttering the UI) before to research
387+
if (Time::now() - SearchTime > 3000)
388+
sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
398389
}
399390

400391
// Sort the PV lines searched so far and update the GUI

0 commit comments

Comments
 (0)