Value value_from_tt(Value v, int ply);
void update_pv(Move* pv, Move move, Move* childPv);
void update_stats(const Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt);
Value value_from_tt(Value v, int ply);
void update_pv(Move* pv, Move move, Move* childPv);
void update_stats(const Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt);
- sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
+ sync_cout << UCI::pv(pos, depth, alpha, beta) << sync_endl;
// In case of failing low/high increase aspiration window and
// re-search, otherwise exit the loop.
// In case of failing low/high increase aspiration window and
// re-search, otherwise exit the loop.
<< " time " << Time::now() - SearchTime << sync_endl;
else if (PVIdx + 1 == multiPV || Time::now() - SearchTime > 3000)
<< " time " << Time::now() - SearchTime << sync_endl;
else if (PVIdx + 1 == multiPV || Time::now() - SearchTime > 3000)
- sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl;
+ sync_cout << UCI::pv(pos, depth, alpha, beta) << sync_endl;
- string uci_pv(const Position& pos, Depth depth, Value alpha, Value beta) {
+/// 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.
- std::stringstream ss;
- Time::point elapsed = Time::now() - SearchTime + 1;
- size_t uciPVSize = std::min((size_t)Options["MultiPV"], RootMoves.size());
- int selDepth = 0;
+string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
- for (Thread* th : Threads)
- if (th->maxPly > selDepth)
- selDepth = th->maxPly;
+ std::stringstream ss;
+ Time::point elapsed = Time::now() - SearchTime + 1;
+ size_t multiPV = std::min((size_t)Options["MultiPV"], RootMoves.size());
+ int selDepth = 0;
- for (size_t i = 0; i < uciPVSize; ++i)
- {
- bool updated = (i <= PVIdx);
+ for (Thread* th : Threads)
+ if (th->maxPly > selDepth)
+ selDepth = th->maxPly;
+
+ for (size_t i = 0; i < multiPV; ++i)
+ {
+ bool updated = (i <= PVIdx);
- Depth d = updated ? depth : depth - ONE_PLY;
- Value v = updated ? RootMoves[i].score : RootMoves[i].previousScore;
+ Depth d = updated ? depth : depth - ONE_PLY;
+ Value v = updated ? RootMoves[i].score : RootMoves[i].previousScore;
- ss << "info depth " << d / ONE_PLY
- << " seldepth " << selDepth
- << " multipv " << i + 1
- << " score " << UCI::value(v);
+ ss << "info"
+ << " depth " << d / ONE_PLY
+ << " seldepth " << selDepth
+ << " multipv " << i + 1
+ << " score " << UCI::value(v);
- ss << " nodes " << pos.nodes_searched()
- << " nps " << pos.nodes_searched() * 1000 / elapsed
- << " tbhits " << TB::Hits
- << " time " << elapsed
- << " pv";
+ ss << " nodes " << pos.nodes_searched()
+ << " nps " << pos.nodes_searched() * 1000 / elapsed;
- for (size_t j = 0; j < RootMoves[i].pv.size(); ++j)
- ss << " " << UCI::move(RootMoves[i].pv[j], pos.is_chess960());
- }
+ if (elapsed > 1000) // Earlier makes little sense
+ ss << " hashfull " << TT.hashfull();
void RootMove::insert_pv_in_tt(Position& pos) {
StateInfo state[MAX_PLY], *st = state;
void RootMove::insert_pv_in_tt(Position& pos) {
StateInfo state[MAX_PLY], *st = state;
- if (!ttHit || tte->move() != pv[idx]) // Don't overwrite correct entries
- tte->save(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[idx], VALUE_NONE, TT.generation());
+ TTEntry* tte = TT.probe(pos.key(), ttHit);
- assert(MoveList<LEGAL>(pos).contains(pv[idx]));
+ if (!ttHit || tte->move() != m) // Don't overwrite correct entries
+ tte->save(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, m, VALUE_NONE, TT.generation());
/// root. We try hard to have a ponder move to return to the GUI, otherwise in case of
/// 'ponder on' we have nothing to think on.
/// root. We try hard to have a ponder move to return to the GUI, otherwise in case of
/// 'ponder on' we have nothing to think on.
- TTEntry* tte = TT.probe(pos.key(), found);
- Move m = found ? tte->move() : MOVE_NONE;
- if (!MoveList<LEGAL>(pos).contains(m))
- m = MOVE_NONE;
-
+ TTEntry* tte = TT.probe(pos.key(), ttHit);