using Eval::evaluate;
using namespace Search;
-// For some reason argument-dependent lookup (ADL) doesn't work for Android's
-// STLPort, so explicitly qualify following functions.
-using std::count;
-using std::find;
-
namespace {
// Set to true to force running with one thread. Used for debugging
/// Search::perft() is our utility to verify move generation. All the leaf nodes
/// up to the given depth are generated and counted and the sum returned.
-int64_t Search::perft(Position& pos, Depth depth) {
-
- StateInfo st;
- int64_t cnt = 0;
-
- MoveList<LEGAL> ml(pos);
+size_t Search::perft(Position& pos, Depth depth) {
- // At the last ply just return the number of moves (leaf nodes)
+ // At the last ply just return the number of legal moves (leaf nodes)
if (depth == ONE_PLY)
- return ml.size();
+ return MoveList<LEGAL>(pos).size();
+ StateInfo st;
+ size_t cnt = 0;
CheckInfo ci(pos);
- for ( ; !ml.end(); ++ml)
+
+ for (MoveList<LEGAL> ml(pos); !ml.end(); ++ml)
{
pos.do_move(ml.move(), st, ci, pos.move_gives_check(ml.move(), ci));
cnt += perft(pos, depth - ONE_PLY);
pos.undo_move(ml.move());
}
+
return cnt;
}
{
Move bookMove = book.probe(pos, Options["Book File"], Options["Best Book Move"]);
- if (bookMove && count(RootMoves.begin(), RootMoves.end(), bookMove))
+ if (bookMove && std::count(RootMoves.begin(), RootMoves.end(), bookMove))
{
- std::swap(RootMoves[0], *find(RootMoves.begin(), RootMoves.end(), bookMove));
+ std::swap(RootMoves[0], *std::find(RootMoves.begin(), RootMoves.end(), bookMove));
goto finalize;
}
}
if (skillBest == MOVE_NONE) // Still unassigned ?
skillBest = do_skill_level();
- std::swap(RootMoves[0], *find(RootMoves.begin(), RootMoves.end(), skillBest));
+ std::swap(RootMoves[0], *std::find(RootMoves.begin(), RootMoves.end(), skillBest));
}
}
// At root obey the "searchmoves" option and skip moves not listed in Root
// Move List, as a consequence any illegal move is also skipped. In MultiPV
// mode we also skip PV moves which have been already searched.
- if (RootNode && !count(RootMoves.begin() + PVIdx, RootMoves.end(), move))
+ if (RootNode && !std::count(RootMoves.begin() + PVIdx, RootMoves.end(), move))
continue;
// At PV and SpNode nodes we want all moves to be legal since the beginning
// be trusted, and we don't update the best move and/or PV.
if (RootNode && !Signals.stop)
{
- RootMove& rm = *find(RootMoves.begin(), RootMoves.end(), move);
+ RootMove& rm = *std::find(RootMoves.begin(), RootMoves.end(), move);
// PV move or new best move ?
if (isPvMove || value > alpha)
int t = SearchTime.elapsed();
int selDepth = 0;
- for (int i = 0; i < Threads.size(); i++)
+ for (size_t i = 0; i < Threads.size(); i++)
if (Threads[i].maxPly > selDepth)
selDepth = Threads[i].maxPly;
}
-/// Thread::idle_loop() is where the thread is parked when it has no work to do.
-/// The parameter 'master_sp', if non-NULL, is a pointer to an active SplitPoint
-/// object for which the thread is the master.
+/// Thread::idle_loop() is where the thread is parked when it has no work to do
+
+void Thread::idle_loop() {
+
+ // Pointer 'sp_master', if non-NULL, points to the active SplitPoint
+ // object for which the thread is the master.
+ const SplitPoint* sp_master = splitPointsCnt ? curSplitPoint : NULL;
-void Thread::idle_loop(SplitPoint* sp_master) {
+ assert(!sp_master || (sp_master->master == this && is_searching));
// 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.
// case we are the last slave of the split point.
if ( Threads.use_sleeping_threads()
&& this != sp->master
- && !sp->master->is_searching)
+ && !sp->slavesMask)
+ {
+ assert(!sp->master->is_searching);
sp->master->wake_up();
+ }
// After releasing the lock we cannot access anymore any SplitPoint
// related data in a safe way becuase it could have been released under