datagen could get in an inf loop if random moves resulted in game over
This commit is contained in:
1 parent
55b73dc85d
commit
c6eb3f464b
3 files changed
+43
-28
No files matched your search
+24
-21
@@ -42,24 +42,6 @@ static void ShowCursorLinux() {
|
|||||||
|
|
||||||
namespace DATAGEN {
|
namespace DATAGEN {
|
||||||
|
|
||||||
static void PlayRandMoves(Board &board, SEARCH::SearchContext& ctx) {
|
|
||||||
std::random_device dev;
|
|
||||||
std::mt19937 rng(dev());
|
|
||||||
|
|
||||||
for (int count = 0; count < RAND_MOVES; count++) {
|
|
||||||
MOVEGEN::GenerateMoves<All>(board);
|
|
||||||
std::uniform_int_distribution<std::mt19937::result_type> dist(0, board.currentMoveIndex - 1);
|
|
||||||
|
|
||||||
bool isLegal = board.MakeMove(board.moveList[dist(rng)]);
|
|
||||||
|
|
||||||
|
|
||||||
if (!isLegal) count--;
|
|
||||||
ctx.positionHistory[board.positionIndex] = board.hashKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOVEGEN::GenerateMoves<All>(board);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -70,10 +52,30 @@ static bool IsGameOver(Board &board, SEARCH::SearchContext& ctx) {
|
|||||||
bool isLegal = copy.MakeMove(board.moveList[i]);
|
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
|
|
||||||
if (!isLegal) continue;
|
if (!isLegal) continue;
|
||||||
moveSeen++; }
|
moveSeen++;
|
||||||
|
}
|
||||||
|
|
||||||
if (moveSeen == 0) return true;
|
return moveSeen == 0;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
static void PlayRandMoves(Board &board, SEARCH::SearchContext& ctx) {
|
||||||
|
std::random_device dev;
|
||||||
|
std::mt19937_64 rng(dev());
|
||||||
|
|
||||||
|
for (int count = 0; count < RAND_MOVES; count++) {
|
||||||
|
MOVEGEN::GenerateMoves<All>(board);
|
||||||
|
std::uniform_int_distribution<int> dist(0, board.currentMoveIndex - 1);
|
||||||
|
|
||||||
|
bool isLegal = board.MakeMove(board.moveList[dist(rng)]);
|
||||||
|
|
||||||
|
if (!isLegal) {
|
||||||
|
count--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ctx.positionHistory[board.positionIndex] = board.hashKey;
|
||||||
|
MOVEGEN::GenerateMoves<All>(board);
|
||||||
|
if (IsGameOver(board, ctx)) break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteToFile(std::vector<Game> &gamesBuffer, std::ofstream &file) {
|
static void WriteToFile(std::vector<Game> &gamesBuffer, std::ofstream &file) {
|
||||||
@@ -104,6 +106,7 @@ static void PlayGames(int id, std::atomic<int>& positions, std::atomic<bool>& st
|
|||||||
Board board;
|
Board board;
|
||||||
SEARCH::SearchContext ctx;
|
SEARCH::SearchContext ctx;
|
||||||
PlayRandMoves(board, ctx);
|
PlayRandMoves(board, ctx);
|
||||||
|
if (IsGameOver(board, ctx)) continue;
|
||||||
|
|
||||||
SearchResults safeResults;
|
SearchResults safeResults;
|
||||||
|
|
||||||
|
|||||||
+12
-7
@@ -138,11 +138,16 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if constexpr (mode == nodesMode) {
|
||||||
if (ctx.nodes > ctx.nodesToGo) {
|
if (ctx.nodes > ctx.nodesToGo) {
|
||||||
ctx.searchStopped = true;
|
ctx.searchStopped = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
} else if constexpr (mode == datagen) {
|
||||||
|
if (ctx.nodes > DATAGEN::HARD_NODES) {
|
||||||
|
ctx.searchStopped = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int bestScore = HCE::Evaluate(board);
|
int bestScore = HCE::Evaluate(board);
|
||||||
@@ -194,18 +199,13 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
|
|||||||
|
|
||||||
template <bool isPV, searchMode mode>
|
template <bool isPV, searchMode mode>
|
||||||
SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchContext& ctx) {
|
SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchContext& ctx) {
|
||||||
if constexpr (mode != bench || mode != nodesMode) {
|
if constexpr (mode != bench && mode != nodesMode) {
|
||||||
if (ctx.nodes % 1024 == 0) {
|
if (ctx.nodes % 1024 == 0) {
|
||||||
if constexpr (mode == normal) {
|
if constexpr (mode == normal) {
|
||||||
if (ctx.sw.GetElapsedMS() >= ctx.timeToSearch) {
|
if (ctx.sw.GetElapsedMS() >= ctx.timeToSearch) {
|
||||||
ctx.searchStopped = true;
|
ctx.searchStopped = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if constexpr (mode == datagen) {
|
|
||||||
if (ctx.nodes >= DATAGEN::HARD_NODES) {
|
|
||||||
ctx.searchStopped = true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if constexpr (mode == nodesMode) {
|
} else if constexpr (mode == nodesMode) {
|
||||||
@@ -213,6 +213,11 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
ctx.searchStopped = true;
|
ctx.searchStopped = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
} else if constexpr (mode == datagen) {
|
||||||
|
if (ctx.nodes > DATAGEN::HARD_NODES) {
|
||||||
|
ctx.searchStopped = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.pvLine.SetLength(ply);
|
ctx.pvLine.SetLength(ply);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
#include "perft.h"
|
#include "perft.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "datagen.h"
|
||||||
|
|
||||||
static void ParsePosition(Board &board, std::string_view command, SEARCH::SearchContext& ctx) {
|
static void ParsePosition(Board &board, std::string_view command, SEARCH::SearchContext& ctx) {
|
||||||
if (command.find("startpos") != std::string::npos) {
|
if (command.find("startpos") != std::string::npos) {
|
||||||
@@ -197,6 +198,12 @@ void UCILoop(Board &board) {
|
|||||||
|
|
||||||
if (input.find("nnue") != std::string::npos) {
|
if (input.find("nnue") != std::string::npos) {
|
||||||
board.PrintNNUE();
|
board.PrintNNUE();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.find("datagen") != std::string::npos) {
|
||||||
|
DATAGEN::Run(500000*2, 22);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user