add depth_of test
This commit is contained in:
parent
0adb59dc7f
commit
bd00c29ad4
@ -158,13 +158,13 @@ impl FutureMoves {
|
|||||||
/// Given an index from `self.arena`, what depth is it at? 0-indexed
|
/// 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 = self.arena[node_idx].parent;
|
let mut current = Some(node_idx);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
depth
|
depth - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute `Move.value`, propegating upwards from the furthest out Moves
|
/// Compute `Move.value`, propegating upwards from the furthest out Moves
|
||||||
@ -491,4 +491,72 @@ mod tests {
|
|||||||
"extend_layer didn't grow arena after refocus"
|
"extend_layer didn't grow arena after refocus"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depth_of_test() {
|
||||||
|
let mut futm = FutureMoves::new(Piece::Black, 0, 0);
|
||||||
|
|
||||||
|
futm.arena.push(Move {
|
||||||
|
i: 0,
|
||||||
|
j: 0,
|
||||||
|
board: Board::new(),
|
||||||
|
winner: Winner::None,
|
||||||
|
parent: None,
|
||||||
|
children: vec![1],
|
||||||
|
value: 0,
|
||||||
|
self_value: 0,
|
||||||
|
color: Piece::Black,
|
||||||
|
lazy_children: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
futm.update_root_idx_raw(0);
|
||||||
|
|
||||||
|
// child 1
|
||||||
|
futm.arena.push(Move::new(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
Board::new(),
|
||||||
|
Piece::White,
|
||||||
|
false,
|
||||||
|
Piece::Black,
|
||||||
|
Some(0),
|
||||||
|
));
|
||||||
|
futm.arena[1].parent = Some(0);
|
||||||
|
futm.arena[1].children = vec![3];
|
||||||
|
|
||||||
|
// dummy
|
||||||
|
futm.arena.push(Move::new(
|
||||||
|
1234,
|
||||||
|
1234,
|
||||||
|
Board::new(),
|
||||||
|
Piece::White,
|
||||||
|
false,
|
||||||
|
Piece::Black,
|
||||||
|
None,
|
||||||
|
));
|
||||||
|
|
||||||
|
futm.arena.push(Move::new(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
Board::new(),
|
||||||
|
Piece::White,
|
||||||
|
false,
|
||||||
|
Piece::Black,
|
||||||
|
Some(0),
|
||||||
|
));
|
||||||
|
|
||||||
|
futm.arena[3].parent = Some(1);
|
||||||
|
|
||||||
|
futm.arena.push(Move::new(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
Board::new(),
|
||||||
|
Piece::White,
|
||||||
|
false,
|
||||||
|
Piece::Black,
|
||||||
|
Some(0),
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(futm.depth_of(3), 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user