feat: live framed search dashboard for a terminal

The terminal output is now a framed dashboard that is redrawn in place
ten times a second instead of a growing list of lines:

- the root position as a coloured board, with the best move's squares
  highlighted;
- the score, white's expected score as an evaluation bar, depth, playouts,
  speed, time with a progress bar (time or playout limit), tree fill and
  notes on tree reuse and collections;
- the principal variation in SAN with move numbers, wrapped and fading
  with depth;
- the most visited root moves (SAN) with a bar for their share of the
  visits, score and prior;
- a spinner while searching, "done" at the end, and bestmove in SAN.

Each frame moves the cursor back to the top of the previous one and
clears below it; lines the user typed under the dashboard (e.g. stop)
are counted and drawn over. The box adapts to the terminal's width and
height (fewer root moves, then no blank lines, the board only when it
fits). RIGBY_PRETTY=1 forces the dashboard into a pipe.

Checked: UCI output is unchanged (node-limited searches identical to
main, including tree reuse and a stalemate root; time-limited ones
differ only in node counts); go wtime, go infinite + stop and quit
work; the dashboard was driven in a real console, including the redraw,
a reused tree and the switch to UCI, and its colours were checked
rendered to HTML. Search is untouched, so the bench is unchanged.

Bench: 546018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-15 14:30:47 +01:00
1 parent 31a35fd84f
commit c859163e2c
6 files changed
+606 -181

No files matched your search

+55 -43
View File
@@ -413,43 +413,57 @@ void Searcher::print_info() const {
const i64 ms = elapsed_ms();
const u32 best = best_child(Tree::root());
pretty::Progress p;
p.depth = int(iterations_ ? std::max<u64>(1, depth_sum_ / iterations_) : 0);
p.seldepth = seldepth_;
p.cp = eval::q_to_cp(best && tree_[best].visits ? tree_[best].q : -root.q);
p.playouts = iterations_;
p.nps = ms ? iterations_ * 1000 / u64(ms) : iterations_;
p.ms = ms;
p.hashfull = int(tree_.used() * 1000 / tree_.capacity());
std::ostringstream out;
out << "info depth " << (iterations_ ? std::max<u64>(1, depth_sum_ / iterations_) : 0) << " seldepth "
<< seldepth_;
const float q = best && tree_[best].visits ? tree_[best].q : -root.q;
out << " score cp " << eval::q_to_cp(q);
out << " nodes " << iterations_ << " nps " << (ms ? iterations_ * 1000 / u64(ms) : iterations_) << " time " << ms;
out << " hashfull " << (tree_.used() * 1000 / tree_.capacity());
out << " pv";
for (const Move m : principal_variation()) out << ' ' << m.to_uci();
uci_io::send(out.str());
}
std::vector<Move> Searcher::principal_variation() const {
std::vector<Move> pv;
u32 idx = Tree::root();
for (int ply = 0; ply < 64; ply++) {
const u32 c = best_child(idx);
if (!c || !tree_[c].visits) break;
p.pv.push_back(Move::from_raw(tree_[c].move).to_uci());
pv.push_back(Move::from_raw(tree_[c].move));
idx = c;
}
if (pretty) {
uci_io::send(pretty::progress(p));
return;
}
std::ostringstream out;
out << "info depth " << p.depth << " seldepth " << p.seldepth << " score cp " << p.cp << " nodes " << p.playouts
<< " nps " << p.nps << " time " << p.ms << " hashfull " << p.hashfull << " pv";
for (const std::string& m : p.pv) out << ' ' << m;
uci_io::send(out.str());
return pv;
}
void Searcher::print_root_moves() const {
void Searcher::draw_dashboard(bool done) {
const Node& root = tree_[Tree::root()];
std::vector<pretty::RootMove> moves;
const u32 best = best_child(Tree::root());
const i64 ms = elapsed_ms();
pretty::Dashboard d;
d.root = root_pos_;
d.depth = int(iterations_ ? std::max<u64>(1, depth_sum_ / iterations_) : 0);
d.seldepth = seldepth_;
d.playouts = iterations_;
d.nps = ms ? iterations_ * 1000 / u64(ms) : iterations_;
d.ms = ms;
d.time_limit_ms = time_limit_ms_;
d.node_limit = node_limit_;
d.hashfull = int(tree_.used() * 1000 / tree_.capacity());
d.cp = eval::q_to_cp(best && tree_[best].visits ? tree_[best].q : -root.q);
d.pv = principal_variation();
for (u32 i = 0; i < root.num_children; i++) {
const Node& child = tree_[root.first_child + i];
moves.push_back({Move::from_raw(child.move).to_uci(), child.visits, eval::q_to_cp(child.q), child.prior()});
d.moves.push_back({Move::from_raw(child.move), child.visits, eval::q_to_cp(child.q), child.prior()});
}
uci_io::send(pretty::root_table(std::move(moves), 8));
d.reused = reused_;
d.collections = gc_runs_;
d.done = done;
uci_io::send(live_.draw(d));
}
SearchResult Searcher::search(const Position& root, const std::vector<u64>& history, const SearchLimits& limits,
@@ -479,6 +493,8 @@ SearchResult Searcher::search(const Position& root, const std::vector<u64>& hist
seldepth_ = 0;
gc_pending_ = false;
gc_runs_ = 0;
reused_ = reused;
node_limit_ = limits.nodes;
compute_time_limit(limits);
SearchResult result;
@@ -488,16 +504,13 @@ SearchResult Searcher::search(const Position& root, const std::vector<u64>& hist
if (root_moves.empty()) {
tree_valid_ = false;
if (print && pretty)
uci_io::send(pretty::note(root.in_check() ? "\n checkmate, no legal moves" : "\n stalemate, no legal moves"));
uci_io::send(pretty::note(root.in_check() ? "checkmate, no legal moves" : "stalemate, no legal moves"));
else if (print)
uci_io::send("info depth 0 score " + std::string(root.in_check() ? "mate 0" : "cp 0"));
return result;
}
if (print && pretty) {
if (reused) uci_io::send(pretty::reused(reused));
uci_io::send(pretty::header());
}
if (print && pretty) live_.begin();
// The root needs its children before the first playout, so that even a
// single playout leaves a move to play.
@@ -507,9 +520,11 @@ SearchResult Searcher::search(const Position& root, const std::vector<u64>& hist
expand(Tree::root(), root);
}
// UCI reports once a second. A human gets lines at 125, 250, 500 ms and so
// on, so short searches still show how the search developed.
i64 next_info = pretty ? 125 : 1000;
// UCI reports once a second; the dashboard for a human is redrawn in place
// ten times a second.
const i64 info_interval = pretty ? 100 : 1000;
const u64 info_mask = pretty ? 255 : 1023;
i64 next_info = pretty ? 0 : 1000;
do {
playout();
if (gc_pending_) {
@@ -520,24 +535,21 @@ SearchResult Searcher::search(const Position& root, const std::vector<u64>& hist
verify_tree();
#endif
}
if (print && (iterations_ & 1023) == 0) {
if (print && (iterations_ & info_mask) == 0) {
const i64 ms = elapsed_ms();
if (ms >= next_info) {
next_info = pretty && next_info < 1000 ? next_info * 2 : ms + 1000;
print_info();
next_info = ms + info_interval;
if (pretty) draw_dashboard(false);
else print_info();
}
}
} while (!should_stop(limits));
if (print) {
if (print && pretty) {
draw_dashboard(true);
} else if (print) {
print_info();
if (pretty) {
print_root_moves();
if (gc_runs_) uci_io::send(pretty::note("\n tree memory was full " + std::to_string(gc_runs_) +
"x: the least visited branches were collected"));
} else if (gc_runs_) {
uci_io::send("info string tree collected " + std::to_string(gc_runs_) + " times");
}
if (gc_runs_) uci_io::send("info string tree collected " + std::to_string(gc_runs_) + " times");
}
const u32 best = best_child(Tree::root());