printing PV and score | bench 4118297

This commit is contained in:
rektdie committed 2025-03-10 10:13:35 +01:00
1 parent 674e769783
commit 6d6fababdb
4 files changed
+43 -3

No files matched your search

-1
View File
@@ -56,7 +56,6 @@ public:
void PrintMove() { void PrintMove() {
std::cout << squareCoords[MoveFrom()] << squareCoords[MoveTo()]; std::cout << squareCoords[MoveFrom()] << squareCoords[MoveTo()];
std::cout << " (" << moveTypes[GetFlags()] << ")\n";
} }
operator uint16_t() { operator uint16_t() {
+10 -1
View File
@@ -17,6 +17,8 @@ static inline bool doingNullMove = false;
// [id][ply] // [id][ply]
static inline int killerMoves[2][64]; static inline int killerMoves[2][64];
inline PVLine pvLine;
static int ScoreMove(Board &board, Move &move) { static int ScoreMove(Board &board, Move &move) {
const int attackerType = board.GetPieceType(move.MoveFrom()); const int attackerType = board.GetPieceType(move.MoveFrom());
const int targetType = board.GetPieceType(move.MoveTo()); 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 NOT PV node then we try to hit the TTable
if (beta - alpha == 1) { if (beta - alpha == 1) {
SearchResults entry = ReadEntry(board.hashKey, depth, alpha, beta); SearchResults entry = ReadEntry(board.hashKey, depth, alpha, beta);
@@ -242,6 +246,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) {
nodeType = PV; nodeType = PV;
alpha = score; alpha = score;
results.bestMove = board.moveList[i]; 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 << "info ";
std::cout << "depth " << depth; 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; return safeResults;
+31
View File
@@ -1,6 +1,10 @@
#pragma once #pragma once
#include "board.h" #include "board.h"
#include "uci.h" #include "uci.h"
#include <vector>
#include "move.h"
constexpr int maxDepth = 64;
extern U64 nodes; extern U64 nodes;
extern bool benchStarted; 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); SearchResults PVS(Board board, int depth, int alpha, int beta);
void SearchPosition(Board &board, SearchParams params); void SearchPosition(Board &board, SearchParams params);
void StopSearch(); void StopSearch();
+2 -1
View File
@@ -207,7 +207,8 @@ void UCILoop(Board &board) {
// parse UCI "ucinewgame" command // parse UCI "ucinewgame" command
if (input.find("ucinewgame") != std::string::npos) { if (input.find("ucinewgame") != std::string::npos) {
ParsePosition(board, "position startpos"); board.SetByFen(StartingFen);
TTable.clear();
continue; continue;
} }