went back to hardware random moves | bench 1136338
This commit is contained in:
1 parent
bd88504745
commit
d73ed3b98d
1 file changed
+16
-4
+16
-4
@@ -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 {
|
||||||
|
|
||||||
|
static std::mutex fileOpenMutex;
|
||||||
|
|
||||||
static bool IsGameOver(Board &board, SEARCH::SearchContext& ctx) {
|
static bool IsGameOver(Board &board, SEARCH::SearchContext& ctx) {
|
||||||
if (SEARCH::IsDraw(board, ctx)) return true;
|
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) {
|
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<int> moveDist(0, 1);
|
||||||
|
bool plusOne = moveDist(rng);
|
||||||
|
|
||||||
for (int count = 0; count < RAND_MOVES + plusOne; count++) {
|
for (int count = 0; count < RAND_MOVES + plusOne; count++) {
|
||||||
MOVEGEN::GenerateMoves<All>(board);
|
MOVEGEN::GenerateMoves<All>(board);
|
||||||
|
|
||||||
bool isLegal = board.MakeMove(board.moveList[UTILS::RandomInt(0, board.currentMoveIndex - 1)]);
|
std::uniform_int_distribution<int> dist(0, board.currentMoveIndex - 1);
|
||||||
|
bool isLegal = board.MakeMove(board.moveList[dist(rng)]);
|
||||||
|
|
||||||
if (!isLegal) {
|
if (!isLegal) {
|
||||||
count--;
|
count--;
|
||||||
@@ -93,8 +101,12 @@ static void PlayGames(int id, std::atomic<int>& positions, std::atomic<bool>& st
|
|||||||
|
|
||||||
std::string fileName = "thread" + std::to_string(id) + ".binpack";
|
std::string fileName = "thread" + std::to_string(id) + ".binpack";
|
||||||
|
|
||||||
|
std::ofstream file;
|
||||||
std::ofstream file(fileName, std::ios::app | std::ios::binary);
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(fileOpenMutex);
|
||||||
|
file.open(fileName, std::ios::app | std::ios::binary);
|
||||||
|
}
|
||||||
|
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
std::cerr << "Failed to open file: " << fileName << std::endl;
|
std::cerr << "Failed to open file: " << fileName << std::endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|||||||
Reference in new issue
Block a user