zero-index FutureMoves::depth_of

This commit is contained in:
Simon Gardling 2025-02-25 10:12:29 -05:00
parent 17ea2e8e98
commit 9f9472939e
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -68,7 +68,7 @@ impl FutureMoves {
self.generate_children( self.generate_children(
node_idx, node_idx,
if self.arena[node_idx].lazy_children { if self.arena[node_idx].lazy_children {
self.depth_of(node_idx) - 1 self.depth_of(node_idx)
} else { } else {
i i
} > self.lazy_expire, } > self.lazy_expire,
@ -168,10 +168,10 @@ impl FutureMoves {
Some(new_indices) 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 { fn depth_of(&self, node_idx: usize) -> usize {
let mut depth = 0; let mut depth = 0;
let mut current = Some(node_idx); let mut current = self.arena[node_idx].parent;
while let Some(parent_idx) = current { while let Some(parent_idx) = current {
depth += 1; depth += 1;
current = self.arena[parent_idx].parent; current = self.arena[parent_idx].parent;
@ -298,7 +298,7 @@ impl FutureMoves {
/// Update current root without modifying or pruning the Arena /// Update current root without modifying or pruning the Arena
fn update_root_idx_raw(&mut self, idx: usize) { fn update_root_idx_raw(&mut self, idx: usize) {
self.current_root = Some(idx); 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) /// Update current root index while pruning and extending the tree (also recalculate values)