1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +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:
Marco Costalba 2012-08-19 10:20:15 +01:00
parent 7c1f8dbde9
commit 4b19430103
6 changed files with 26 additions and 33 deletions

View file

@ -120,7 +120,7 @@ void benchmark(const Position& current, istream& is) {
if (limitType == "perft") 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; cerr << "\nPerft " << limits.depth << " leaf nodes: " << cnt << endl;
nodes += cnt; nodes += cnt;
} }

View file

@ -45,7 +45,7 @@ struct MoveList {
void operator++() { cur++; } void operator++() { cur++; }
bool end() const { return cur == last; } bool end() const { return cur == last; }
Move move() const { return cur->move; } Move move() const { return cur->move; }
int size() const { return int(last - mlist); } size_t size() const { return last - mlist; }
private: private:
MoveStack mlist[MAX_MOVES]; MoveStack mlist[MAX_MOVES];

View file

@ -198,24 +198,23 @@ void Search::init() {
/// Search::perft() is our utility to verify move generation. All the leaf nodes /// 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. /// 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; StateInfo st;
int64_t cnt = 0; size_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();
CheckInfo ci(pos); 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)); pos.do_move(ml.move(), st, ci, pos.move_gives_check(ml.move(), ci));
cnt += perft(pos, depth - ONE_PLY); cnt += perft(pos, depth - ONE_PLY);
pos.undo_move(ml.move()); pos.undo_move(ml.move());
} }
return cnt; return cnt;
} }
@ -1541,7 +1540,7 @@ split_point_start: // At split points actual search starts from here
int t = SearchTime.elapsed(); int t = SearchTime.elapsed();
int selDepth = 0; 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) if (Threads[i].maxPly > selDepth)
selDepth = Threads[i].maxPly; selDepth = Threads[i].maxPly;

View file

@ -98,7 +98,7 @@ extern Position RootPosition;
extern Time SearchTime; extern Time SearchTime;
extern void init(); extern void init();
extern int64_t perft(Position& pos, Depth depth); extern size_t perft(Position& pos, Depth depth);
extern void think(); extern void think();
} // namespace Search } // namespace Search

View file

@ -55,7 +55,7 @@ Thread::Thread(Fn fn) {
lock_init(sleepLock); lock_init(sleepLock);
cond_init(sleepCond); 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); lock_init(splitPoints[j].lock);
if (!thread_create(handle, start_routine, this)) if (!thread_create(handle, start_routine, this))
@ -213,7 +213,7 @@ void ThreadPool::init() {
ThreadPool::~ThreadPool() { ThreadPool::~ThreadPool() {
for (int i = 0; i < size(); i++) for (size_t i = 0; i < size(); i++)
delete threads[i]; delete threads[i];
delete timer; delete timer;
@ -232,7 +232,7 @@ void ThreadPool::read_uci_options() {
maxThreadsPerSplitPoint = Options["Max Threads per Split Point"]; maxThreadsPerSplitPoint = Options["Max Threads per Split Point"];
minimumSplitDepth = Options["Min Split Depth"] * ONE_PLY; minimumSplitDepth = Options["Min Split Depth"] * ONE_PLY;
useSleepingThreads = Options["Use Sleeping Threads"]; useSleepingThreads = Options["Use Sleeping Threads"];
int requested = Options["Threads"]; size_t requested = Options["Threads"];
assert(requested > 0); assert(requested > 0);
@ -253,7 +253,7 @@ void ThreadPool::read_uci_options() {
void ThreadPool::wake_up() const { 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]->maxPly = 0;
threads[i]->do_sleep = false; threads[i]->do_sleep = false;
@ -269,7 +269,7 @@ void ThreadPool::wake_up() const {
void ThreadPool::sleep() 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() 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 { 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)) if (threads[i]->is_available_to(master))
return true; return true;
@ -344,7 +344,7 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta,
lock_grab(sp->lock); lock_grab(sp->lock);
lock_grab(splitLock); 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)) if (threads[i]->is_available_to(master))
{ {
sp->slavesMask |= 1ULL << i; sp->slavesMask |= 1ULL << i;

View file

@ -67,10 +67,7 @@ struct SplitPoint {
class Thread { class Thread {
Thread(const Thread&); // Only declared to disable the default ones typedef void (Thread::* Fn) (); // Pointer to member function
Thread& operator=(const Thread&); // that are not suitable in this case.
typedef void (Thread::* Fn) ();
public: public:
Thread(Fn fn); Thread(Fn fn);
@ -88,7 +85,7 @@ public:
SplitPoint splitPoints[MAX_SPLITPOINTS_PER_THREAD]; SplitPoint splitPoints[MAX_SPLITPOINTS_PER_THREAD];
MaterialTable materialTable; MaterialTable materialTable;
PawnTable pawnTable; PawnTable pawnTable;
int idx; size_t idx;
int maxPly; int maxPly;
Lock sleepLock; Lock sleepLock;
WaitCondition sleepCond; WaitCondition sleepCond;
@ -107,18 +104,15 @@ public:
/// All the access to shared thread data is done through this class. /// All the access to shared thread data is done through this class.
class ThreadPool { 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: 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(); ~ThreadPool();
Thread& operator[](int id) { return *threads[id]; } Thread& operator[](int id) { return *threads[id]; }
bool use_sleeping_threads() const { return useSleepingThreads; } bool use_sleeping_threads() const { return useSleepingThreads; }
int min_split_depth() const { return minimumSplitDepth; } 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]; } Thread* main_thread() { return threads[0]; }
void wake_up() const; void wake_up() const;