From 5c6d75e9ef9b869a32ddf2403b62e8c79d2f1ee9 Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 6 Oct 2025 17:56:46 +0200 Subject: [PATCH] separated printings | bench 6238369 --- source/move.h | 19 ++++++++++++++++++ source/search.cpp | 49 ++++++++++++++++++++++++++++------------------- source/search.h | 12 ++++++++++++ source/uci.cpp | 1 + source/uci.h | 2 ++ 5 files changed, 63 insertions(+), 20 deletions(-) diff --git a/source/move.h b/source/move.h index 785a2b5..5d8ac1b 100644 --- a/source/move.h +++ b/source/move.h @@ -80,6 +80,25 @@ public: } } + std::string GetMoveString() { + std::string result = squareCoords[MoveFrom()]; + result += squareCoords[MoveTo()]; + + int flags = GetFlags(); + + if (flags == knightPromotion || flags == knightPromoCapture) { + result += 'n'; + } else if (flags == bishopPromotion || flags == bishopPromoCapture) { + result += 'b'; + } else if (flags == rookPromotion || flags == rookPromoCapture) { + result += 'r'; + } else if (flags == queenPromotion || flags == queenPromoCapture) { + result += 'q'; + } + + return result; + } + uint16_t ConvertToViriMoveFormat() { uint16_t viriMove = 0; int flags = GetFlags(); diff --git a/source/search.cpp b/source/search.cpp index 1ca6741..d4cb1e9 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -6,6 +6,7 @@ #include "benchmark.h" #include "types.h" #include "tunables.h" +#include namespace SEARCH { @@ -819,26 +820,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext* ctx) { } if constexpr (mode == normal || mode == nodesMode) { - std::cout << "info "; - std::cout << "depth " << depth; - std::cout << " seldepth " << ctx->seldepth; - std::cout << " time " << elapsed; - std::cout << " score "; - - if (std::abs(safeResults.score) + MAX_PLY >= MATE_SCORE) { - int mateIn = (MATE_SCORE - (std::abs(safeResults.score) - 1)) / 2; - mateIn = safeResults.score < 0 ? mateIn * -1 : mateIn; - - std::cout << "mate " << mateIn; - } else { - std::cout << "cp " << safeResults.score; - } - - std::cout << " nodes " << ctx->nodes << " nps " << int(ctx->nodes/ctx->sw.GetElapsedSec()); - std::cout << " hashfull " << ctx->TT.GetUsedPercentage(); - std::cout << " pv "; - ctx->pvLine.Print(0); - std::cout << std::endl; + PrintSearchInfo(ctx, safeResults, depth, elapsed); if constexpr (mode == normal) { if (ctx->sw.GetElapsedMS() >= softTime) { @@ -905,6 +887,33 @@ int MoveEstimatedValue(Board& board, Move& move) { return value; } +void PrintSearchInfo(SearchContext* ctx, SearchResults& results, int depth, int elapsed) { + if (UCIEnabled) { + std::cout << "info "; + std::cout << "depth " << depth; + std::cout << " seldepth " << ctx->seldepth; + std::cout << " time " << elapsed; + std::cout << " score "; + + if (std::abs(results.score) + MAX_PLY >= MATE_SCORE) { + int mateIn = (MATE_SCORE - (std::abs(results.score) - 1)) / 2; + mateIn = results.score < 0 ? mateIn * -1 : mateIn; + + std::cout << "mate " << mateIn; + } else { + std::cout << "cp " << results.score; + } + + std::cout << " nodes " << ctx->nodes << " nps " << int(ctx->nodes/ctx->sw.GetElapsedSec()); + std::cout << " hashfull " << ctx->TT.GetUsedPercentage(); + std::cout << " pv "; + ctx->pvLine.Print(0); + std::cout << std::endl; + } else { + // TODO + } +} + template SearchResults PVS(Board&, int, int, int, int, SearchContext* ctx, bool cutnode); template SearchResults PVS(Board&, int, int, int, int, SearchContext* ctx, bool cutnode); template SearchResults PVS(Board&, int, int, int, int, SearchContext* ctx, bool cutnode); diff --git a/source/search.h b/source/search.h index 0116cdc..f9867d0 100644 --- a/source/search.h +++ b/source/search.h @@ -148,6 +148,16 @@ public: } } + std::string GetLine(int n) { + std::string result = ""; + for (int i = 0; i < length[n]; i++) { + result += table[n][i].GetMoveString(); + result += ' '; + } + + return result; + } + void Clear() { length[MAX_DEPTH - 1] = {}; table[MAX_DEPTH - 1][MAX_DEPTH - 1] = {}; @@ -218,5 +228,7 @@ bool IsDraw(Board &board, SearchContext* ctx); void ListScores(Board &board, SearchContext* ctx); +void PrintSearchInfo(SearchContext* ctx, SearchResults& results, int depth, int elapsed); + int MoveEstimatedValue(Board& board, Move& move); } diff --git a/source/uci.cpp b/source/uci.cpp index b624a30..36a47f0 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -278,6 +278,7 @@ void UCILoop(Board &board) { // parse UCI "uci" command if (input.find("uci") != std::string::npos) { + UCIEnabled = true; // print engine info PrintEngineInfo(); continue; diff --git a/source/uci.h b/source/uci.h index 1f2553d..48cebb5 100644 --- a/source/uci.h +++ b/source/uci.h @@ -2,6 +2,8 @@ #include "move.h" #include "board.h" +inline bool UCIEnabled = false; + class SearchParams { public: int wtime = 0;