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>
77 lines
2.1 KiB
C++
77 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "position.h"
|
|
#include "types.h"
|
|
|
|
namespace rigby::pretty {
|
|
|
|
// Human-readable search display for a terminal: a framed dashboard with the
|
|
// board, the score, search statistics, the principal variation and the root
|
|
// moves, redrawn in place while the search runs. The engine uses it until the
|
|
// first "uci" command; GUIs and match runners always send "uci" (and read
|
|
// stdout through a pipe), so they only ever see plain UCI.
|
|
|
|
// True when stdout is a terminal (and NO_COLOR is not set). Turns on ANSI
|
|
// colours and UTF-8 output on the Windows console.
|
|
bool init_terminal();
|
|
|
|
std::string banner(const std::string& name, const std::string& version, const std::string& author);
|
|
|
|
// Lines the user typed (and the terminal echoed) since the dashboard was last
|
|
// drawn; each one pushed the cursor a line further down.
|
|
std::atomic<int>& typed_lines();
|
|
|
|
struct RootMove {
|
|
Move move;
|
|
u32 visits = 0;
|
|
int cp = 0; // from Q, side to move's view
|
|
float prior = 0.0f;
|
|
};
|
|
|
|
// One snapshot of a running search.
|
|
struct Dashboard {
|
|
Position root;
|
|
int depth = 0;
|
|
int seldepth = 0;
|
|
u64 playouts = 0;
|
|
u64 nps = 0;
|
|
i64 ms = 0;
|
|
i64 time_limit_ms = 0; // 0: no time limit
|
|
u64 node_limit = 0; // 0: no playout limit
|
|
int hashfull = 0; // per mille
|
|
int cp = 0; // side to move's view
|
|
std::vector<Move> pv;
|
|
std::vector<RootMove> moves;
|
|
u64 reused = 0;
|
|
int collections = 0;
|
|
bool done = false;
|
|
};
|
|
|
|
// Draws dashboards in place: each call returns the text that replaces the
|
|
// previous dashboard of the same search.
|
|
class LiveView {
|
|
public:
|
|
void begin() {
|
|
lines_ = 0;
|
|
frame_ = 0;
|
|
typed_lines() = 0;
|
|
}
|
|
std::string draw(const Dashboard& d);
|
|
|
|
private:
|
|
int lines_ = 0;
|
|
int frame_ = 0;
|
|
};
|
|
|
|
std::string note(const std::string& text);
|
|
std::string bestmove(const Position& root, Move move);
|
|
|
|
// Standard algebraic notation of a legal move, with + and #.
|
|
std::string san(const Position& pos, Move m);
|
|
|
|
} // namespace rigby::pretty
|