diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index db7c275..6787ff7 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -46,7 +46,7 @@ impl FutureMoves { // we want to select all nodes that don't have children, or are lazy (need to maybe be regenerated) .filter(|&idx| { let got = &self.arena[idx]; - got.is_lazy || got.children.is_empty() + got.is_trimmed || got.children.is_empty() }) .filter(|&idx| self.is_connected_to_root(idx)) .collect::>() @@ -317,23 +317,25 @@ impl FutureMoves { // values are needed in order to prune and see what's best self.compute_values(0..self.arena_len()); - let by_depth = - self.by_depth((0..self.arena.len()).filter(|&i| self.is_connected_to_root(i))); + let by_depth = self.by_depth(0..self.arena.len()); const TOP_K_CHIL: usize = 2; - // the lower the value, the more conservative - const UP_TO: usize = 5; + // the lower the value, the more conservative, what level to stop pruning at? + // a lower value allows more possible paths + let up_to = self.current_depth - 2; - // start pruning at X depth before self.max_depth - const START_PRUNING_AT_MINUS: usize = 2; - if self.max_depth > self.current_depth + START_PRUNING_AT_MINUS { + // start pruning at X depth before self.max_depth is reached + // used for pruning during tree generation before the tree is fully grown + const START_PRUNING_AT_MINUS: usize = 3; + + if self.max_depth.saturating_sub(START_PRUNING_AT_MINUS) > self.current_depth { return; } for (depth, indexes) in by_depth { // TODO! maybe update by_depth every iteration or something? - if depth > UP_TO { + if depth > up_to { return; } @@ -344,10 +346,10 @@ impl FutureMoves { for idx in indexes { let mut m = self.arena[idx].clone(); - if m.is_lazy { + if m.is_trimmed { continue; } - m.is_lazy = true; + m.is_trimmed = true; m.sort_children(&mut self.arena); if m.children.len() > TOP_K_CHIL { let drained = m.children.drain(TOP_K_CHIL..); @@ -358,6 +360,8 @@ impl FutureMoves { self.arena[idx] = m; } } + + // rebuild tree to exclude the things that were pruned self.refocus_tree(); } @@ -444,7 +448,7 @@ mod tests { value: None, self_value: 0, color: Piece::Black, - is_lazy: false, + is_trimmed: false, }); futm.update_root_idx_raw(0); @@ -546,7 +550,7 @@ mod tests { value: None, self_value: 0, color: Piece::Black, - is_lazy: false, + is_trimmed: false, }); futm.update_root_idx_raw(0); @@ -610,7 +614,7 @@ mod tests { value: None, self_value: 0, color: Piece::Black, - is_lazy: false, + is_trimmed: false, }); futm.update_root_idx_raw(0); diff --git a/src/logic/move.rs b/src/logic/move.rs index 03f3273..d72f7af 100644 --- a/src/logic/move.rs +++ b/src/logic/move.rs @@ -31,8 +31,8 @@ pub struct Move { /// Which color made a move on this move? pub color: Piece, - /// Was this child lazily created? (it will have delayed child generation) - pub is_lazy: bool, + /// Was this move's children previously trimmed? + pub is_trimmed: bool, } lazy_static! { @@ -57,7 +57,7 @@ impl Move { children: Vec::new(), value: None, color, - is_lazy: false, + is_trimmed: false, self_value: 0, }; m.self_value = m.compute_self_value(agent_color);