X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=eb8aea24a13abc521c07016787e9ea30f3660b15;hp=7873e7dc552d5ec0cadb8db902df5fe186b31eb6;hb=ba4e215493de31263b9bd352af79d00193e545bf;hpb=e385f194e970f0675bd4c3509bca4a6c81b6df5e diff --git a/src/search.cpp b/src/search.cpp index 7873e7dc..eb8aea24 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -324,7 +324,7 @@ void MainThread::search() { void Thread::search() { - Stack stack[MAX_PLY+7], *ss = stack+4; // To allow referencing (ss-4) and (ss+2) + Stack stack[MAX_PLY+7], *ss = stack+4; // To reference from (ss-4) to (ss+2) Value bestValue, alpha, beta, delta; Move easyMove = MOVE_NONE; MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr); @@ -527,7 +527,7 @@ namespace { Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode, bool skipEarlyPruning) { const bool PvNode = NT == PV; - const bool rootNode = PvNode && (ss-1)->ply == 0; + const bool rootNode = PvNode && ss->ply == 0; assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE); assert(PvNode || (alpha == beta - 1)); @@ -553,15 +553,14 @@ namespace { moveCount = quietCount = ss->moveCount = 0; ss->statScore = 0; bestValue = -VALUE_INFINITE; - ss->ply = (ss-1)->ply + 1; // Check for the available remaining time if (thisThread == Threads.main()) static_cast(thisThread)->check_time(); - // Used to send selDepth info to GUI - if (PvNode && thisThread->selDepth < ss->ply) - thisThread->selDepth = ss->ply; + // Used to send selDepth info to GUI (selDepth counts from 1, ply from 0) + if (PvNode && thisThread->selDepth < ss->ply + 1) + thisThread->selDepth = ss->ply + 1; if (!rootNode) { @@ -584,6 +583,7 @@ namespace { assert(0 <= ss->ply && ss->ply < MAX_PLY); + (ss+1)->ply = ss->ply + 1; ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE; ss->contHistory = &thisThread->contHistory[NO_PIECE][0]; (ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE; @@ -649,8 +649,8 @@ namespace { int drawScore = TB::UseRule50 ? 1 : 0; - value = v < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply - : v > drawScore ? VALUE_MATE - MAX_PLY - ss->ply + value = v < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply + 1 + : v > drawScore ? VALUE_MATE - MAX_PLY - ss->ply - 1 : VALUE_DRAW + 2 * v * drawScore; tte->save(posKey, value_to_tt(value, ss->ply), BOUND_EXACT, @@ -947,13 +947,16 @@ moves_loop: // When in check search starts from here && moveCount > 1 && (!captureOrPromotion || moveCountPruning)) { - int mch = std::max(1, moveCount - (ss-1)->moveCount / 16); - Depth r = reduction(improving, depth, mch); + Depth r = reduction(improving, depth, moveCount); if (captureOrPromotion) r -= r ? ONE_PLY : DEPTH_ZERO; else { + // Decrease reduction if opponent's move count is high + if ((ss-1)->moveCount > 15) + r -= ONE_PLY; + // Increase reduction if ttMove is a capture if (ttCapture) r += ONE_PLY; @@ -1161,7 +1164,7 @@ moves_loop: // When in check search starts from here } ss->currentMove = bestMove = MOVE_NONE; - ss->ply = (ss-1)->ply + 1; + (ss+1)->ply = ss->ply + 1; moveCount = 0; // Check for an instant draw or if the maximum ply has been reached @@ -1176,7 +1179,6 @@ moves_loop: // When in check search starts from here // only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS. ttDepth = InCheck || depth >= DEPTH_QS_CHECKS ? DEPTH_QS_CHECKS : DEPTH_QS_NO_CHECKS; - // Transposition table lookup posKey = pos.key(); tte = TT.probe(posKey, ttHit);