void set_active_threads(int newActiveThreads) { ActiveThreads = newActiveThreads; }
void incrementNodeCounter(int threadID) { threads[threadID].nodes++; }
void incrementBetaCounter(Color us, Depth d, int threadID) { threads[threadID].betaCutOffs[us] += unsigned(d); }
- void print_current_line(SearchStack ss[], int ply, int threadID);
void resetNodeCounters();
void resetBetaCounters();
void put_threads_to_sleep();
void idle_loop(int threadID, SplitPoint* waitSp);
bool split(const Position& pos, SearchStack* ss, int ply, Value* alpha, const Value beta, Value* bestValue,
- const Value futilityValue, Depth depth, int* moves, MovePicker* mp, int master, bool pvNode);
+ Depth depth, int* moves, MovePicker* mp, int master, bool pvNode);
private:
- friend void poll();
+ friend void poll(SearchStack ss[], int ply);
int ActiveThreads;
volatile bool AllThreadsShouldExit, AllThreadsShouldSleep;
Thread threads[MAX_THREADS];
SplitPoint SplitPointStack[MAX_THREADS][ACTIVE_SPLIT_POINTS_MAX];
- Lock MPLock, IOLock;
+ Lock MPLock;
#if !defined(_MSC_VER)
pthread_cond_t WaitCond;
int current_search_time();
int nps();
- void poll();
+ void poll(SearchStack ss[], int ply);
void ponderhit();
void wait_for_stop_or_ponderhit();
void init_ss_array(SearchStack ss[]);
&& TM.available_thread_exists(threadID)
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
- && TM.split(pos, ss, ply, &alpha, beta, &bestValue, VALUE_NONE,
+ && TM.split(pos, ss, ply, &alpha, beta, &bestValue,
depth, &moveCount, &mp, threadID, true))
break;
}
const TTEntry* tte;
Move ttMove, move;
Depth ext, newDepth;
- Value bestValue, refinedValue, nullValue, value, futilityValue, futilityValueScaled;
+ Value bestValue, refinedValue, nullValue, value, futilityValueScaled;
bool isCheck, singleEvasion, moveIsCheck, captureOrPromotion, dangerous;
bool mateThreat = false;
int moveCount = 0;
- futilityValue = refinedValue = bestValue = value = -VALUE_INFINITE;
+ refinedValue = bestValue = value = -VALUE_INFINITE;
if (depth < OnePly)
return qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID);
else
ss[ply].eval = evaluate(pos, ei, threadID);
- futilityValue = ss[ply].eval + futility_margin(depth, 0); //FIXME: Remove me, only for split
refinedValue = refine_eval(tte, ss[ply].eval, ply); // Enhance accuracy with TT value if possible
update_gains(pos, ss[ply - 1].currentMove, ss[ply - 1].eval, ss[ply].eval);
}
&& TM.available_thread_exists(threadID)
&& !AbortSearch
&& !TM.thread_should_stop(threadID)
- && TM.split(pos, ss, ply, NULL, beta, &bestValue, futilityValue, //FIXME: SMP & futilityValue
+ && TM.split(pos, ss, ply, NULL, beta, &bestValue,
depth, &moveCount, &mp, threadID, false))
break;
}
Move move;
int moveCount;
bool isCheck = pos.is_check();
- bool useFutilityPruning = sp->depth < 7 * OnePly //FIXME: sync with search
- && !isCheck;
+ // Step 10. Loop through moves
+ // Loop through all legal moves until no moves remain or a beta cutoff occurs
lock_grab(&(sp->lock));
while ( sp->bestValue < sp->beta
bool moveIsCheck = pos.move_is_check(move, ci);
bool captureOrPromotion = pos.move_is_capture_or_promotion(move);
- ss[sp->ply].currentMove = move;
-
- // Decide the new search depth
+ // Step 11. Decide the new search depth
bool dangerous;
Depth ext = extension(pos, move, false, captureOrPromotion, moveIsCheck, false, false, &dangerous);
Depth newDepth = sp->depth - OnePly + ext;
- // Prune?
- if ( useFutilityPruning
+ // Update current move
+ ss[sp->ply].currentMove = move;
+
+ // Step 12. Futility pruning
+ if ( !isCheck
&& !dangerous
- && !captureOrPromotion)
+ && !captureOrPromotion
+ && !move_is_castle(move))
{
// Move count based pruning
if ( moveCount >= futility_move_count(sp->depth)
}
// Value based pruning
- Value futilityValueScaled = sp->futilityValue - moveCount * 8; //FIXME: sync with search
+ Depth predictedDepth = newDepth - nonpv_reduction(sp->depth, moveCount);
+ Value futilityValueScaled = ss[sp->ply].eval + futility_margin(predictedDepth, moveCount)
+ + H.gain(pos.piece_on(move_from(move)), move_to(move)) + 45;
if (futilityValueScaled < sp->beta)
{
NodesSincePoll++;
if (NodesSincePoll >= NodesBetweenPolls)
{
- poll();
+ poll(ss, ply);
NodesSincePoll = 0;
}
}
ss[ply].init(ply);
ss[ply + 2].initKillers();
- TM.print_current_line(ss, ply, threadID);
}
// looks at the time consumed so far and decides if it's time to abort the
// search.
- void poll() {
+ void poll(SearchStack ss[], int ply) {
static int lastInfoTime;
int t = current_search_time();
else if (t - lastInfoTime >= 1000)
{
lastInfoTime = t;
- lock_grab(&TM.IOLock);
if (dbg_show_mean)
dbg_print_mean();
cout << "info nodes " << TM.nodes_searched() << " nps " << nps()
<< " time " << t << " hashfull " << TT.full() << endl;
- lock_release(&TM.IOLock);
+ // We only support current line printing in single thread mode
+ if (ShowCurrentLine && TM.active_threads() == 1)
+ {
+ cout << "info currline";
+ for (int p = 0; p < ply; p++)
+ cout << " " << ss[p].currentMove;
- if (ShowCurrentLine)
- TM.threads[0].printCurrentLineRequest = true;
+ cout << endl;
+ }
}
// Should we stop the search?
// Initialize global locks
lock_init(&MPLock, NULL);
- lock_init(&IOLock, NULL);
// Initialize SplitPointStack locks
for (i = 0; i < MAX_THREADS; i++)
// splitPoint->cpus becomes 0), split() returns true.
bool ThreadsManager::split(const Position& p, SearchStack* sstck, int ply,
- Value* alpha, const Value beta, Value* bestValue, const Value futilityValue,
+ Value* alpha, const Value beta, Value* bestValue,
Depth depth, int* moves, MovePicker* mp, int master, bool pvNode) {
assert(p.is_ok());
splitPoint->beta = beta;
splitPoint->pvNode = pvNode;
splitPoint->bestValue = *bestValue;
- splitPoint->futilityValue = futilityValue;
splitPoint->master = master;
splitPoint->mp = mp;
splitPoint->moves = *moves;
// This makes the threads to go to sleep
AllThreadsShouldSleep = true;
-
- // Reset flags to a known state.
- for (int i = 1; i < ActiveThreads; i++)
- {
- // This flag can be in a random state
- threads[i].printCurrentLineRequest = false;
- }
- }
-
- // print_current_line() prints _once_ the current line of search for a
- // given thread and then setup the print request for the next thread.
- // Called when the UCI option UCI_ShowCurrLine is 'true'.
-
- void ThreadsManager::print_current_line(SearchStack ss[], int ply, int threadID) {
-
- assert(ply >= 0 && ply < PLY_MAX);
- assert(threadID >= 0 && threadID < ActiveThreads);
-
- if (!threads[threadID].printCurrentLineRequest)
- return;
-
- // One shot only
- threads[threadID].printCurrentLineRequest = false;
-
- if (threads[threadID].state == THREAD_SEARCHING)
- {
- lock_grab(&IOLock);
- cout << "info currline " << (threadID + 1);
- for (int p = 0; p < ply; p++)
- cout << " " << ss[p].currentMove;
-
- cout << endl;
- lock_release(&IOLock);
- }
-
- // Setup print request for the next thread ID
- if (threadID + 1 < ActiveThreads)
- threads[threadID + 1].printCurrentLineRequest = true;
}
-
/// The RootMoveList class
// RootMoveList c'tor