#include "movegen.h" #include #include #include static unsigned long long perft(Position pos, int depth){ if (depth==0) return 1ULL; Move moves[256]; unsigned long long nodes = 0ULL; int n = gen_moves(&pos, moves, 256, 0); for (int i=0;ifrom & 7), fr = (m->from >> 4); int tf = (m->to & 7), tr = (m->to >> 4); buf[0] = 'a' + ff; buf[1] = '1' + fr; buf[2] = 'a' + tf; buf[3] = '1' + tr; int i=4; if (m->promo){ char pc='q'; switch(m->promo){ case WQ: case BQ: pc='q'; break; case WR: case BR: pc='r'; break; case WB: case BB: pc='b'; break; case WN: case BN: pc='n'; break; default: pc='q'; } buf[i++]=pc; } buf[i]=0; } static void run_case(const char *fen, int depth, unsigned long long expected){ Position p; if (!parse_fen(&p, fen)){ fprintf(stderr, "Bad FEN: %s\n", fen); return; } unsigned long long n = perft(p, depth); printf("perft(%d) = %llu %s\n", depth, n, (expected? (n==expected?"OK":"MISMATCH"):"")); } int main(int argc, char**argv){ if (argc>=3){ const char *fen = argv[1]; int depth = atoi(argv[2]); Position p; if (!parse_fen(&p, fen)){ fprintf(stderr, "Bad FEN input\n"); return 2; } if (argc>=4 && strcmp(argv[3], "--divide")==0){ Move moves[256]; int n = gen_moves(&p, moves, 256, 0); unsigned long long total=0ULL; for (int i=0;i=4 && strcmp(argv[3], "--divide-pseudo")==0){ Move moves[256]; int n = gen_moves_pseudo(&p, moves, 256, 0); for (int i=0;i