feat: coloured search output for a terminal
Started from a terminal, Rigby now shows its search for a human: coloured progress lines (depth/seldepth, playouts, speed, time, a tree fill bar, score in pawns, the PV fading with depth) at 125, 250, 500 ms and then every second, and at the end a table of the most visited root moves with a bar for their share of the visits, their score and prior. Tree reuse and collections are shown as notes, and bestmove is highlighted. The first "uci" command switches to plain UCI output for good. GUIs and match runners send it first and read stdout through a pipe, so they never see the coloured output. NO_COLOR turns it off. On Windows the console gets ANSI processing and UTF-8 output. Checked: the UCI output of a scripted session (two searches with tree reuse, a stalemate root) is identical to main apart from nps and time; go wtime, go infinite with stop, and quit work; the pretty mode was driven in a real console, including the switch to UCI. 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:
1 parent
1754753a6e
commit
6490286852
6 files changed
+319
-17
No files matched your search
+10
-1
@@ -14,6 +14,7 @@
|
||||
#include "mcts.h"
|
||||
#include "perft.h"
|
||||
#include "position.h"
|
||||
#include "pretty.h"
|
||||
#include "uci_io.h"
|
||||
|
||||
namespace rigby {
|
||||
@@ -144,7 +145,7 @@ void go(Engine& e, std::istringstream& is) {
|
||||
e.searcher.stop_flag = false;
|
||||
e.worker = std::thread([&e, pos = e.pos, history = e.history, limits] {
|
||||
const SearchResult result = e.searcher.search(pos, history, limits, true);
|
||||
send("bestmove " + result.best.to_uci());
|
||||
send(e.searcher.pretty ? pretty::bestmove(result.best.to_uci()) : "bestmove " + result.best.to_uci());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -198,6 +199,10 @@ void uci_loop() {
|
||||
auto engine = std::make_unique<Engine>();
|
||||
Engine& e = *engine;
|
||||
|
||||
// A human at a terminal gets coloured search output until "uci" arrives.
|
||||
e.searcher.pretty = pretty::init_terminal();
|
||||
if (e.searcher.pretty) send(pretty::banner(ENGINE_NAME, ENGINE_VERSION, ENGINE_AUTHOR));
|
||||
|
||||
std::string line;
|
||||
while (std::getline(std::cin, line)) {
|
||||
std::istringstream is(line);
|
||||
@@ -205,6 +210,10 @@ void uci_loop() {
|
||||
is >> cmd;
|
||||
|
||||
if (cmd == "uci") {
|
||||
if (e.searcher.pretty) {
|
||||
e.stop();
|
||||
e.searcher.pretty = false;
|
||||
}
|
||||
print_id();
|
||||
} else if (cmd == "isready") {
|
||||
send("readyok");
|
||||
|
||||
Reference in new issue
Block a user