I'm not sure if my approach is anything new (it's definitely not the most efficient), but the wiki doesn't mention it.
I'm using a "quazi-legal" move generator:
Code: Select all
move_t* gen_all(move_t* moves);
Code: Select all
int64_t perft(move_t* moves, uint8_t depth) {
move_t *pCurr, *pEnd;
int64_t count = 0, n;
if (!depth)
return 1;
if (!(pEnd = gen_all(moves)))
return -1;
for (pCurr = moves; pCurr != pEnd; ++pCurr) {
make(*pCurr);
n = perft(pEnd, depth - 1);
unmake(*pCurr);
if (n < 0)
return 0;
count += n;
}
return count;
}
Could you please help me find the bug?