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