From f6512a40922d4ee143d81fb68e797a3491a5c596 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 9 Oct 2015 16:55:25 +0200 Subject: [PATCH] Move EasyMove logic to its original place And other small fixes. No functional change. --- src/search.cpp | 53 ++++++++++++++++++++++---------------------------- src/thread.cpp | 6 +++--- src/thread.h | 2 +- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 08bfc63e..9b2d705e 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -311,19 +311,6 @@ void MainThread::think() { for (Thread* th : Threads) if (th != this) th->wait_while(th->searching); - - // Clear any candidate easy move that wasn't stable for the last search - // iterations; the second condition prevents consecutive fast moves. - if (EasyMove.stableCnt < 6 || Time.elapsed() < Time.available()) - EasyMove.clear(); - - size_t multiPV = Options["MultiPV"]; - Skill skill(Options["Skill Level"]); - - // If skill level is enabled, swap best PV line with the sub-optimal one - if (skill.enabled()) - std::swap(rootMoves[0], *std::find(rootMoves.begin(), - rootMoves.end(), skill.best_move(multiPV))); } // When playing in 'nodes as time' mode, subtract the searched nodes from @@ -551,7 +538,20 @@ void Thread::search(bool isMainThread) { } searching = false; - notify_one(); // Wake up main if is sleeping waiting for us + notify_one(); // Wake up main thread if is sleeping waiting for us + + if (!isMainThread) + return; + + // Clear any candidate easy move that wasn't stable for the last search + // iterations; the second condition prevents consecutive fast moves. + if (EasyMove.stableCnt < 6 || Time.elapsed() < Time.available()) + EasyMove.clear(); + + // If skill level is enabled, swap best PV line with the sub-optimal one + if (skill.enabled()) + std::swap(rootMoves[0], *std::find(rootMoves.begin(), + rootMoves.end(), skill.best_move(multiPV))); } @@ -910,9 +910,7 @@ moves_loop: // When in check search starts from here // Move count based pruning if ( depth < 16 * ONE_PLY && moveCount >= FutilityMoveCounts[improving][depth]) - { continue; - } predictedDepth = newDepth - reduction(improving, depth, moveCount); @@ -930,9 +928,7 @@ moves_loop: // When in check search starts from here // Prune moves with negative SEE at low depths if (predictedDepth < 4 * ONE_PLY && pos.see_sign(move) < VALUE_ZERO) - { continue; - } } // Speculative prefetch as early as possible @@ -990,12 +986,10 @@ moves_loop: // When in check search starts from here // Step 16. Full depth search, when LMR is skipped or fails high if (doFullDepthSearch) - { value = newDepth < ONE_PLY ? givesCheck ? -qsearch(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO) : -qsearch(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO) : - search(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode); - } // For PV nodes only, do a full PV search on the first move or after a fail // high (in the latter case search only if value < beta), otherwise let the @@ -1082,11 +1076,11 @@ moves_loop: // When in check search starts from here quietsSearched[quietCount++] = move; } - // Following condition would detect a stop or a cutoff set only after move - // loop has been completed. But in this case bestValue is valid because we - // have fully searched our subtree, and we can anyhow save the result in TT. + // Following condition would detect a stop only after move loop has been + // completed. But in this case bestValue is valid because we have fully + // searched our subtree, and we can anyhow save the result in TT. /* - if (Signals.stop || thisThread->cutoff_occurred()) + if (Signals.stop) return VALUE_DRAW; */ @@ -1383,25 +1377,24 @@ moves_loop: // When in check search starts from here ss->killers[0] = move; } - Thread *th = pos.this_thread(); // Shorthand - Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY)); Square prevSq = to_sq((ss-1)->currentMove); HistoryStats& cmh = CounterMovesHistory[pos.piece_on(prevSq)][prevSq]; + Thread* thisThread = pos.this_thread(); - th->History.updateH(pos.moved_piece(move), to_sq(move), bonus); + thisThread->History.updateH(pos.moved_piece(move), to_sq(move), bonus); if (is_ok((ss-1)->currentMove)) { - th->Countermoves.update(pos.piece_on(prevSq), prevSq, move); + thisThread->Countermoves.update(pos.piece_on(prevSq), prevSq, move); cmh.updateCMH(pos.moved_piece(move), to_sq(move), bonus); } // Decrease all the other played quiet moves for (int i = 0; i < quietsCnt; ++i) { - th->History.updateH(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus); + thisThread->History.updateH(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus); if (is_ok((ss-1)->currentMove)) cmh.updateCMH(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus); @@ -1594,7 +1587,7 @@ void check_time() { else if (Limits.nodes) { - if ((int64_t)Threads.nodes_searched() >= Limits.nodes) + if (Threads.nodes_searched() >= Limits.nodes) Signals.stop = true; } } diff --git a/src/thread.cpp b/src/thread.cpp index a35f521f..29484273 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -219,11 +219,11 @@ void ThreadPool::read_uci_options() { } -// ThreadPool::nodes_searched() returns the number of nodes searched. +// ThreadPool::nodes_searched() returns the number of nodes searched -uint64_t ThreadPool::nodes_searched() { +int64_t ThreadPool::nodes_searched() { - uint64_t nodes = 0; + int64_t nodes = 0; for (Thread *th : *this) nodes += th->pos.nodes_searched(); return nodes; diff --git a/src/thread.h b/src/thread.h index db242837..0c6cdd5a 100644 --- a/src/thread.h +++ b/src/thread.h @@ -115,7 +115,7 @@ struct ThreadPool : public std::vector { MainThread* main() { return static_cast(at(0)); } void read_uci_options(); void start_thinking(const Position&, const Search::LimitsType&, Search::StateStackPtr&); - uint64_t nodes_searched(); + int64_t nodes_searched(); TimerThread* timer; };