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>
58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <bit>
|
|
|
|
#include "types.h"
|
|
|
|
namespace rigby {
|
|
|
|
constexpr u64 bb(int sq) { return 1ULL << sq; }
|
|
inline int lsb(u64 b) { return std::countr_zero(b); }
|
|
inline int popcount(u64 b) { return std::popcount(b); }
|
|
inline int pop_lsb(u64& b) {
|
|
const int sq = lsb(b);
|
|
b &= b - 1;
|
|
return sq;
|
|
}
|
|
|
|
constexpr u64 FILE_A_BB = 0x0101010101010101ULL;
|
|
constexpr u64 FILE_H_BB = FILE_A_BB << 7;
|
|
constexpr u64 RANK_1_BB = 0xFFULL;
|
|
constexpr u64 RANK_8_BB = RANK_1_BB << 56;
|
|
|
|
constexpr u64 file_bb(int sq) { return FILE_A_BB << file_of(sq); }
|
|
constexpr u64 rank_bb(int sq) { return RANK_1_BB << (8 * rank_of(sq)); }
|
|
|
|
// Small, fast, deterministic generator (xorshift64*). Used for magics and Zobrist keys.
|
|
struct Prng {
|
|
u64 state;
|
|
explicit Prng(u64 seed) : state(seed ? seed : 0x9E3779B97F4A7C15ULL) {}
|
|
u64 next() {
|
|
state ^= state >> 12;
|
|
state ^= state << 25;
|
|
state ^= state >> 27;
|
|
return state * 2685821657736338717ULL;
|
|
}
|
|
u64 sparse() { return next() & next() & next(); }
|
|
};
|
|
|
|
namespace attacks {
|
|
|
|
void init();
|
|
|
|
extern u64 pawn[2][64];
|
|
extern u64 knight[64];
|
|
extern u64 king[64];
|
|
// Squares strictly between two aligned squares, 0 otherwise.
|
|
extern u64 between[64][64];
|
|
// The full line through two aligned squares (both included), 0 otherwise.
|
|
extern u64 line[64][64];
|
|
|
|
u64 bishop(int sq, u64 occ);
|
|
u64 rook(int sq, u64 occ);
|
|
inline u64 queen(int sq, u64 occ) { return bishop(sq, occ) | rook(sq, occ); }
|
|
|
|
} // namespace attacks
|
|
|
|
} // namespace rigby
|