+
+ // check_time() is used to print debug info and, more importantly, to detect
+ // when we are out of available time and thus stop the search.
+
+ void check_time() {
+
+ static TimePoint lastInfoTime = now();
+
+ int elapsed = Time.elapsed();
+ TimePoint tick = Limits.startTime + elapsed;
+
+ if (tick - lastInfoTime >= 1000)
+ {
+ lastInfoTime = tick;
+ dbg_print();
+ }
+
+ // An engine may not stop pondering until told so by the GUI
+ if (Limits.ponder)
+ return;
+
+ if (Limits.use_time_management())
+ {
+ bool stillAtFirstMove = Signals.firstRootMove.load(std::memory_order_relaxed)
+ && !Signals.failedLowAtRoot.load(std::memory_order_relaxed)
+ && elapsed > Time.available() * 3 / 4;
+
+ if (stillAtFirstMove || elapsed > Time.maximum() - 10)
+ Signals.stop = true;
+ }
+ else if (Limits.movetime && elapsed >= Limits.movetime)
+ Signals.stop = true;
+
+ else if (Limits.nodes && Threads.nodes_searched() >= Limits.nodes)
+ Signals.stop = true;
+ }
+