From 0d837ca0548f1cf0b9df0c6d806cd7a1af3e84f6 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 6 Mar 2025 15:40:50 -0500 Subject: [PATCH] add deriving board from index --- src/logic/future_moves.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index f3ee325..aaf6f3f 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -293,6 +293,33 @@ impl FutureMoves { } } + fn get_board_from_idx(&self, idx: usize) -> Option { + if let Some(root) = self.current_root { + let mut hist = Vec::new(); + + let mut current = Some(idx); + while let Some(parent_idx) = current { + if parent_idx == root { + break; + } + + let n = &self.arena[parent_idx]; + hist.push((n.coord, n.color)); + current = n.parent; + } + + let mut board = self.arena[root].board.clone(); + for (m, c) in hist.into_iter().rev() { + if let Some(m) = m { + let _ = board.place(m, c); + } + } + Some(board) + } else { + None + } + } + /// Return the best move which is a child of `self.current_root` pub fn best_move(&self) -> Option> { self.current_root