From 6d6fababdb20fb0655dcac348538d8ba717d5618 Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 10 Mar 2025 10:13:35 +0100 Subject: [PATCH] printing PV and score | bench 4118297 --- source/move.h | 1 - source/search.cpp | 11 ++++++++++- source/search.h | 31 +++++++++++++++++++++++++++++++ source/uci.cpp | 3 ++- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/source/move.h b/source/move.h index b2c8b2a..703b69e 100644 --- a/source/move.h +++ b/source/move.h @@ -56,7 +56,6 @@ public: void PrintMove() { std::cout << squareCoords[MoveFrom()] << squareCoords[MoveTo()]; - std::cout << " (" << moveTypes[GetFlags()] << ")\n"; } operator uint16_t() { diff --git a/source/search.cpp b/source/search.cpp index 1dee32d..143cb1b 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -17,6 +17,8 @@ static inline bool doingNullMove = false; // [id][ply] static inline int killerMoves[2][64]; +inline PVLine pvLine; + static int ScoreMove(Board &board, Move &move) { const int attackerType = board.GetPieceType(move.MoveFrom()); const int targetType = board.GetPieceType(move.MoveTo()); @@ -145,6 +147,8 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { } } + pvLine.SetLength(ply); + // if NOT PV node then we try to hit the TTable if (beta - alpha == 1) { SearchResults entry = ReadEntry(board.hashKey, depth, alpha, beta); @@ -242,6 +246,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { nodeType = PV; alpha = score; results.bestMove = board.moveList[i]; + pvLine.SetMove(ply, board.moveList[i]); } } @@ -300,7 +305,11 @@ static SearchResults ID(Board &board, SearchParams params) { std::cout << "info "; std::cout << "depth " << depth; - std::cout << " nodes " << nodes << " nps " << int(nodes/elapsed) << std::endl; + std::cout << " score cp " << safeResults.score; + std::cout << " nodes " << nodes << " nps " << int(nodes/elapsed); + std::cout << " pv "; + pvLine.Print(0); + std::cout << std::endl; } return safeResults; diff --git a/source/search.h b/source/search.h index 395604e..3cdb3ec 100644 --- a/source/search.h +++ b/source/search.h @@ -1,6 +1,10 @@ #pragma once #include "board.h" #include "uci.h" +#include +#include "move.h" + +constexpr int maxDepth = 64; extern U64 nodes; extern bool benchStarted; @@ -25,6 +29,33 @@ public: } }; +class PVLine { +private: + int length[maxDepth] = {}; + Move table[maxDepth][maxDepth] = {}; +public: + void SetLength(int ply) { + length[ply] = ply; + } + + void SetMove(int ply, Move move) { + table[ply][ply] = move; + + for (int i = ply + 1; i < length[ply + 1]; i++) { + table[ply][i] = table[ply+1][i]; + } + + length[ply] = length[ply + 1]; + } + + void Print(int n) { + for (int i = 0; i < length[n]; i++) { + table[n][i].PrintMove(); + std::cout << ' '; + } + } +}; + SearchResults PVS(Board board, int depth, int alpha, int beta); void SearchPosition(Board &board, SearchParams params); void StopSearch(); diff --git a/source/uci.cpp b/source/uci.cpp index 9ca743f..5c5a9cb 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -207,7 +207,8 @@ void UCILoop(Board &board) { // parse UCI "ucinewgame" command if (input.find("ucinewgame") != std::string::npos) { - ParsePosition(board, "position startpos"); + board.SetByFen(StartingFen); + TTable.clear(); continue; }