From c5cc0646efc30a6723ed2b4ce6a524e77c095f45 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Wed, 18 Jun 2025 08:22:12 -0700 Subject: [PATCH] [perft] Add back the block on searching into seen positions Check if the board position has been seen and stop recursion if so. --- position/src/perft.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/position/src/perft.rs b/position/src/perft.rs index a9ae169..97b3c51 100644 --- a/position/src/perft.rs +++ b/position/src/perft.rs @@ -18,14 +18,18 @@ impl Position { let legal_moves: Vec = self.all_legal_moves(None).collect(); - for ply in legal_moves { - let ply = ply.ply(); + for generated_ply in legal_moves { + let ply = generated_ply.ply(); - let _has_seen_position = self + let has_seen_position = self .make_move(ply, ValidateMove::No) .expect("unable to make generated move"); - let nodes_counted = self.perft_recursive(depth - 1, depth); + let nodes_counted = if has_seen_position { + 1 + } else { + self.perft_recursive(depth - 1, max_depth) + }; total_nodes_counted += nodes_counted;