Pretty print #117

Merged
rektdie merged 2 commits from pretty-print into main 2025-10-07 13:32:00 +02:00
5 changed files with 63 additions and 20 deletions
Showing only changes of commit 5c6d75e9ef - Show all commits

No files matched your search

+19
View File
@@ -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 ConvertToViriMoveFormat() {
uint16_t viriMove = 0; uint16_t viriMove = 0;
int flags = GetFlags(); int flags = GetFlags();
+29 -20
View File
@@ -6,6 +6,7 @@
#include "benchmark.h" #include "benchmark.h"
#include "types.h" #include "types.h"
#include "tunables.h" #include "tunables.h"
#include <iomanip>
namespace SEARCH { namespace SEARCH {
@@ -819,26 +820,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext* ctx) {
} }
if constexpr (mode == normal || mode == nodesMode) { if constexpr (mode == normal || mode == nodesMode) {
std::cout << "info "; PrintSearchInfo(ctx, safeResults, depth, elapsed);
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;
if constexpr (mode == normal) { if constexpr (mode == normal) {
if (ctx->sw.GetElapsedMS() >= softTime) { if (ctx->sw.GetElapsedMS() >= softTime) {
@@ -905,6 +887,33 @@ int MoveEstimatedValue(Board& board, Move& move) {
return value; 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<true, searchMode::bench>(Board&, int, int, int, int, SearchContext* ctx, bool cutnode); template SearchResults PVS<true, searchMode::bench>(Board&, int, int, int, int, SearchContext* ctx, bool cutnode);
template SearchResults PVS<false, searchMode::bench>(Board&, int, int, int, int, SearchContext* ctx, bool cutnode); template SearchResults PVS<false, searchMode::bench>(Board&, int, int, int, int, SearchContext* ctx, bool cutnode);
template SearchResults PVS<true, searchMode::normal>(Board&, int, int, int, int, SearchContext* ctx, bool cutnode); template SearchResults PVS<true, searchMode::normal>(Board&, int, int, int, int, SearchContext* ctx, bool cutnode);
+12
View File
@@ -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() { void Clear() {
length[MAX_DEPTH - 1] = {}; length[MAX_DEPTH - 1] = {};
table[MAX_DEPTH - 1][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 ListScores(Board &board, SearchContext* ctx);
void PrintSearchInfo(SearchContext* ctx, SearchResults& results, int depth, int elapsed);
int MoveEstimatedValue(Board& board, Move& move); int MoveEstimatedValue(Board& board, Move& move);
} }
+1
View File
@@ -278,6 +278,7 @@ void UCILoop(Board &board) {
// parse UCI "uci" command // parse UCI "uci" command
if (input.find("uci") != std::string::npos) { if (input.find("uci") != std::string::npos) {
UCIEnabled = true;
// print engine info // print engine info
PrintEngineInfo(); PrintEngineInfo();
continue; continue;
+2
View File
@@ -2,6 +2,8 @@
#include "move.h" #include "move.h"
#include "board.h" #include "board.h"
inline bool UCIEnabled = false;
class SearchParams { class SearchParams {
public: public:
int wtime = 0; int wtime = 0;