mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Move EasyMove logic to its original place
And other small fixes. No functional change.
This commit is contained in:
parent
8a2c8c58ca
commit
f6512a4092
3 changed files with 27 additions and 34 deletions
|
@ -311,19 +311,6 @@ void MainThread::think() {
|
||||||
for (Thread* th : Threads)
|
for (Thread* th : Threads)
|
||||||
if (th != this)
|
if (th != this)
|
||||||
th->wait_while(th->searching);
|
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
|
// When playing in 'nodes as time' mode, subtract the searched nodes from
|
||||||
|
@ -551,7 +538,20 @@ void Thread::search(bool isMainThread) {
|
||||||
}
|
}
|
||||||
|
|
||||||
searching = false;
|
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
|
// Move count based pruning
|
||||||
if ( depth < 16 * ONE_PLY
|
if ( depth < 16 * ONE_PLY
|
||||||
&& moveCount >= FutilityMoveCounts[improving][depth])
|
&& moveCount >= FutilityMoveCounts[improving][depth])
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
predictedDepth = newDepth - reduction<PvNode>(improving, depth, moveCount);
|
predictedDepth = newDepth - reduction<PvNode>(improving, depth, moveCount);
|
||||||
|
|
||||||
|
@ -930,10 +928,8 @@ moves_loop: // When in check search starts from here
|
||||||
|
|
||||||
// Prune moves with negative SEE at low depths
|
// Prune moves with negative SEE at low depths
|
||||||
if (predictedDepth < 4 * ONE_PLY && pos.see_sign(move) < VALUE_ZERO)
|
if (predictedDepth < 4 * ONE_PLY && pos.see_sign(move) < VALUE_ZERO)
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Speculative prefetch as early as possible
|
// Speculative prefetch as early as possible
|
||||||
prefetch(TT.first_entry(pos.key_after(move)));
|
prefetch(TT.first_entry(pos.key_after(move)));
|
||||||
|
@ -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
|
// Step 16. Full depth search, when LMR is skipped or fails high
|
||||||
if (doFullDepthSearch)
|
if (doFullDepthSearch)
|
||||||
{
|
|
||||||
value = newDepth < ONE_PLY ?
|
value = newDepth < ONE_PLY ?
|
||||||
givesCheck ? -qsearch<NonPV, true>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
givesCheck ? -qsearch<NonPV, true>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
||||||
: -qsearch<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
: -qsearch<NonPV, false>(pos, ss+1, -(alpha+1), -alpha, DEPTH_ZERO)
|
||||||
: - search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
|
: - search<NonPV>(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
|
// 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
|
// 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;
|
quietsSearched[quietCount++] = move;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Following condition would detect a stop or a cutoff set only after move
|
// Following condition would detect a stop only after move loop has been
|
||||||
// loop has been completed. But in this case bestValue is valid because we
|
// completed. But in this case bestValue is valid because we have fully
|
||||||
// have fully searched our subtree, and we can anyhow save the result in TT.
|
// searched our subtree, and we can anyhow save the result in TT.
|
||||||
/*
|
/*
|
||||||
if (Signals.stop || thisThread->cutoff_occurred())
|
if (Signals.stop)
|
||||||
return VALUE_DRAW;
|
return VALUE_DRAW;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1383,25 +1377,24 @@ moves_loop: // When in check search starts from here
|
||||||
ss->killers[0] = move;
|
ss->killers[0] = move;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread *th = pos.this_thread(); // Shorthand
|
|
||||||
|
|
||||||
Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY));
|
Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY));
|
||||||
|
|
||||||
Square prevSq = to_sq((ss-1)->currentMove);
|
Square prevSq = to_sq((ss-1)->currentMove);
|
||||||
HistoryStats& cmh = CounterMovesHistory[pos.piece_on(prevSq)][prevSq];
|
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))
|
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);
|
cmh.updateCMH(pos.moved_piece(move), to_sq(move), bonus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrease all the other played quiet moves
|
// Decrease all the other played quiet moves
|
||||||
for (int i = 0; i < quietsCnt; ++i)
|
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))
|
if (is_ok((ss-1)->currentMove))
|
||||||
cmh.updateCMH(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
cmh.updateCMH(pos.moved_piece(quiets[i]), to_sq(quiets[i]), -bonus);
|
||||||
|
@ -1594,7 +1587,7 @@ void check_time() {
|
||||||
|
|
||||||
else if (Limits.nodes)
|
else if (Limits.nodes)
|
||||||
{
|
{
|
||||||
if ((int64_t)Threads.nodes_searched() >= Limits.nodes)
|
if (Threads.nodes_searched() >= Limits.nodes)
|
||||||
Signals.stop = true;
|
Signals.stop = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
for (Thread *th : *this)
|
||||||
nodes += th->pos.nodes_searched();
|
nodes += th->pos.nodes_searched();
|
||||||
return nodes;
|
return nodes;
|
||||||
|
|
|
@ -115,7 +115,7 @@ struct ThreadPool : public std::vector<Thread*> {
|
||||||
MainThread* main() { return static_cast<MainThread*>(at(0)); }
|
MainThread* main() { return static_cast<MainThread*>(at(0)); }
|
||||||
void read_uci_options();
|
void read_uci_options();
|
||||||
void start_thinking(const Position&, const Search::LimitsType&, Search::StateStackPtr&);
|
void start_thinking(const Position&, const Search::LimitsType&, Search::StateStackPtr&);
|
||||||
uint64_t nodes_searched();
|
int64_t nodes_searched();
|
||||||
TimerThread* timer;
|
TimerThread* timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue