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; uint32_t zero = 0;
std::memcpy(buffer.data() + offset, &zero, sizeof(zero)); 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"); if (!file) throw std::runtime_error("Failed to open file for writing");
file.write(buffer.data(), buffer.size()); file.write(buffer.data(), buffer.size());
@@ -234,8 +234,9 @@ void Run(int targetPositions, int threads) {
int positions = 0; int positions = 0;
int lastPrintedPosition = 0; int lastPrintedPosition = 0;
double lastPrintedTime = stopwatch.GetElapsedSec();
while (positions < targetPositions * 1000000) { while (positions < targetPositions * 1000) {
Game game; Game game;
Board board; Board board;
@@ -262,8 +263,11 @@ void Run(int targetPositions, int threads) {
board.MakeMove(results.bestMove); board.MakeMove(results.bestMove);
MOVEGEN::GenerateMoves<All>(board); MOVEGEN::GenerateMoves<All>(board);
// Increment positions, but do not exceed target
if (positions < targetPositions * 1000) {
positions++; positions++;
} }
}
if (std::abs(safeResults.score) >= std::abs(SEARCH::MATE_SCORE) - SEARCH::MAX_PLY) { if (std::abs(safeResults.score) >= std::abs(SEARCH::MATE_SCORE) - SEARCH::MAX_PLY) {
wdl = board.sideToMove ? 2 : 0; wdl = board.sideToMove ? 2 : 0;
@@ -272,16 +276,21 @@ void Run(int targetPositions, int threads) {
game.format.packFrom(board, staticEval, wdl); game.format.packFrom(board, staticEval, wdl);
WriteToFile(game, "data.binpack"); WriteToFile(game, "data.binpack");
if (positions / 100 > lastPrintedPosition) { // Print progress every second
lastPrintedPosition = positions / 1000; double currentTime = stopwatch.GetElapsedSec();
PrintProgress(positions, targetPositions * 1000000, stopwatch, threads); if (currentTime - lastPrintedTime >= 1) {
lastPrintedTime = currentTime;
PrintProgress(positions, targetPositions * 1000, stopwatch, threads);
} }
} }
PrintProgress(positions, targetPositions * 1000, stopwatch, threads);
#ifdef _WIN32 #ifdef _WIN32
ShowCursor(); ShowCursor();
#else #else
ShowCursorLinux(); ShowCursorLinux();
#endif #endif
} }
} }