separated playing games from run function

This commit is contained in:
rektdie committed 2025-04-03 03:15:45 +02:00
1 parent 34f5bbdd43
commit c0b76d81bb
5 files changed
+50 -41

No files matched your search

+2 -2
View File
@@ -9,8 +9,8 @@ constexpr int noEPTarget = -1;
constexpr int MAX_MOVES = 218; constexpr int MAX_MOVES = 218;
inline int positionIndex = 0; thread_local inline int positionIndex = 0;
inline U64 positionHistory[1000]; thread_local inline U64 positionHistory[1000];
class Board { class Board {
public: public:
+33 -24
View File
@@ -3,6 +3,7 @@
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <thread> #include <thread>
#include <atomic>
#include "datagen.h" #include "datagen.h"
#include "movegen.h" #include "movegen.h"
#include "evaluate.h" #include "evaluate.h"
@@ -220,23 +221,8 @@ void PrintProgress(int positions, int targetPositions, Stopwatch &stopwatch, int
std::cout << std::string(width, '-') << std::endl; std::cout << std::string(width, '-') << std::endl;
} }
void Run(int targetPositions, int threads) { void PlayGame(std::atomic<int>& positions, int targetPositions) {
#ifdef _WIN32 while (positions.load(std::memory_order_relaxed) < targetPositions) {
system("cls");
HideCursor();
#else
std::cout << "\033[2J\033[H";
HideCursorLinux();
#endif
Stopwatch stopwatch;
stopwatch.Restart();
int positions = 0;
int lastPrintedPosition = 0;
double lastPrintedTime = stopwatch.GetElapsedSec();
while (positions < targetPositions * 1000) {
Game game; Game game;
Board board; Board board;
@@ -264,18 +250,41 @@ void Run(int targetPositions, int threads) {
MOVEGEN::GenerateMoves<All>(board); MOVEGEN::GenerateMoves<All>(board);
// Increment positions, but do not exceed target // Increment positions, but do not exceed target
if (positions < targetPositions * 1000) { if (positions.load(std::memory_order_relaxed) < targetPositions) {
positions++; positions.fetch_add(1, std::memory_order_relaxed);
if (std::abs(safeResults.score) >= std::abs(SEARCH::MATE_SCORE) - SEARCH::MAX_PLY) {
wdl = board.sideToMove ? 2 : 0;
}
} }
} }
if (std::abs(safeResults.score) >= std::abs(SEARCH::MATE_SCORE) - SEARCH::MAX_PLY) {
wdl = board.sideToMove ? 2 : 0;
}
game.format.packFrom(board, staticEval, wdl); game.format.packFrom(board, staticEval, wdl);
WriteToFile(game, "data.binpack"); WriteToFile(game, "data.binpack");
}
}
void Run(int targetPositions, int threads) {
#ifdef _WIN32
system("cls");
HideCursor();
#else
std::cout << "\033[2J\033[H";
HideCursorLinux();
#endif
Stopwatch stopwatch;
std::atomic<int> positions = 0;
auto worker = std::thread(PlayGame, std::ref(positions), targetPositions * 1000);
worker.detach();
int lastPrintedPosition = 0;
double lastPrintedTime = stopwatch.GetElapsedSec();
while (positions.load(std::memory_order_relaxed) < targetPositions * 1000) {
// Print progress every second // Print progress every second
double currentTime = stopwatch.GetElapsedSec(); double currentTime = stopwatch.GetElapsedSec();
if (currentTime - lastPrintedTime >= 1) { if (currentTime - lastPrintedTime >= 1) {
+7 -7
View File
@@ -10,16 +10,16 @@
namespace SEARCH { namespace SEARCH {
U64 nodes = 0; thread_local U64 nodes = 0;
U64 nodesToGo = 0; thread_local U64 nodesToGo = 0;
bool benchStarted = false; thread_local bool benchStarted = false;
static inline int timeToSearch = 0; thread_local static inline int timeToSearch = 0;
static inline bool doingNullMove = false; thread_local static inline bool doingNullMove = false;
inline PVLine pvLine; thread_local inline PVLine pvLine;
Stopwatch sw; thread_local Stopwatch sw;
void InitLMRTable() { void InitLMRTable() {
for (int depth = 0; depth <= MAX_DEPTH; depth++) { for (int depth = 0; depth <= MAX_DEPTH; depth++) {
+6 -6
View File
@@ -19,15 +19,15 @@ constexpr int MAX_DEPTH = 64;
constexpr int MAX_PLY = 128; constexpr int MAX_PLY = 128;
constexpr int MAX_HISTORY = 16384; constexpr int MAX_HISTORY = 16384;
extern U64 nodes; thread_local extern U64 nodes;
extern bool benchStarted; thread_local extern bool benchStarted;
constexpr int inf = 100000; constexpr int inf = 100000;
inline bool searchStopped = false; thread_local inline bool searchStopped = false;
// [id][ply] // [id][ply]
inline int killerMoves[2][MAX_PLY]; thread_local inline int killerMoves[2][MAX_PLY];
inline int lmrTable[MAX_DEPTH+1][MAX_MOVES]; inline int lmrTable[MAX_DEPTH+1][MAX_MOVES];
@@ -75,7 +75,7 @@ public:
} }
}; };
inline History history; thread_local inline History history;
class PVLine { class PVLine {
private: private:
+2 -2
View File
@@ -21,7 +21,7 @@ constexpr U64 maxHash = (64* 1000000) / sizeof(TTEntry);
// 5 MB // 5 MB
constexpr U64 defaultHash = (5 * 1000000) / sizeof(TTEntry); constexpr U64 defaultHash = (5 * 1000000) / sizeof(TTEntry);
inline U64 hashSize = defaultHash; thread_local inline U64 hashSize = defaultHash;
constexpr int invalidEntry = 111111; constexpr int invalidEntry = 111111;
@@ -61,4 +61,4 @@ public:
void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove); void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove);
}; };
inline TTable TT; thread_local inline TTable TT;