Add perft testing

This commit is contained in:
2025-08-19 17:28:38 -04:00
parent 15b1a03928
commit 8cecd705a0
3 changed files with 55 additions and 0 deletions

View File

@@ -785,6 +785,26 @@ int get_legal_moves(struct Board *board, struct Move *out) {
return count;
}
uint64_t perft(struct Board *board, int depth) {
if (depth == 0) return 1;
struct Move moves[256];
int n = get_legal_moves(board, moves);
if (depth == 1) return (uint64_t) n;
uint64_t nodes = 0;
for (int i = 0; i < n; ++i) {
struct Board after;
if (!apply_move_on_copy(board, &after, moves[i])) {
// Shouldn't happen with legal moves, but be defensive
continue;
}
nodes += perft(&after, depth - 1);
}
return nodes;
}
void print_board(const struct Board *board) {
const char PIECE_CH[12] = {
'P','N','B','R','Q','K',