Datagen #46

Merged
rektdie merged 27 commits from datagen into main 2025-04-03 03:54:14 +02:00
Showing only changes of commit 114ef9728a - Show all commits
+14 -5
View File
@@ -142,7 +142,7 @@ static void WriteToFile(const Game &game, const std::string &filename) {
uint32_t zero = 0;
std::memcpy(buffer.data() + offset, &zero, sizeof(zero));
std::ofstream file(filename, std::ios::binary | std::ios::out | std::ios::trunc);
std::ofstream file(filename, std::ios::binary | std::ios::out | std::ios::app);
if (!file) throw std::runtime_error("Failed to open file for writing");
file.write(buffer.data(), buffer.size());
@@ -234,8 +234,9 @@ void Run(int targetPositions, int threads) {
int positions = 0;
int lastPrintedPosition = 0;
double lastPrintedTime = stopwatch.GetElapsedSec();
while (positions < targetPositions * 1000000) {
while (positions < targetPositions * 1000) {
Game game;
Board board;
@@ -262,8 +263,11 @@ void Run(int targetPositions, int threads) {
board.MakeMove(results.bestMove);
MOVEGEN::GenerateMoves<All>(board);
// Increment positions, but do not exceed target
if (positions < targetPositions * 1000) {
positions++;
}
}
if (std::abs(safeResults.score) >= std::abs(SEARCH::MATE_SCORE) - SEARCH::MAX_PLY) {
wdl = board.sideToMove ? 2 : 0;
@@ -272,16 +276,21 @@ void Run(int targetPositions, int threads) {
game.format.packFrom(board, staticEval, wdl);
WriteToFile(game, "data.binpack");
if (positions / 100 > lastPrintedPosition) {
lastPrintedPosition = positions / 1000;
PrintProgress(positions, targetPositions * 1000000, stopwatch, threads);
// Print progress every second
double currentTime = stopwatch.GetElapsedSec();
if (currentTime - lastPrintedTime >= 1) {
lastPrintedTime = currentTime;
PrintProgress(positions, targetPositions * 1000, stopwatch, threads);
}
}
PrintProgress(positions, targetPositions * 1000, stopwatch, threads);
#ifdef _WIN32
ShowCursor();
#else
ShowCursorLinux();
#endif
}
}