Add perft testing
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user