#pragma once #include #include #include #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& 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 pv; std::vector 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