13#pragma GCC diagnostic push
14#pragma GCC diagnostic ignored "-Weffc++"
24#pragma GCC diagnostic pop
29#if defined(CHRONO_MISSING)
30 gettimeofday(&execution_start, NULL);
32 execution_start = std::chrono::high_resolution_clock::now();
39#if defined(CHRONO_MISSING)
40 gettimeofday(&execution_end, NULL);
42 execution_end = std::chrono::high_resolution_clock::now();
51#if defined(BELOFTE_NOUNICODE)
64#if defined(CHRONO_MISSING)
65 return (execution_end.tv_sec * 1000000LL + execution_end.tv_usec) -
66 (execution_start.tv_sec * 1000000LL + execution_start.tv_usec);
68 return std::chrono::duration_cast<std::chrono::microseconds>(execution_end - execution_start).count();
71#if defined(CHRONO_MISSING)
72 struct timeval now_end;
73 gettimeofday(&now_end, NULL);
74 return (now_end.tv_sec * 1000000LL + now_end.tv_usec) -
75 (execution_start.tv_sec * 1000000LL + execution_start.tv_usec);
77 std::chrono::high_resolution_clock::time_point now_end;
78 now_end = std::chrono::high_resolution_clock::now();
79 return std::chrono::duration_cast<std::chrono::microseconds>(now_end - execution_start).count();
86#if defined(CHRONO_MISSING)
87 return (execution_end.tv_sec * 1000LL + execution_end.tv_usec / 1000LL) -
88 (execution_start.tv_sec * 1000LL + execution_start.tv_usec / 1000LL);
90 return std::chrono::duration_cast<std::chrono::milliseconds>(execution_end - execution_start).count();
93#if defined(CHRONO_MISSING)
94 struct timeval now_end;
95 gettimeofday(&now_end, NULL);
96 return (now_end.tv_sec * 1000LL + now_end.tv_usec / 1000LL) -
97 (execution_start.tv_sec * 1000LL + execution_start.tv_usec / 1000LL);
99 std::chrono::high_resolution_clock::time_point now_end;
100 now_end = std::chrono::high_resolution_clock::now();
101 return std::chrono::duration_cast<std::chrono::milliseconds>(now_end - execution_start).count();
108#if defined(CHRONO_MISSING)
109 return (execution_end.tv_sec + execution_end.tv_usec / 1000000LL) -
110 (execution_start.tv_sec + execution_start.tv_usec / 1000000LL);
112 return std::chrono::duration_cast<std::chrono::seconds>(execution_end - execution_start).count();
115#if defined(CHRONO_MISSING)
116 struct timeval now_end;
117 gettimeofday(&now_end, NULL);
118 return (now_end.tv_sec + now_end.tv_usec / 1000000LL) -
119 (execution_start.tv_sec + execution_start.tv_usec / 1000000LL);
121 std::chrono::high_resolution_clock::time_point now_end;
122 now_end = std::chrono::high_resolution_clock::now();
123 return std::chrono::duration_cast<std::chrono::seconds>(now_end - execution_start).count();
132belofte::stringList
const belofte::stringSplit(std::string src, std::string
const& delim)
135 size_t delimPos = src.find(delim);
136 while (delimPos != std::string::npos) {
137 v.emplace_back(src.substr(0, delimPos));
138 src = src.substr(delimPos + delim.length());
139 delimPos = src.find(delim);
141 std::string s = alltrim(src, delim);
142 if (s !=
"") v.emplace_back(s);
150std::pair<std::string, std::string> belofte::decompose(std::string
const& src,
151 std::string
const& delim)
155 size_t delimPos = src.find(delim);
156 if (delimPos != std::string::npos) {
157 first = src.substr(0, delimPos);
158 second = src.substr(delimPos + delim.length());
162 return std::make_pair(first, second);
168std::string belofte::to_string(int32_t value)
170 std::ostringstream ss;
175std::string belofte::to_string(int64_t value)
177 std::ostringstream ss;
184std::string belofte::alltrim(std::string s, std::string
const& delim)
187 while (s.find(delim) == 0) s.erase(0, 1);
188 size_t len = s.size();
189 while (!s.empty() && (s.rfind(delim) == --len)) s.erase(len, len + 1);
194bool belofte::is_number(std::string
const& s)
196 return !s.empty() && std::find_if(s.begin(), s.end(),
197 [](
unsigned char c) { return !std::isdigit(c); }) == s.end();
202int belofte::getRandomInt(
int const nCeil)
204#if defined(BELOFTE_NORANDOM)
207 if (
App().getConfig(
"random", 0)) {
208 return std::rand() % nCeil;
215int belofte::getRandomRange(
int const nStart,
int const nMax)
217#if defined(BELOFTE_NORANDOM)
218 return (nStart + nMax) / 2;
220 if (
App().getConfig(
"random", 0)) {
221 return nStart + std::rand() % (nMax + 1 - nStart);
223 return (nStart + nMax) / 2;
230std::string belofte::getRCname(std::string
const& basename)
232 std::string rcname(basename);
234 std::size_t found = rcname.rfind(std::string(
".exe"));
235 if (found != std::string::npos)
236 rcname = rcname.erase(found, std::string::npos);
237 return rcname +
".rc";
246int belofte::positionParamIndex(stringList
const& param,
247 std::string
const& find)
249 for (
unsigned int i = 0; i < param.size(); i++) {
250 if (param[i] == find)
return static_cast<int> (i);
255int belofte::positionParamValue(stringList
const& param,
256 std::string
const& find,
unsigned long const nOffSet)
258 for (
unsigned int i = 0; i < param.size(); i++) {
259 if (param[i] == find) {
260 if (i < param.size() + nOffSet)
return atoi(param[i + nOffSet].c_str());
266std::string belofte::currentDate()
268 time_t now = time(
nullptr);
271 tstruct = *localtime(&now);
272 strftime(buf,
sizeof (buf),
"%Y.%m.%d", &tstruct);
276std::string belofte::scoreAsStr(
long const sc)
278#if defined(BELOFTE_NOUNICODE)
293 else return "M-" + belofte::to_string(
static_cast<int32_t
>((
SCORE_MATE - sc + 1) / 2));
298 else return "-M" + belofte::to_string(
static_cast<int32_t
>(-(
SCORE_MATE + sc) / 2));
300 return belofte::to_string(
static_cast<int32_t
>(sc));
303std::string belofte::prettyTime(
long const nTime)
305 long nSeconds = nTime / 1000;
306 int ms = nTime % 1000;
307 std::stringstream sTime;
309 sTime << belofte::to_string(static_cast<int32_t>(nSeconds));
311 if (nSeconds >= 86400) {
312 sTime << belofte::to_string(static_cast<int32_t>(nSeconds / 86400)) <<
"d ";
315 if (nSeconds >= 3600) {
316 sTime << belofte::to_string(static_cast<int32_t>(nSeconds / 3600)) <<
":";
318 }
else if (nTime > 86400000) {
321 if (nSeconds >= 60) {
322 sTime << std::setw(2) << std::setfill(
'0')
323 << belofte::to_string(
static_cast<int32_t
>(nSeconds / 60)) <<
":";
328 sTime << std::setw(2) << std::setfill('0') << belofte::to_string(static_cast<int32_t>(nSeconds));
331 sTime <<
"." << std::setw(3) << std::setfill(
'0')
332 << belofte::to_string(
static_cast<int32_t
>(ms));
This is the main include file, needs to be included before any other include.
long long getDurationSec() const
std::string getDuration() const
TimedExecution()
implementation of timing functions
long long getDurationMilliSec() const
long long getDurationMicroSec() const
constexpr bScore SCORE_MATE
constexpr bScore SCORE_PUNDEFINED
constexpr bScore SCORE_PRACTICAL_DRAW
constexpr bScore SCORE_CONVERGE_BYDEPTH
constexpr bScore SCORE_WINNING
constexpr bScore SCORE_POSITIVE
constexpr bScore SCORE_THEORETIC_DRAW
constexpr bScore SCORE_INFINITE