From e1a0f6f1b49eceb5fcbc64da944820b07f8e9b0d Mon Sep 17 00:00:00 2001 From: PGG106 Date: Mon, 16 Jan 2023 22:23:00 +0100 Subject: [PATCH 1/3] fix go perft command, fix unknown command detection --- src/misc.cpp | 12 ++++++------ src/uci.cpp | 21 +++++++++++---------- src/uci.h | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index d44a4436..76847df3 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -76,12 +76,12 @@ void PrintUciOutput(const int score, const int depth, const S_ThreadData* td, co std::cout << std::setw(3) << depth << "/"; - std::cout << std::left << std::setw(3) << td->info.seldepth << " "; - std::cout << std::setw(4) << std::setprecision(3) << parsed_time; - std::cout << std::setw(2) << time_unit << " "; - std::cout << std::right << std::setw(5) << nodes / 1000 << "kn" << " "; - if (is_mate) std::cout << std::setw(2) << " M" << std::left << std::setw(3) << parsed_score << " "; - else std::cout << std::setw(5) << parsed_score << " "; + std::cout << std::left << std::setw(3) << td->info.seldepth; + std::cout << std::right << std::setw(4) << std::setprecision(3) << parsed_time; + std::cout << std::left << std::setw(2) << time_unit; + std::cout << std::right << std::setw(5) << nodes / 1000 << "kn "; + if (is_mate) std::cout << std::setw(1) << "M" << std::left << std::setw(3) << parsed_score; + else std::cout << std::setw(5) << parsed_score; std::cout << std::right << std::setw(5) << nps / 1000 << "kn/s" << " "; // loop over the moves within a PV line diff --git a/src/uci.cpp b/src/uci.cpp index ebc7a36e..862d31b3 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -125,8 +125,8 @@ void parse_position(const std::string& command, S_Board* pos) { go depth 64 */ -// parse UCI "go" command -void parse_go(const std::string& line, S_SearchINFO* info, S_Board* pos) { +// parse UCI "go" command, returns true if we have to search afterwards and false otherwise +bool parse_go(const std::string& line, S_SearchINFO* info, S_Board* pos) { Reset_info(info); int depth = -1, movetime = -1; int movestogo; @@ -142,9 +142,9 @@ void parse_go(const std::string& line, S_SearchINFO* info, S_Board* pos) { } if (tokens.at(1) == "perft") { - int perft_depth = std::stoi(tokens[1]); + int perft_depth = std::stoi(tokens[2]); perft_test(perft_depth, pos); - return; + return false; } if (tokens.at(i) == "binc" && pos->side == BLACK) { @@ -203,7 +203,7 @@ void parse_go(const std::string& line, S_SearchINFO* info, S_Board* pos) { std::cout << "depth: " << info->depth << " "; std::cout << "timeset: " << info->timeset << " "; std::cout << "nodeset: " << info->nodeset << "\n"; - + return true; } // main UCI loop @@ -261,12 +261,12 @@ void Uci_Loop(char** argv) { parse_position("position startpos", &td->pos); } // call parse go function - parse_go(input, &td->info, &td->pos); + bool search = parse_go(input, &td->info, &td->pos); // Start search in a separate thread - main_search_thread = std::thread(Root_search_position, td->info.depth, td, uci_options); + if (search) main_search_thread = std::thread(Root_search_position, td->info.depth, td, uci_options); } - if (tokens[0] == "setoption") { + else if (tokens[0] == "setoption") { if (tokens[2] == "Hash") { uci_options->Hash = std::stoi(tokens[4]); @@ -280,7 +280,7 @@ void Uci_Loop(char** argv) { } // parse UCI "isready" command - if (input == "isready") { + else if (input == "isready") { std::cout << "readyok\n"; continue; @@ -359,6 +359,7 @@ void Uci_Loop(char** argv) { } } } - } else std::cout << "Unknown command: " << input << std::endl; + } + else std::cout << "Unknown command: " << input << std::endl; } } diff --git a/src/uci.h b/src/uci.h index b4710406..9fc6fbdb 100644 --- a/src/uci.h +++ b/src/uci.h @@ -14,7 +14,7 @@ int parse_move(const std::string& move_string, S_Board* pos); void parse_position(const std::string& command, S_Board* pos); // parse UCI "go" command -void parse_go(const std::string& line, S_SearchINFO* info, S_Board* pos); +bool parse_go(const std::string& line, S_SearchINFO* info, S_Board* pos); // main UCI loop void Uci_Loop(char** argv); \ No newline at end of file From 455d7d8f8bdde5c21af3cf8d037bddbeced3b3e7 Mon Sep 17 00:00:00 2001 From: PGG106 Date: Tue, 17 Jan 2023 00:17:48 +0100 Subject: [PATCH 2/3] final nice output printing tweak Bench: 5092158 --- src/misc.cpp | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 76847df3..b2033aa1 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -57,32 +57,48 @@ void PrintUciOutput(const int score, const int depth, const S_ThreadData* td, co //Convert time in seconds if possible std::string time_unit = "ms"; float parsed_time = time; - if (time >= 1000) { + if (parsed_time >= 1000) { parsed_time = parsed_time / 1000; time_unit = 's'; + if (parsed_time >= 60) + { + parsed_time = parsed_time / 60; + time_unit = 'm'; + } } + + // convert time to string + std::stringstream time_stream; + time_stream << std::setprecision(3) << parsed_time; + std::string time_string = time_stream.str() + time_unit; + //Convert score to a decimal format or to a mate string float parsed_score = 0; - bool is_mate = false; + std::string score_unit = ""; if (score > -mate_value && score < -mate_score) { - parsed_score = -(score + mate_value) / 2; - is_mate = true; + parsed_score = (score + mate_value) / 2; + score_unit = "-M"; } else if (score > mate_score && score < mate_value) { parsed_score = (mate_value - score) / 2 + 1; - is_mate = true; + score_unit = "+M"; } - else parsed_score = static_cast(score) / 100; - + else { + parsed_score = static_cast(score) / 100; + score_unit = parsed_score > 0 ? '+' : '-'; + } + // convert score to string + std::stringstream score_stream; + score_stream << std::fixed << std::setprecision(2) << parsed_score; + std::string score_string = score_unit + score_stream.str(); + //Pretty print search info std::cout << std::setw(3) << depth << "/"; std::cout << std::left << std::setw(3) << td->info.seldepth; - std::cout << std::right << std::setw(4) << std::setprecision(3) << parsed_time; - std::cout << std::left << std::setw(2) << time_unit; - std::cout << std::right << std::setw(5) << nodes / 1000 << "kn "; - if (is_mate) std::cout << std::setw(1) << "M" << std::left << std::setw(3) << parsed_score; - else std::cout << std::setw(5) << parsed_score; - std::cout << std::right << std::setw(5) << nps / 1000 << "kn/s" << " "; + std::cout << std::right << std::setw(8) << time_string; + std::cout << std::right << std::setw(10) << nodes / 1000 << "kn "; + std::cout << std::setw(8) << std::right << score_string; + std::cout << std::setw(8) << std::right << std::fixed << std::setprecision(0) << nps / 1000.0 << "kn/s" << " "; // loop over the moves within a PV line for (int count = 0; count < td->pv_table.pvLength[0]; count++) { From 369d9e40e216e9f2ca44a6d8ab035afbed20c63c Mon Sep 17 00:00:00 2001 From: PGG106 Date: Tue, 17 Jan 2023 00:28:52 +0100 Subject: [PATCH 3/3] fix negative mate score --- src/misc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index b2033aa1..c024c70e 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -60,7 +60,7 @@ void PrintUciOutput(const int score, const int depth, const S_ThreadData* td, co if (parsed_time >= 1000) { parsed_time = parsed_time / 1000; time_unit = 's'; - if (parsed_time >= 60) + if (parsed_time >= 60) { parsed_time = parsed_time / 60; time_unit = 'm'; @@ -76,7 +76,7 @@ void PrintUciOutput(const int score, const int depth, const S_ThreadData* td, co float parsed_score = 0; std::string score_unit = ""; if (score > -mate_value && score < -mate_score) { - parsed_score = (score + mate_value) / 2; + parsed_score = std::abs((score + mate_value) / 2); score_unit = "-M"; } else if (score > mate_score && score < mate_value) {