add deriving board from index
This commit is contained in:
parent
945ec934f5
commit
0d837ca054
@ -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`
|
/// Return the best move which is a child of `self.current_root`
|
||||||
pub fn best_move(&self) -> Option<Option<CoordPair>> {
|
pub fn best_move(&self) -> Option<Option<CoordPair>> {
|
||||||
self.current_root
|
self.current_root
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user