compiler optimizations + focus the benchmark futher

This commit is contained in:
2025-02-18 22:33:29 -05:00
parent 9854067ca7
commit 52179c040b
3 changed files with 36 additions and 28 deletions

View File

@@ -97,7 +97,8 @@ impl FutureMoves {
}
/// Generate children for all children of `nodes`
fn extend_layers(&mut self) {
/// only `pub` for the sake of benchmarking
pub fn extend_layers(&mut self) {
let mut next_nodes: Vec<usize> = (0..self.arena.len())
// we want to select all nodes that don't have children, or are lazy (need to maybe be regenerated)
.filter(|&idx| self.arena[idx].children.is_empty() || self.arena[idx].lazy_children)
@@ -283,23 +284,26 @@ impl FutureMoves {
if let Some(curr_board_idx) = curr_board {
self.update_root_idx(curr_board_idx);
} else {
// println!("Generating root of FutureMoves");
self.arena.clear();
self.arena.push(Move {
i: 0,
j: 0,
board: *board,
winner: Winner::None,
parent: None,
children: Vec::new(),
value: 0,
color: !self.agent_color,
lazy_children: false,
});
self.create_root_raw(*board);
self.update_root_idx(0);
}
}
pub fn create_root_raw(&mut self, board: Board) {
self.arena.clear();
self.arena.push(Move {
i: 0,
j: 0,
board,
winner: Winner::None,
parent: None,
children: Vec::new(),
value: 0,
color: !self.agent_color,
lazy_children: false,
});
}
/// Update the root based on the coordinate of the move
/// Returns a boolean, `true` if the operation was successful, false if not
#[must_use = "You must check if the root was properly set"]
@@ -317,9 +321,14 @@ impl FutureMoves {
.is_some()
}
fn update_root_idx(&mut self, idx: usize) {
fn update_root_idx_raw(&mut self, idx: usize) {
self.current_root = Some(idx);
self.current_depth -= self.depth_of(idx) - 1;
}
fn update_root_idx(&mut self, idx: usize) {
self.update_root_idx_raw(idx);
self.refocus_tree();
self.extend_layers();
self.compute_values(0..self.arena.len());