1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Get rid of struct Time

We just need the milliseconds of current system
time for our needs. This allows to simplify the
API.

No functional change.
This commit is contained in:
Marco Costalba 2012-09-04 09:38:51 +02:00
parent 5900ab76a0
commit b50ce5ebfb
6 changed files with 28 additions and 26 deletions

View file

@ -111,7 +111,7 @@ void benchmark(const Position& current, istream& is) {
int64_t nodes = 0; int64_t nodes = 0;
Search::StateStackPtr st; Search::StateStackPtr st;
Time time = Time::now(); Time::point t = Time::now();
for (size_t i = 0; i < fens.size(); i++) for (size_t i = 0; i < fens.size(); i++)
{ {
@ -133,7 +133,7 @@ void benchmark(const Position& current, istream& is) {
} }
} }
int e = time.elapsed() + 1; // Assure positive to avoid a 'divide by zero' int e = Time::now() - t + 1; // Assure positive to avoid a 'divide by zero'
cerr << "\n===========================" cerr << "\n==========================="
<< "\nTotal time (ms) : " << e << "\nTotal time (ms) : " << e

View file

@ -340,7 +340,7 @@ namespace {
Book::Book() { Book::Book() {
for (int i = Time::now().msec() % 10000; i > 0; i--) for (int i = Time::now() % 10000; i > 0; i--)
RKiss.rand<unsigned>(); // Make random number generation less deterministic RKiss.rand<unsigned>(); // Make random number generation less deterministic
} }

View file

@ -68,6 +68,13 @@ const string engine_info(bool to_uci) {
} }
/// Convert system time to milliseconds. That's all we need.
Time::point Time::now() {
sys_time_t t; system_time(&t); return time_to_msec(t);
}
/// Debug functions used mainly to collect run-time statistics /// Debug functions used mainly to collect run-time statistics
static uint64_t hits[2], means[2]; static uint64_t hits[2], means[2];
@ -201,7 +208,7 @@ void timed_wait(WaitCondition& sleepCond, Lock& sleepLock, int msec) {
int tm = msec; int tm = msec;
#else #else
timespec ts, *tm = &ts; timespec ts, *tm = &ts;
uint64_t ms = Time::now().msec() + msec; uint64_t ms = Time::now() + msec;
ts.tv_sec = ms / 1000; ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000000LL; ts.tv_nsec = (ms % 1000) * 1000000LL;

View file

@ -44,15 +44,10 @@ struct Log : public std::ofstream {
}; };
struct Time { namespace Time {
int64_t msec() const { return time_to_msec(t); } typedef int64_t point;
int elapsed() const { return int(now().msec() - msec()); } point now();
}
static Time now() { Time t; system_time(&t.t); return t; }
private:
sys_time_t t;
};
template<class Entry, int Size> template<class Entry, int Size>

View file

@ -42,7 +42,7 @@ namespace Search {
LimitsType Limits; LimitsType Limits;
std::vector<RootMove> RootMoves; std::vector<RootMove> RootMoves;
Position RootPosition; Position RootPosition;
Time SearchTime; Time::point SearchTime;
StateStackPtr SetupStates; StateStackPtr SetupStates;
} }
@ -290,7 +290,7 @@ void Search::think() {
if (Options["Use Search Log"]) if (Options["Use Search Log"])
{ {
int e = SearchTime.elapsed(); int e = Time::now() - SearchTime;
Log log(Options["Search Log Filename"]); Log log(Options["Search Log Filename"]);
log << "Nodes: " << pos.nodes_searched() log << "Nodes: " << pos.nodes_searched()
@ -398,7 +398,7 @@ namespace {
// Send full PV info to GUI if we are going to leave the loop or // Send full PV info to GUI if we are going to leave the loop or
// if we have a fail high/low and we are deep in the search. // if we have a fail high/low and we are deep in the search.
if ((bestValue > alpha && bestValue < beta) || SearchTime.elapsed() > 2000) if ((bestValue > alpha && bestValue < beta) || Time::now() - SearchTime > 2000)
sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl; sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
// In case of failing high/low increase aspiration window and // In case of failing high/low increase aspiration window and
@ -431,7 +431,7 @@ namespace {
if (!Signals.stop && Options["Use Search Log"]) if (!Signals.stop && Options["Use Search Log"])
{ {
Log log(Options["Search Log Filename"]); Log log(Options["Search Log Filename"]);
log << pretty_pv(pos, depth, bestValue, SearchTime.elapsed(), &RootMoves[0].pv[0]) log << pretty_pv(pos, depth, bestValue, Time::now() - SearchTime, &RootMoves[0].pv[0])
<< std::endl; << std::endl;
} }
@ -451,14 +451,14 @@ namespace {
// Stop search if most of available time is already consumed. We // Stop search if most of available time is already consumed. We
// probably don't have enough time to search the first move at the // probably don't have enough time to search the first move at the
// next iteration anyway. // next iteration anyway.
if (SearchTime.elapsed() > (TimeMgr.available_time() * 62) / 100) if (Time::now() - SearchTime > (TimeMgr.available_time() * 62) / 100)
stop = true; stop = true;
// Stop search early if one move seems to be much better than others // Stop search early if one move seems to be much better than others
if ( depth >= 12 if ( depth >= 12
&& !stop && !stop
&& ( (bestMoveNeverChanged && pos.captured_piece_type()) && ( (bestMoveNeverChanged && pos.captured_piece_type())
|| SearchTime.elapsed() > (TimeMgr.available_time() * 40) / 100)) || Time::now() - SearchTime > (TimeMgr.available_time() * 40) / 100))
{ {
Value rBeta = bestValue - EasyMoveMargin; Value rBeta = bestValue - EasyMoveMargin;
(ss+1)->excludedMove = RootMoves[0].pv[0]; (ss+1)->excludedMove = RootMoves[0].pv[0];
@ -827,7 +827,7 @@ split_point_start: // At split points actual search starts from here
{ {
Signals.firstRootMove = (moveCount == 1); Signals.firstRootMove = (moveCount == 1);
if (thisThread == Threads.main_thread() && SearchTime.elapsed() > 2000) if (thisThread == Threads.main_thread() && Time::now() - SearchTime > 2000)
sync_cout << "info depth " << depth / ONE_PLY sync_cout << "info depth " << depth / ONE_PLY
<< " currmove " << move_to_uci(move, Chess960) << " currmove " << move_to_uci(move, Chess960)
<< " currmovenumber " << moveCount + PVIdx << sync_endl; << " currmovenumber " << moveCount + PVIdx << sync_endl;
@ -1494,7 +1494,7 @@ split_point_start: // At split points actual search starts from here
static RKISS rk; static RKISS rk;
// PRNG sequence should be not deterministic // PRNG sequence should be not deterministic
for (int i = Time::now().msec() % 50; i > 0; i--) for (int i = Time::now() % 50; i > 0; i--)
rk.rand<unsigned>(); rk.rand<unsigned>();
// RootMoves are already sorted by score in descending order // RootMoves are already sorted by score in descending order
@ -1536,7 +1536,7 @@ split_point_start: // At split points actual search starts from here
string uci_pv(const Position& pos, int depth, Value alpha, Value beta) { string uci_pv(const Position& pos, int depth, Value alpha, Value beta) {
std::stringstream s; std::stringstream s;
int t = SearchTime.elapsed(); int t = Time::now() - SearchTime;
int selDepth = 0; int selDepth = 0;
for (size_t i = 0; i < Threads.size(); i++) for (size_t i = 0; i < Threads.size(); i++)
@ -1749,9 +1749,9 @@ void Thread::idle_loop() {
void check_time() { void check_time() {
static Time lastInfoTime = Time::now(); static Time::point lastInfoTime = Time::now();
if (lastInfoTime.elapsed() >= 1000) if (Time::now() - lastInfoTime >= 1000)
{ {
lastInfoTime = Time::now(); lastInfoTime = Time::now();
dbg_print(); dbg_print();
@ -1760,7 +1760,7 @@ void check_time() {
if (Limits.ponder) if (Limits.ponder)
return; return;
int e = SearchTime.elapsed(); int e = Time::now() - SearchTime;
bool stillAtFirstMove = Signals.firstRootMove bool stillAtFirstMove = Signals.firstRootMove
&& !Signals.failedLowAtRoot && !Signals.failedLowAtRoot
&& e > TimeMgr.available_time(); && e > TimeMgr.available_time();

View file

@ -99,7 +99,7 @@ extern volatile SignalsType Signals;
extern LimitsType Limits; extern LimitsType Limits;
extern std::vector<RootMove> RootMoves; extern std::vector<RootMove> RootMoves;
extern Position RootPosition; extern Position RootPosition;
extern Time SearchTime; extern Time::point SearchTime;
extern StateStackPtr SetupStates; extern StateStackPtr SetupStates;
extern void init(); extern void init();