mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Prefer size_t over int for array sizes
Align to standard library conventions. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
7c1f8dbde9
commit
4b19430103
6 changed files with 26 additions and 33 deletions
|
@ -120,7 +120,7 @@ void benchmark(const Position& current, istream& is) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ struct MoveList {
|
|||
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];
|
||||
|
|
|
@ -198,24 +198,23 @@ void Search::init() {
|
|||
/// 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) {
|
||||
|
||||
// At the last ply just return the number of legal moves (leaf nodes)
|
||||
if (depth == ONE_PLY)
|
||||
return MoveList<LEGAL>(pos).size();
|
||||
|
||||
StateInfo st;
|
||||
int64_t cnt = 0;
|
||||
|
||||
MoveList<LEGAL> ml(pos);
|
||||
|
||||
// At the last ply just return the number of moves (leaf nodes)
|
||||
if (depth == ONE_PLY)
|
||||
return ml.size();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1541,7 +1540,7 @@ split_point_start: // At split points actual search starts from here
|
|||
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;
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ extern Position RootPosition;
|
|||
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
|
||||
|
|
|
@ -55,7 +55,7 @@ Thread::Thread(Fn fn) {
|
|||
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))
|
||||
|
@ -213,7 +213,7 @@ void ThreadPool::init() {
|
|||
|
||||
ThreadPool::~ThreadPool() {
|
||||
|
||||
for (int i = 0; i < size(); i++)
|
||||
for (size_t i = 0; i < size(); i++)
|
||||
delete threads[i];
|
||||
|
||||
delete timer;
|
||||
|
@ -232,7 +232,7 @@ void ThreadPool::read_uci_options() {
|
|||
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);
|
||||
|
||||
|
@ -253,7 +253,7 @@ void ThreadPool::read_uci_options() {
|
|||
|
||||
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;
|
||||
|
@ -269,7 +269,7 @@ void ThreadPool::wake_up() const {
|
|||
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ void ThreadPool::sleep() const {
|
|||
|
||||
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;
|
||||
|
||||
|
@ -344,7 +344,7 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta,
|
|||
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;
|
||||
|
|
18
src/thread.h
18
src/thread.h
|
@ -67,14 +67,11 @@ struct SplitPoint {
|
|||
|
||||
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;
|
||||
|
@ -88,7 +85,7 @@ public:
|
|||
SplitPoint splitPoints[MAX_SPLITPOINTS_PER_THREAD];
|
||||
MaterialTable materialTable;
|
||||
PawnTable pawnTable;
|
||||
int idx;
|
||||
size_t idx;
|
||||
int maxPly;
|
||||
Lock sleepLock;
|
||||
WaitCondition sleepCond;
|
||||
|
@ -107,18 +104,15 @@ public:
|
|||
/// 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;
|
||||
|
|
Loading…
Add table
Reference in a new issue