From 9f9472939e0c6d8481ca76d289599ae386347c62 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Tue, 25 Feb 2025 10:12:29 -0500 Subject: [PATCH] zero-index FutureMoves::depth_of --- src/logic/future_moves.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index 1ddf4b5..1f464bb 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -68,7 +68,7 @@ impl FutureMoves { self.generate_children( node_idx, if self.arena[node_idx].lazy_children { - self.depth_of(node_idx) - 1 + self.depth_of(node_idx) } else { i } > self.lazy_expire, @@ -168,10 +168,10 @@ impl FutureMoves { Some(new_indices) } - /// Given an index from `self.arena`, what depth is it at? 1-indexed (ROOT IS AT INDEX 1) + /// Given an index from `self.arena`, what depth is it at? 0-indexed fn depth_of(&self, node_idx: usize) -> usize { let mut depth = 0; - let mut current = Some(node_idx); + let mut current = self.arena[node_idx].parent; while let Some(parent_idx) = current { depth += 1; current = self.arena[parent_idx].parent; @@ -298,7 +298,7 @@ impl FutureMoves { /// Update current root without modifying or pruning the Arena fn update_root_idx_raw(&mut self, idx: usize) { self.current_root = Some(idx); - self.current_depth -= self.depth_of(idx) - 1; + self.current_depth -= self.depth_of(idx); } /// Update current root index while pruning and extending the tree (also recalculate values)