From d73ed3b98d9669cd23e27c2e140839ed6fd90c01 Mon Sep 17 00:00:00 2001 From: rektdie Date: Tue, 6 May 2025 19:41:42 +0200 Subject: [PATCH] went back to hardware random moves | bench 1136338 --- source/datagen.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/source/datagen.cpp b/source/datagen.cpp index d04385b..a95f013 100644 --- a/source/datagen.cpp +++ b/source/datagen.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "datagen.h" #include "movegen.h" #include "evaluate.h" @@ -43,6 +44,8 @@ static void ShowCursorLinux() { namespace DATAGEN { +static std::mutex fileOpenMutex; + static bool IsGameOver(Board &board, SEARCH::SearchContext& ctx) { if (SEARCH::IsDraw(board, ctx)) return true; @@ -60,12 +63,17 @@ static bool IsGameOver(Board &board, SEARCH::SearchContext& ctx) { } static void PlayRandMoves(Board &board, SEARCH::SearchContext& ctx) { - bool plusOne = UTILS::RandomBool(); + std::random_device dev; + std::mt19937_64 rng(dev()); + + std::uniform_int_distribution moveDist(0, 1); + bool plusOne = moveDist(rng); for (int count = 0; count < RAND_MOVES + plusOne; count++) { MOVEGEN::GenerateMoves(board); - bool isLegal = board.MakeMove(board.moveList[UTILS::RandomInt(0, board.currentMoveIndex - 1)]); + std::uniform_int_distribution dist(0, board.currentMoveIndex - 1); + bool isLegal = board.MakeMove(board.moveList[dist(rng)]); if (!isLegal) { count--; @@ -93,8 +101,12 @@ static void PlayGames(int id, std::atomic& positions, std::atomic& st std::string fileName = "thread" + std::to_string(id) + ".binpack"; - - std::ofstream file(fileName, std::ios::app | std::ios::binary); + std::ofstream file; + { + std::lock_guard lock(fileOpenMutex); + file.open(fileName, std::ios::app | std::ios::binary); + } + if (!file.is_open()) { std::cerr << "Failed to open file: " << fileName << std::endl; exit(-1);