Align to standard library conventions.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
if (limitType == "perft")
{
- int64_t cnt = Search::perft(pos, limits.depth * ONE_PLY);
+ size_t cnt = Search::perft(pos, limits.depth * ONE_PLY);
cerr << "\nPerft " << limits.depth << " leaf nodes: " << cnt << endl;
nodes += cnt;
}
void operator++() { cur++; }
bool end() const { return cur == last; }
Move move() const { return cur->move; }
- int size() const { return int(last - mlist); }
+ size_t size() const { return last - mlist; }
private:
MoveStack mlist[MAX_MOVES];
/// 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) {
+size_t Search::perft(Position& pos, Depth depth) {
- StateInfo st;
- int64_t cnt = 0;
-
- MoveList<LEGAL> ml(pos);
-
- // 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;
}
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;
extern Time SearchTime;
extern void init();
-extern int64_t perft(Position& pos, Depth depth);
+extern size_t perft(Position& pos, Depth depth);
extern void think();
} // namespace Search
lock_init(sleepLock);
cond_init(sleepCond);
- for (int j = 0; j < MAX_SPLITPOINTS_PER_THREAD; j++)
+ for (size_t j = 0; j < MAX_SPLITPOINTS_PER_THREAD; j++)
lock_init(splitPoints[j].lock);
if (!thread_create(handle, start_routine, this))
ThreadPool::~ThreadPool() {
- for (int i = 0; i < size(); i++)
+ for (size_t i = 0; i < size(); i++)
delete threads[i];
delete timer;
maxThreadsPerSplitPoint = Options["Max Threads per Split Point"];
minimumSplitDepth = Options["Min Split Depth"] * ONE_PLY;
useSleepingThreads = Options["Use Sleeping Threads"];
- int requested = Options["Threads"];
+ size_t requested = Options["Threads"];
assert(requested > 0);
void ThreadPool::wake_up() const {
- for (int i = 0; i < size(); i++)
+ for (size_t i = 0; i < size(); i++)
{
threads[i]->maxPly = 0;
threads[i]->do_sleep = false;
void ThreadPool::sleep() const {
- for (int i = 1; i < size(); i++) // Main thread will go to sleep by itself
+ for (size_t i = 1; i < size(); i++) // Main thread will go to sleep by itself
threads[i]->do_sleep = true; // to avoid a race with start_searching()
}
bool ThreadPool::available_slave_exists(Thread* master) const {
- for (int i = 0; i < size(); i++)
+ for (size_t i = 0; i < size(); i++)
if (threads[i]->is_available_to(master))
return true;
lock_grab(sp->lock);
lock_grab(splitLock);
- for (int i = 0; i < size() && !Fake; ++i)
+ for (size_t i = 0; i < size() && !Fake; ++i)
if (threads[i]->is_available_to(master))
{
sp->slavesMask |= 1ULL << i;
class Thread {
- Thread(const Thread&); // Only declared to disable the default ones
- Thread& operator=(const Thread&); // that are not suitable in this case.
-
- typedef void (Thread::* Fn) ();
+ typedef void (Thread::* Fn) (); // Pointer to member function
public:
Thread(Fn fn);
- ~Thread();
+ ~Thread();
void wake_up();
bool cutoff_occurred() const;
SplitPoint splitPoints[MAX_SPLITPOINTS_PER_THREAD];
MaterialTable materialTable;
PawnTable pawnTable;
- int idx;
+ size_t idx;
int maxPly;
Lock sleepLock;
WaitCondition sleepCond;
/// All the access to shared thread data is done through this class.
class ThreadPool {
- /* As long as the single ThreadPool object is defined as a global we don't
- need to explicitly initialize to zero its data members because variables with
- static storage duration are automatically set to zero before enter main()
- */
+
public:
- void init(); // No c'tor becuase Threads is global and we need engine initialized
+ void init(); // No c'tor, Threads object is global and engine shall be fully initialized
~ThreadPool();
Thread& operator[](int id) { return *threads[id]; }
bool use_sleeping_threads() const { return useSleepingThreads; }
int min_split_depth() const { return minimumSplitDepth; }
- int size() const { return (int)threads.size(); }
+ size_t size() const { return threads.size(); }
Thread* main_thread() { return threads[0]; }
void wake_up() const;