add deriving board from index

This commit is contained in:
Simon Gardling 2025-03-06 15:40:50 -05:00
parent 945ec934f5
commit 0d837ca054
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -293,6 +293,33 @@ impl FutureMoves {
}
}
fn get_board_from_idx(&self, idx: usize) -> Option<Board> {
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<Option<CoordPair>> {
self.current_root