namespace {
- // Maximum number of allowed moves per position
- const int MOVES_MAX = 256;
-
// Types
enum NodeType { NonPV, PV };
// Init futility move count array
for (d = 0; d < 32; d++)
- FutilityMoveCountArray[d] = 3 + (1 << (3 * d / 8));
+ FutilityMoveCountArray[d] = int(3.001 + 0.25 * pow(d, 2.0));
}
// Add some extra time if the best move has changed during the last two iterations
if (Iteration > 5 && Iteration <= 50)
- TimeMgr.pv_unstability(BestMoveChangesByIteration[Iteration],
+ TimeMgr.pv_instability(BestMoveChangesByIteration[Iteration],
BestMoveChangesByIteration[Iteration-1]);
// Stop search if most of MaxSearchTime is consumed at the end of the
// Step 2. Check for aborted search and immediate draw
if (AbortSearch || ThreadsMgr.thread_should_stop(threadID))
- return VALUE_ZERO;
+ return VALUE_DRAW;
if (pos.is_draw() || ply >= PLY_MAX - 1)
return VALUE_DRAW;
lock_grab(&(sp->lock));
lock_release(&(sp->lock));
+ // In helpful master concept a master can help only a sub-tree, and
+ // because here is all finished is not possible master is booked.
assert(threads[threadID].state == THREAD_AVAILABLE);
threads[threadID].state = THREAD_SEARCHING;
void ThreadsManager::exit_threads() {
- ActiveThreads = MAX_THREADS; // HACK
- AllThreadsShouldSleep = true; // HACK
+ ActiveThreads = MAX_THREADS; // Wake up all the threads
+ AllThreadsShouldExit = true; // Let the woken up threads to exit idle_loop()
+ AllThreadsShouldSleep = true; // Avoid an assert in wake_sleeping_threads()
wake_sleeping_threads();
- // This makes the threads to exit idle_loop()
- AllThreadsShouldExit = true;
-
// Wait for thread termination
for (int i = 1; i < MAX_THREADS; i++)
while (threads[i].state != THREAD_TERMINATED) {}
assert(threadID >= 0 && threadID < ActiveThreads);
- SplitPoint* sp;
+ SplitPoint* sp = threads[threadID].splitPoint;
- for (sp = threads[threadID].splitPoint; sp && !sp->stopRequest; sp = sp->parent) {}
+ for ( ; sp && !sp->stopRequest; sp = sp->parent) {}
return sp != NULL;
}
// Make a local copy to be sure doesn't change under our feet
int localActiveSplitPoints = threads[slave].activeSplitPoints;
- if (localActiveSplitPoints == 0)
- // No active split points means that the thread is available as
- // a slave for any other thread.
- return true;
-
- if (ActiveThreads == 2)
+ // No active split points means that the thread is available as
+ // a slave for any other thread.
+ if (localActiveSplitPoints == 0 || ActiveThreads == 2)
return true;
// Apply the "helpful master" concept if possible. Use localActiveSplitPoints