std::vector<RootMove> RootMoves;
Position RootPos;
Color RootColor;
- Time::point SearchTime, IterationTime;
+ Time::point SearchTime;
StateStackPtr SetupStates;
}
RootColor = RootPos.side_to_move();
TimeMgr.init(Limits, RootPos.game_ply(), RootColor);
+ int cf = Options["Contempt Factor"] * PawnValueMg / 100; // From centipawns
+ DrawValue[ RootColor] = VALUE_DRAW - Value(cf);
+ DrawValue[~RootColor] = VALUE_DRAW + Value(cf);
+
if (RootMoves.empty())
{
RootMoves.push_back(MOVE_NONE);
}
}
- if (Options["Contempt Factor"] && !Options["UCI_AnalyseMode"])
- {
- int cf = Options["Contempt Factor"] * PawnValueMg / 100; // From centipawns
- cf = cf * Material::game_phase(RootPos) / PHASE_MIDGAME; // Scale down with phase
- DrawValue[ RootColor] = VALUE_DRAW - Value(cf);
- DrawValue[~RootColor] = VALUE_DRAW + Value(cf);
- }
- else
- DrawValue[WHITE] = DrawValue[BLACK] = VALUE_DRAW;
-
if (Options["Write Search Log"])
{
Log log(Options["Search Log Filename"]);
// Reset aspiration window starting size
if (depth >= 5)
{
- delta = Value(16);
+ delta = Value(depth > 23 ? 16 : 12);
alpha = std::max(RootMoves[PVIdx].prevScore - delta,-VALUE_INFINITE);
beta = std::min(RootMoves[PVIdx].prevScore + delta, VALUE_INFINITE);
}
sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
}
- IterationTime = Time::now() - SearchTime;
-
// If skill levels are enabled and time is up, pick a sub-optimal best move
if (skill.enabled() && skill.time_to_pick(depth))
skill.pick_move();
// Do we have time for the next iteration? Can we stop searching now?
if (Limits.use_time_management() && !Signals.stop && !Signals.stopOnPonderhit)
{
- bool stop = false; // Local variable, not the volatile Signals.stop
-
// Take some extra time if the best move has changed
if (depth > 4 && depth < 50 && MultiPV == 1)
TimeMgr.pv_instability(BestMoveChanges);
// Stop the search if only one legal move is available or all
// of the available time has been used.
if ( RootMoves.size() == 1
- || IterationTime > TimeMgr.available_time() )
- stop = true;
-
- if (stop)
+ || Time::now() - SearchTime > TimeMgr.available_time())
{
// If we are allowed to ponder do not stop the search now but
// keep pondering until the GUI sends "ponderhit" or "stop".
&& !ss->skipNullMove
&& abs(beta) < VALUE_MATE_IN_MAX_PLY)
{
- Value rbeta = beta + 200;
- Depth rdepth = depth - ONE_PLY - 3 * ONE_PLY;
+ Value rbeta = std::min(beta + 200, VALUE_INFINITE);
+ Depth rdepth = depth - 4 * ONE_PLY;
assert(rdepth >= ONE_PLY);
assert((ss-1)->currentMove != MOVE_NONE);
// case of Signals.stop or thread.cutoff_occurred() are set, but this is
// harmless because return value is discarded anyhow in the parent nodes.
// If we are in a singular extension search then return a fail low score.
- // A split node has at least one move - the one tried before to be splitted.
+ // A split node has at least one move - the one tried before to be split.
if (!moveCount)
return excludedMove ? alpha
: inCheck ? mated_in(ss->ply) : DrawValue[pos.side_to_move()];
mutex.lock();
// If we are master and all slaves have finished then exit idle_loop
- if (this_sp && !this_sp->slavesMask)
+ if (this_sp && this_sp->slavesMask.none())
{
mutex.unlock();
break;
searching = false;
activePosition = NULL;
- sp->slavesMask &= ~(1ULL << idx);
+ sp->slavesMask.reset(idx);
sp->nodes += pos.nodes_searched();
// Wake up the master thread so to allow it to return from the idle
// loop in case we are the last slave of the split point.
if ( Threads.sleepWhileIdle
&& this != sp->masterThread
- && !sp->slavesMask)
+ && sp->slavesMask.none())
{
assert(!sp->masterThread->searching);
sp->masterThread->notify_one();
// If this thread is the master of a split point and all slaves have finished
// their work at this split point, return from the idle loop.
- if (this_sp && !this_sp->slavesMask)
+ if (this_sp && this_sp->slavesMask.none())
{
this_sp->mutex.lock();
- bool finished = !this_sp->slavesMask; // Retest under lock protection
+ bool finished = this_sp->slavesMask.none(); // Retest under lock protection
this_sp->mutex.unlock();
if (finished)
return;
sp.mutex.lock();
nodes += sp.nodes;
- Bitboard sm = sp.slavesMask;
- while (sm)
- {
- Position* pos = Threads[pop_lsb(&sm)]->activePosition;
- if (pos)
- nodes += pos->nodes_searched();
- }
+
+ for (size_t idx = 0; idx < Threads.size(); ++idx)
+ if (sp.slavesMask.test(idx) && Threads[idx]->activePosition)
+ nodes += Threads[idx]->activePosition->nodes_searched();
sp.mutex.unlock();
}
Time::point elapsed = Time::now() - SearchTime;
bool stillAtFirstMove = Signals.firstRootMove
&& !Signals.failedLowAtRoot
- && elapsed > TimeMgr.available_time()
- && elapsed > IterationTime * 1.4;
+ && elapsed > TimeMgr.available_time() * 75 / 100;
bool noMoreTime = elapsed > TimeMgr.maximum_time() - 2 * TimerThread::Resolution
|| stillAtFirstMove;