Datagen #46

Merged
rektdie merged 27 commits from datagen into main 2025-04-03 03:54:14 +02:00
Showing only changes of commit 5619ced265 - Show all commits
+8 -2
View File
@@ -4,6 +4,7 @@
#include <iomanip> #include <iomanip>
#include <thread> #include <thread>
#include <atomic> #include <atomic>
#include <mutex>
#include "datagen.h" #include "datagen.h"
#include "movegen.h" #include "movegen.h"
#include "evaluate.h" #include "evaluate.h"
@@ -43,6 +44,8 @@ static void ShowCursorLinux() {
namespace DATAGEN { namespace DATAGEN {
std::mutex mutex;
static void PlayRandMoves(Board &board) { static void PlayRandMoves(Board &board) {
std::random_device dev; std::random_device dev;
std::mt19937 rng(dev()); std::mt19937 rng(dev());
@@ -125,6 +128,7 @@ std::istream &operator>>(std::istream &is, Game &game) {
} }
static void WriteToFile(const Game &game, const std::string &filename) { static void WriteToFile(const Game &game, const std::string &filename) {
std::lock_guard<std::mutex> lock(mutex);
// Create a buffer to store the serialized data [prevents corruption] // Create a buffer to store the serialized data [prevents corruption]
std::vector<char> buffer; std::vector<char> buffer;
@@ -278,8 +282,10 @@ void Run(int targetPositions, int threads) {
std::atomic<int> positions = 0; std::atomic<int> positions = 0;
auto worker = std::thread(PlayGame, std::ref(positions), targetPositions * 1000); for (int i = 0; i < threads; i++) {
worker.detach(); auto worker = std::thread(PlayGame, std::ref(positions), targetPositions * 1000);
worker.detach();
}
int lastPrintedPosition = 0; int lastPrintedPosition = 0;
double lastPrintedTime = stopwatch.GetElapsedSec(); double lastPrintedTime = stopwatch.GetElapsedSec();