void undo_move(Move m);
void do_null_move(StateInfo& newSt);
void undo_null_move();
- void increment_nodes();
- void increment_tbHits();
// Static Exchange Evaluation
bool see_ge(Move m, Value threshold = VALUE_ZERO) const;
int game_ply() const;
bool is_chess960() const;
Thread* this_thread() const;
- uint64_t nodes_searched() const;
- uint64_t tb_hits() const;
bool is_draw(int ply) const;
int rule50_count() const;
Score psq_score() const;
int castlingRightsMask[SQUARE_NB];
Square castlingRookSquare[CASTLING_RIGHT_NB];
Bitboard castlingPath[CASTLING_RIGHT_NB];
- uint64_t nodes;
- uint64_t tbHits;
int gamePly;
Color sideToMove;
Thread* thisThread;
return st->rule50;
}
-inline uint64_t Position::nodes_searched() const {
- return nodes;
-}
-
-inline void Position::increment_nodes() {
- nodes++;
-}
-
-inline uint64_t Position::tb_hits() const {
- return tbHits;
-}
-
-inline void Position::increment_tbHits() {
- tbHits++;
-}
-
inline bool Position::opposite_bishops() const {
return pieceCount[W_BISHOP] == 1
&& pieceCount[B_BISHOP] == 1
void update_pv(Move* pv, Move move, Move* childPv);
void update_cm_stats(Stack* ss, Piece pc, Square s, int bonus);
void update_stats(const Position& pos, Stack* ss, Move move, Move* quiets, int quietsCnt, int bonus);
- void check_time();
} // namespace
for (Thread* th : Threads)
{
- th->resetCalls = true;
th->counterMoves.fill(MOVE_NONE);
th->history.fill(0);
th->counterMoveHistory[NO_PIECE][0].fill(CounterMovePruneThreshold - 1);
}
+ Threads.main()->callsCnt = 0;
Threads.main()->previousScore = VALUE_INFINITE;
}
{
bestValue = ::search<PV>(rootPos, ss, alpha, beta, rootDepth, false, false);
- this->tbHits = rootPos.tb_hits();
- this->nodes = rootPos.nodes_searched();
-
// Bring the best move to the front. It is critical that sorting
// is done with a stable algorithm because all the values but the
// first and eventually the new best one are set to -VALUE_INFINITE
ss->ply = (ss-1)->ply + 1;
// Check for the available remaining time
- if (thisThread->resetCalls.load(std::memory_order_relaxed))
- {
- thisThread->resetCalls = false;
-
- thisThread->tbHits = pos.tb_hits();
- thisThread->nodes = pos.nodes_searched();
-
- // At low node count increase the checking rate to about 0.1% of nodes
- // otherwise use a default value.
- thisThread->callsCnt = Limits.nodes ? std::min(4096, int(Limits.nodes / 1024))
- : 4096;
- }
-
- if (--thisThread->callsCnt <= 0)
- {
- for (Thread* th : Threads)
- th->resetCalls = true;
-
- check_time();
- }
+ if (thisThread == Threads.main())
+ static_cast<MainThread*>(thisThread)->check_time();
// Used to send selDepth info to GUI
if (PvNode && thisThread->maxPly < ss->ply)
if (err != TB::ProbeState::FAIL)
{
- pos.increment_tbHits();
+ thisThread->tbHits.fetch_add(1, std::memory_order_relaxed);
int drawScore = TB::UseRule50 ? 1 : 0;
ss->moveCount = --moveCount;
continue;
}
-
+
if (move == ttMove && captureOrPromotion)
ttCapture = true;
r -= r ? ONE_PLY : DEPTH_ZERO;
else
{
-
// Increase reduction if ttMove is a capture
if (ttCapture)
r += ONE_PLY;
-
+
// Increase reduction for cut nodes
if (cutNode)
r += 2 * ONE_PLY;
return best;
}
+} // namespace
// 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() {
+ void MainThread::check_time() {
+
+ if (--callsCnt > 0)
+ return;
+
+ // At low node count increase the checking rate to about 0.1% of nodes
+ // otherwise use a default value.
+ callsCnt = Limits.nodes ? std::min(4096, int(Limits.nodes / 1024)) : 4096;
- static std::atomic<TimePoint> lastInfoTime = { now() };
+ static TimePoint lastInfoTime = now();
int elapsed = Time.elapsed();
TimePoint tick = Limits.startTime + elapsed;
Signals.stop = true;
}
-} // namespace
-
/// UCI::pv() formats PV information according to the UCI protocol. UCI requires
/// that all (if any) unsearched PV lines are sent using a previous search score.
Material::Table materialTable;
Endgames endgames;
size_t idx, PVIdx;
- int maxPly, callsCnt;
- std::atomic<uint64_t> tbHits;
- std::atomic<uint64_t> nodes;
+ int maxPly;
+ std::atomic<uint64_t> nodes, tbHits;
Position rootPos;
Search::RootMoves rootMoves;
std::atomic<Depth> rootDepth;
Depth completedDepth;
- std::atomic_bool resetCalls;
CounterMoveStat counterMoves;
ButterflyHistory history;
CounterMoveHistoryStat counterMoveHistory;
struct MainThread : public Thread {
virtual void search();
+ void check_time();
bool easyMovePlayed, failedLow;
double bestMoveChanges;
Value previousScore;
+ int callsCnt = 0;
};