Datagen #46
No files matched your search
+45
-1
@@ -1,9 +1,14 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
#include <cstring>
|
||||||
#include "datagen.h"
|
#include "datagen.h"
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
|
#include "evaluate.h"
|
||||||
|
#include "search.h"
|
||||||
|
#include "movegen.h"
|
||||||
|
|
||||||
namespace DATAGEN {
|
namespace DATAGEN {
|
||||||
|
|
||||||
|
// TODO: Causes segment fault
|
||||||
static void PlayRandMoves(Board &board) {
|
static void PlayRandMoves(Board &board) {
|
||||||
std::random_device dev;
|
std::random_device dev;
|
||||||
std::mt19937 rng(dev());
|
std::mt19937 rng(dev());
|
||||||
@@ -17,7 +22,46 @@ static void PlayRandMoves(Board &board) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Run() {
|
static bool IsGameOver(Board &board) {
|
||||||
|
Board copy = board;
|
||||||
|
// Checkmate / stalemate
|
||||||
|
int moveCounter = 0;
|
||||||
|
for (int i = 0; board.currentMoveIndex; i++) {
|
||||||
|
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
|
if (!isLegal) continue;
|
||||||
|
positionIndex--;
|
||||||
|
moveCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moveCounter == 0) return true;
|
||||||
|
|
||||||
|
// Draws
|
||||||
|
return SEARCH::IsDraw(board);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Run(int games) {
|
||||||
|
for (int i = 0; i < games; i++) {
|
||||||
|
Board board;
|
||||||
|
MarlinFormat position;
|
||||||
|
uint8_t wdl = 1;
|
||||||
|
positionIndex = 0;
|
||||||
|
std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves));
|
||||||
|
SEARCH::history.Clear();
|
||||||
|
|
||||||
|
//PlayRandMoves(board);
|
||||||
|
|
||||||
|
SEARCH::SearchResults safeResults;
|
||||||
|
|
||||||
|
// TODO: Game loop
|
||||||
|
|
||||||
|
if (std::abs(safeResults.score) >= SEARCH::inf - SEARCH::MAX_DEPTH) {
|
||||||
|
wdl = board.sideToMove ? 2 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
position.packFrom(board, HCE::Evaluate(board), wdl);
|
||||||
|
board.PrintBoard();
|
||||||
|
std::cout << "Eval: " << position.eval << std::endl;
|
||||||
|
std::cout << "WDL: " << int(position.wdl) << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -50,5 +50,5 @@ struct Game {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void Run();
|
void Run(int games);
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
|
#include "datagen.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
MOVEGEN::initLeaperAttacks();
|
MOVEGEN::initLeaperAttacks();
|
||||||
@@ -16,6 +17,12 @@ int main(int argc, char* argv[]) {
|
|||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
if (std::string(argv[1]) == "bench") {
|
if (std::string(argv[1]) == "bench") {
|
||||||
RunBenchmark();
|
RunBenchmark();
|
||||||
|
} else if (std::string(argv[1]) == "datagen") {
|
||||||
|
int count = 1;
|
||||||
|
if (argc > 2) {
|
||||||
|
count = std::stoi(argv[2]);
|
||||||
|
}
|
||||||
|
DATAGEN::Run(count);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
UCILoop(board);
|
UCILoop(board);
|
||||||
|
|||||||
+11
-5
@@ -124,6 +124,10 @@ static bool IsInsuffMat(Board &board) {
|
|||||||
&& !(board.pieces[Pawn] | board.pieces[Queen] | board.pieces[Rook]));
|
&& !(board.pieces[Pawn] | board.pieces[Queen] | board.pieces[Rook]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsDraw(Board &board) {
|
||||||
|
return IsFifty || IsInsuffMat || IsThreefold;
|
||||||
|
}
|
||||||
|
|
||||||
static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) {
|
static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) {
|
||||||
int reduction = 0;
|
int reduction = 0;
|
||||||
|
|
||||||
@@ -445,7 +449,7 @@ static SearchResults ID(Board &board, SearchParams params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <searchMode mode>
|
template <searchMode mode>
|
||||||
void SearchPosition(Board &board, SearchParams params) {
|
SearchResults SearchPosition(Board &board, SearchParams params) {
|
||||||
searchStopped = false;
|
searchStopped = false;
|
||||||
if constexpr (mode != bench) {
|
if constexpr (mode != bench) {
|
||||||
nodes = 0;
|
nodes = 0;
|
||||||
@@ -454,11 +458,13 @@ void SearchPosition(Board &board, SearchParams params) {
|
|||||||
|
|
||||||
SearchResults results = ID<mode>(board, params);
|
SearchResults results = ID<mode>(board, params);
|
||||||
|
|
||||||
if constexpr (mode != normal) return;
|
if constexpr (mode != normal) return results;
|
||||||
|
|
||||||
std::cout << "bestmove ";
|
std::cout << "bestmove ";
|
||||||
results.bestMove.PrintMove();
|
results.bestMove.PrintMove();
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopSearch() {
|
void StopSearch() {
|
||||||
@@ -472,8 +478,8 @@ template SearchResults PVS<false, searchMode::normal>(Board, int, int, int, int)
|
|||||||
template SearchResults PVS<true, searchMode::datagen>(Board, int, int, int, int);
|
template SearchResults PVS<true, searchMode::datagen>(Board, int, int, int, int);
|
||||||
template SearchResults PVS<false, searchMode::datagen>(Board, int, int, int, int);
|
template SearchResults PVS<false, searchMode::datagen>(Board, int, int, int, int);
|
||||||
|
|
||||||
template void SearchPosition<normal>(Board &board, SearchParams params);
|
template SearchResults SearchPosition<normal>(Board &board, SearchParams params);
|
||||||
template void SearchPosition<bench>(Board &board, SearchParams params);
|
template SearchResults SearchPosition<bench>(Board &board, SearchParams params);
|
||||||
template void SearchPosition<datagen>(Board &board, SearchParams params);
|
template SearchResults SearchPosition<datagen>(Board &board, SearchParams params);
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-1
@@ -111,9 +111,11 @@ template <bool isPV, searchMode mode>
|
|||||||
SearchResults PVS(Board board, int depth, int alpha, int beta, int ply);
|
SearchResults PVS(Board board, int depth, int alpha, int beta, int ply);
|
||||||
|
|
||||||
template <searchMode mode>
|
template <searchMode mode>
|
||||||
void SearchPosition(Board &board, SearchParams params);
|
SearchResults SearchPosition(Board &board, SearchParams params);
|
||||||
void StopSearch();
|
void StopSearch();
|
||||||
|
|
||||||
|
bool IsDraw(Board &board);
|
||||||
|
|
||||||
constexpr int moveScoreTable[6][6] = {
|
constexpr int moveScoreTable[6][6] = {
|
||||||
105, 205, 305, 405, 505, 605,
|
105, 205, 305, 405, 505, 605,
|
||||||
104, 204, 304, 404, 504, 604,
|
104, 204, 304, 404, 504, 604,
|
||||||
|
|||||||
Reference in new issue
Block a user