feat: minimal MCTS engine with UCI

Bitboard board with fancy magics and fully legal move generation, checked
by a perft suite. PUCT search over a node arena with FPU reduction and
in-tree draw detection. Hand-written value (eval + quiescence) and
heuristic policy stand in until the network is trained. UCI loop with a
search thread, OpenBench-compatible bench and Makefile.

Bench: 546127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rektdieandclaude committed 2026-11-15 00:31:20 +01:00
commit d3044c0b88
19 files changed
+1997

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
#pragma once
#include <string>
#include <string_view>
#include "bitboard.h"
#include "types.h"
namespace rigby {
namespace zobrist {
void init();
}
// Plain copy-make position. Small enough to copy at every tree step.
struct Position {
u64 pieces[6] = {};
u64 colors[2] = {};
u8 board[64];
int stm = WHITE;
int castling = 0;
int ep = NO_SQUARE; // only set when a capture there is pseudo-legal
int halfmove = 0;
int fullmove = 1;
u64 key = 0;
Position();
bool set_fen(std::string_view fen);
std::string fen() const;
void make_move(Move m);
u64 occupancy() const { return colors[WHITE] | colors[BLACK]; }
u64 pieces_of(int color, int type) const { return pieces[type] & colors[color]; }
int king_square(int color) const { return lsb(pieces_of(color, KING)); }
int piece_on(int sq) const { return board[sq]; }
u64 attackers_to(int sq, u64 occ) const;
bool square_attacked(int sq, int by, u64 occ) const;
u64 checkers() const { return attackers_to(king_square(stm), occupancy()) & colors[stm ^ 1]; }
bool in_check() const { return checkers() != 0; }
bool insufficient_material() const;
// Returns a null move when the string is not a legal move here.
Move parse_uci(std::string_view uci) const;
std::string pretty() const;
private:
void put_piece(int piece, int sq);
void remove_piece(int sq);
void move_piece(int from, int to);
};
void generate_legal(const Position& pos, MoveList& list);
} // namespace rigby