changed raw ctx pointer to unique | bench 3415609

This commit is contained in:
rektdie committed 2025-06-06 06:18:57 +02:00
1 parent b1fd8e6021
commit dec219e4d7
3 files changed
+13 -12

No files matched your search

+3 -2
View File
@@ -1,6 +1,7 @@
#include <cstring> #include <cstring>
#include <string_view> #include <string_view>
#include <array> #include <array>
#include <memory>
#include "benchmark.h" #include "benchmark.h"
#include "search.h" #include "search.h"
#include "stopwatch.h" #include "stopwatch.h"
@@ -64,12 +65,12 @@ void RunBenchmark() {
Board board; Board board;
int depth = BENCH_DEPTH; int depth = BENCH_DEPTH;
SEARCH::SearchContext *ctx = new SearchContext(); auto ctx = std::make_unique<SearchContext>();
Stopwatch sw; Stopwatch sw;
for (int i = 0; i < fenPositions.size(); i++) { for (int i = 0; i < fenPositions.size(); i++) {
board.SetByFen(fenPositions[i]); board.SetByFen(fenPositions[i]);
SearchPosition<bench>(board, SearchParams(), ctx); SearchPosition<bench>(board, SearchParams(), ctx.get());
} }
std::cout << ctx->nodes << " nodes " << int(ctx->nodes/sw.GetElapsedSec()) << " nps" << std::endl; std::cout << ctx->nodes << " nodes " << int(ctx->nodes/sw.GetElapsedSec()) << " nps" << std::endl;
+6 -6
View File
@@ -130,9 +130,9 @@ static void PlayGames(int id, std::atomic<int>& positions, std::atomic<bool>& st
while (!stopFlag) { while (!stopFlag) {
Game game; Game game;
Board board; Board board;
SEARCH::SearchContext *ctx = new SEARCH::SearchContext(); auto ctx = std::make_unique<SEARCH::SearchContext>();
PlayRandMoves(board, ctx); PlayRandMoves(board, ctx.get());
if (IsGameOver(board, ctx)) continue; if (IsGameOver(board, ctx.get())) continue;
Board startpos = board; Board startpos = board;
@@ -141,8 +141,8 @@ static void PlayGames(int id, std::atomic<int>& positions, std::atomic<bool>& st
int staticEval = UTILS::ConvertToWhiteRelative(board, NNUE::net.Evaluate(board)); int staticEval = UTILS::ConvertToWhiteRelative(board, NNUE::net.Evaluate(board));
int wdl = 1; int wdl = 1;
while (!IsGameOver(board, ctx)) { while (!IsGameOver(board, ctx.get())) {
SearchResults results = SEARCH::SearchPosition<SEARCH::datagen>(board, SearchParams(), ctx); SearchResults results = SEARCH::SearchPosition<SEARCH::datagen>(board, SearchParams(), ctx.get());
if (!results.bestMove) break; if (!results.bestMove) break;
safeResults = results; safeResults = results;
@@ -158,7 +158,7 @@ static void PlayGames(int id, std::atomic<int>& positions, std::atomic<bool>& st
MOVEGEN::GenerateMoves<All>(board); MOVEGEN::GenerateMoves<All>(board);
} }
if (!SEARCH::IsDraw(board, ctx)) { if (!SEARCH::IsDraw(board, ctx.get())) {
wdl = board.sideToMove ? 2 : 0; wdl = board.sideToMove ? 2 : 0;
} }
+4 -4
View File
@@ -111,7 +111,7 @@ static void PrintEngineInfo() {
void UCILoop(Board &board) { void UCILoop(Board &board) {
std::string input = ""; std::string input = "";
SEARCH::SearchContext *ctx = new SEARCH::SearchContext(); auto ctx = std::make_unique<SEARCH::SearchContext>();
// main loop // main loop
while (true) { while (true) {
@@ -125,7 +125,7 @@ void UCILoop(Board &board) {
// parse UCI "position" command // parse UCI "position" command
if (input.find("position") != std::string::npos) { if (input.find("position") != std::string::npos) {
ParsePosition(board, input, ctx); ParsePosition(board, input, ctx.get());
continue; continue;
} }
@@ -146,7 +146,7 @@ void UCILoop(Board &board) {
// parse UCI "go" command // parse UCI "go" command
if (input.find("go") != std::string::npos) { if (input.find("go") != std::string::npos) {
ParseGo(board, input, ctx); ParseGo(board, input, ctx.get());
continue; continue;
} }
@@ -171,7 +171,7 @@ void UCILoop(Board &board) {
} }
if (input.find("setoption") != std::string::npos) { if (input.find("setoption") != std::string::npos) {
SetOption(input, ctx); SetOption(input, ctx.get());
continue; continue;
} }