playing matches in datagen | bench 1857933

This commit is contained in:
rektdie committed 2025-04-01 20:15:44 +02:00
1 parent f4eeec2b4e
commit 649bee6490
4 files changed
+52 -43

No files matched your search

+36 -15
View File
@@ -19,16 +19,34 @@ static void PlayRandMoves(Board &board) {
bool isLegal = board.MakeMove(board.moveList[dist(rng)]); bool isLegal = board.MakeMove(board.moveList[dist(rng)]);
if (!isLegal) count--; if (!isLegal) count--;
} }
MOVEGEN::GenerateMoves<All>(board);
} }
static bool IsGameOver(Board &board) { static bool IsGameOver(Board &board) {
// TODO bool isDraw = SEARCH::IsDraw(board);
if (isDraw) return true;
int moveSeen = 0;
for (int i = 0; i < board.currentMoveIndex; i++) {
Board copy = board;
bool isLegal = copy.MakeMove(board.moveList[i]);
if (!isLegal) continue;
positionIndex--;
moveSeen++;
}
if (moveSeen == 0) return true;
return false;
} }
void Run(int games) { void Run(int games) {
for (int i = 0; i < games; i++) { for (int i = 0; i < games; i++) {
Game game;
Board board; Board board;
MarlinFormat position;
uint8_t wdl = 1; uint8_t wdl = 1;
positionIndex = 0; positionIndex = 0;
std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves)); std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves));
@@ -36,25 +54,28 @@ void Run(int games) {
PlayRandMoves(board); PlayRandMoves(board);
int staticEval = HCE::Evaluate(board);
SEARCH::SearchResults safeResults; SEARCH::SearchResults safeResults;
// while (!IsGameOver(board)) {
// SEARCH::SearchResults results = SEARCH::SearchPosition<SEARCH::datagen>(board, SearchParams());
// if (!results.bestMove) break; MOVEGEN::GenerateMoves<All>(board);
// safeResults = results;
// board.MakeMove(results.bestMove); while (!IsGameOver(board)) {
// } SEARCH::SearchResults results = SEARCH::SearchPosition<SEARCH::datagen>(board, SearchParams());
if (std::abs(safeResults.score) >= SEARCH::inf - SEARCH::MAX_DEPTH) { if (!results.bestMove) break;
safeResults = results;
game.moves.push_back(ScoredMove(results.bestMove, results.score));
board.MakeMove(results.bestMove);
MOVEGEN::GenerateMoves<All>(board);
}
if (std::abs(safeResults.score) >= std::abs(SEARCH::MATE_SCORE) - SEARCH::MAX_PLY) {
wdl = board.sideToMove ? 2 : 0; wdl = board.sideToMove ? 2 : 0;
} }
position.packFrom(board, HCE::Evaluate(board), wdl); game.format.packFrom(board, staticEval, wdl);
board.PrintBoard();
std::cout << "Eval: " << position.eval << std::endl;
std::cout << "WDL: " << int(position.wdl) << std::endl;
} }
} }
} }
+2
View File
@@ -44,6 +44,8 @@ struct Game {
MarlinFormat format; MarlinFormat format;
std::vector<ScoredMove> moves; std::vector<ScoredMove> moves;
Game(){};
Game(MarlinFormat f, std::vector<ScoredMove> m) { Game(MarlinFormat f, std::vector<ScoredMove> m) {
format = f; format = f;
moves = m; moves = m;
+3 -3
View File
@@ -323,6 +323,9 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
score = -PVS<isPV, mode>(copy, newDepth, -beta, -alpha, ply + 1).score; score = -PVS<isPV, mode>(copy, newDepth, -beta, -alpha, ply + 1).score;
} }
moveSeen++;
positionIndex--;
if (searchStopped) return 0; if (searchStopped) return 0;
if (currMove.IsQuiet()) { if (currMove.IsQuiet()) {
@@ -330,9 +333,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
seenQuietsCount++; seenQuietsCount++;
} }
moveSeen++;
positionIndex--;
// Fail high (beta cutoff) // Fail high (beta cutoff)
if (score >= beta) { if (score >= beta) {
if (!currMove.IsCapture()) { if (!currMove.IsCapture()) {
+11 -25
View File
@@ -148,11 +148,10 @@ Move parseMove(Board &board, std::string_view str) {
} }
std::array<uint8_t, 16> CompressPieces(Board &board) { std::array<uint8_t, 16> CompressPieces(Board &board) {
const uint8_t UNMOVED_ROOK = 0x10; // Special value for unmoved rooks const uint8_t UNMOVED_ROOK = 0x08; // We only have 4 bits, so we use bit 3 to mark unmoved rooks
std::array<uint8_t, 16> compressed{}; // Zero-initialize
std::array<uint8_t, 16> compressed; for (int square = 0; square < 64; square++) {
for (int square = a1; square <= h8; square++) {
int pieceCode = 0; int pieceCode = 0;
for (int pieceType = Pawn; pieceType <= King; pieceType++) { for (int pieceType = Pawn; pieceType <= King; pieceType++) {
@@ -160,38 +159,25 @@ std::array<uint8_t, 16> CompressPieces(Board &board) {
if (pieceBitboard.IsSet(square)) { if (pieceBitboard.IsSet(square)) {
if (board.colors[White] & board.pieces[pieceType]) { if (board.colors[White] & board.pieces[pieceType]) {
pieceCode = pieceType + 1; // White pieces: 1-6 pieceCode = pieceType; // White: 1-6
} else { } else {
pieceCode = pieceType + 7; // Black pieces: 7-12 pieceCode = pieceType + 6; // Black: 7-12
} }
// If it's a rook and hasn't moved (check castling rights) // Check for unmoved rook
if (pieceType == Rook) { if (pieceType == Rook) {
if (board.sideToMove == White) { if ((board.castlingRights & (whiteKingRight | whiteQueenRight | blackKingRight | blackQueenRight)) != 0) {
// If the white rooks are still eligible for castling, they haven't moved pieceCode |= UNMOVED_ROOK; // Mark as unmoved rook (bit 3 set)
if ((board.castlingRights & (whiteKingRight | whiteQueenRight)) != 0) {
pieceCode |= UNMOVED_ROOK; // Mark as unmoved rook
}
} else if (board.sideToMove == Black) {
// If the black rooks are still eligible for castling, they haven't moved
if ((board.castlingRights & (blackKingRight | blackQueenRight)) != 0) {
pieceCode |= UNMOVED_ROOK; // Mark as unmoved rook
}
} }
} }
break; break;
} }
} }
// Determine the byte index for storing the piece code (since we are packing 2 pieces per byte) int byteIndex = square / 4;
int byteIndex = square / 2; int shift = (square % 4) * 4;
// Pack the piece code into the byte array compressed[byteIndex] |= (pieceCode & 0x0F) << shift; // Pack 4-bit pieceCode
if (square % 2 == 0) {
compressed[byteIndex] = (compressed[byteIndex] & 0xF0) | (pieceCode & 0x0F);
} else {
compressed[byteIndex] = (compressed[byteIndex] & 0x0F) | ((pieceCode & 0x0F) << 4);
}
} }
return compressed; return compressed;