From 4a0c734ebaf75a7f2b531bc44878d578f882e4c2 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Thu, 16 May 2024 09:06:44 +0200 Subject: [PATCH] perft: Avoid recursion at depth 2 --- src/search.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/search.c b/src/search.c index 06f889b..9fd90cf 100644 --- a/src/search.c +++ b/src/search.c @@ -60,7 +60,13 @@ u64 perft(pos_t *pos, int depth, int ply, bool output) nodes++; } else { move_do(pos, *move); - subnodes = perft(pos, depth - 1, ply + 1, output); + if (depth == 2) { + movelist_t movelist2; + pos_set_checkers_pinners_blockers(pos); + subnodes = pos_legal(pos, pos_gen_pseudo(pos, &movelist2))->nmoves; + } else { + subnodes = perft(pos, depth - 1, ply + 1, output); + } if (output && ply == 1) { char movestr[8]; printf("%s: %d\n", move_str(movestr, *move, 0), subnodes); @@ -105,7 +111,13 @@ u64 perft_test(pos_t *pos, int depth, int ply, bool output) nodes++; } else { move_do2(pos, *move, &state); - subnodes = perft_test(pos, depth - 1, ply + 1, output); + if (depth == 2) { + movelist_t movelist2; + pos_set_checkers_pinners_blockers(pos); + subnodes = pos_legal(pos, pos_gen_pseudo(pos, &movelist2))->nmoves; + } else { + subnodes = perft_test(pos, depth - 1, ply + 1, output); + } if (output && ply == 1) { char movestr[8]; printf("%s: %d\n", move_str(movestr, *move, 0), subnodes);