nits
This commit is contained in:
parent
8e22768987
commit
2305a8065f
@ -314,21 +314,23 @@ impl FutureMoves {
|
|||||||
|
|
||||||
let mut index_map = vec![None; self.arena.len()];
|
let mut index_map = vec![None; self.arena.len()];
|
||||||
|
|
||||||
let new_start: Vec<(usize, (usize, Move))> = retain
|
let new_start: Vec<(usize, usize, Move)> = retain
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate() // old_idx
|
.enumerate() // old_idx
|
||||||
.zip(self.arena.drain(..))
|
.zip(self.arena.drain(..))
|
||||||
.flat_map(|((old_idx, keep), node)| keep.then_some((old_idx, node))) // filter out unrelated nodes
|
.filter(|&((_, keep), _)| keep) // filter out un-related nodes
|
||||||
|
.map(|((old_idx, _), node)| (old_idx, node))
|
||||||
.enumerate() // new_idx
|
.enumerate() // new_idx
|
||||||
|
.map(|(a, (b, c))| (a, b, c))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for &(new_idx, (old_idx, _)) in &new_start {
|
for &(new_idx, old_idx, _) in &new_start {
|
||||||
index_map[old_idx] = Some(new_idx);
|
index_map[old_idx] = Some(new_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.arena = new_start
|
self.arena = new_start
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_, (_, mut node))| {
|
.map(|(_, _, mut node)| {
|
||||||
if let Some(parent) = node.parent.as_mut() {
|
if let Some(parent) = node.parent.as_mut() {
|
||||||
if let Some(new_parent) = index_map[*parent] {
|
if let Some(new_parent) = index_map[*parent] {
|
||||||
*parent = new_parent;
|
*parent = new_parent;
|
||||||
@ -339,7 +341,10 @@ impl FutureMoves {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for c in node.children.as_mut_slice() {
|
for c in node.children.as_mut_slice() {
|
||||||
debug_assert!(index_map.get(*c).unwrap().is_some());
|
debug_assert!(
|
||||||
|
index_map.get(*c).unwrap().is_some(),
|
||||||
|
"index_map should contain the child's index"
|
||||||
|
);
|
||||||
*c = unsafe { index_map.get_unchecked(*c).unwrap_unchecked() };
|
*c = unsafe { index_map.get_unchecked(*c).unwrap_unchecked() };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,18 +431,15 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn expand_layer_test() {
|
fn expand_layer_test() {
|
||||||
let mut futm = FutureMoves::new(Piece::Black, 1, 1);
|
let mut futm = FutureMoves::new(Piece::Black, 1, 1);
|
||||||
futm.arena.push(Move {
|
futm.arena.push(Move::new(
|
||||||
i: 0,
|
0,
|
||||||
j: 0,
|
0,
|
||||||
board: Board::new().starting_pos(),
|
Board::new().starting_pos(),
|
||||||
winner: Winner::None,
|
Piece::Black,
|
||||||
parent: None,
|
false,
|
||||||
children: Vec::new(),
|
Piece::Black,
|
||||||
value: 0,
|
None,
|
||||||
self_value: 0,
|
));
|
||||||
color: Piece::Black,
|
|
||||||
lazy_children: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
futm.update_root_idx_raw(0);
|
futm.update_root_idx_raw(0);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user