Skip to content

Commit

Permalink
Call cycle detection before qsearch()
Browse files Browse the repository at this point in the history
This has the property of raising alpha before calling qsearch(), thus
maybe giving some more cuts during qsearch(). The patch is equivalent
to the use of cycle detection inside qsearch() at depth 0, but is in
fact implemented by re-ordering code inside search(), which explains
the [0..4] bounds in the following tests.

STC (interrupted after 124250 games, with LLR=0.87):
http://tests.stockfishchess.org/tests/view/5b1500bd0ebc5902a8b420bf
LLR: 0.87 (-2.94,2.94) [0.00,4.00]
Total: 124250 W: 24973 L: 24470 D: 74807

LTC:
http://tests.stockfishchess.org/tests/view/5b1590eb0ebc5902a84dcd09
LLR: 2.96 (-2.94,2.94) [0.00,4.00]
Total: 74234 W: 11098 L: 10733 D: 52403

Closes #1635

Bench: 4326784
  • Loading branch information
snicolet committed Jun 5, 2018
1 parent 9597ad8 commit e4f8a4f
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,25 @@ namespace {
template <NodeType NT>
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {

// Use quiescence search when needed
if (depth < ONE_PLY)
return qsearch<NT>(pos, ss, alpha, beta);

constexpr bool PvNode = NT == PV;
const bool rootNode = PvNode && ss->ply == 0;

// Check if we have an upcoming move which draws by repetition, or
// if the opponent had an alternative move earlier to this position.
if ( pos.rule50_count() >= 3
&& alpha < VALUE_DRAW
&& !rootNode
&& pos.has_game_cycle(ss->ply))
{
alpha = VALUE_DRAW;
if (alpha >= beta)
return alpha;
}

// Dive into quiescence search when the depth reaches zero
if (depth < ONE_PLY)
return qsearch<NT>(pos, ss, alpha, beta);

assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE);
assert(PvNode || (alpha == beta - 1));
assert(DEPTH_ZERO < depth && depth < DEPTH_MAX);
Expand Down Expand Up @@ -578,17 +590,6 @@ namespace {
beta = std::min(mate_in(ss->ply+1), beta);
if (alpha >= beta)
return alpha;

// Check if there exists a move which draws by repetition, or an alternative
// earlier move to this position.
if ( pos.rule50_count() >= 3
&& alpha < VALUE_DRAW
&& pos.has_game_cycle(ss->ply))
{
alpha = VALUE_DRAW;
if (alpha >= beta)
return alpha;
}
}

assert(0 <= ss->ply && ss->ply < MAX_PLY);
Expand Down

0 comments on commit e4f8a4f

Please sign in to comment.