add early_break for extend_layers

This commit is contained in:
Simon Gardling 2025-02-26 14:37:25 -05:00
parent 9fd3b45c0e
commit cd0ac5f538
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
3 changed files with 12 additions and 6 deletions

View File

@ -11,6 +11,7 @@ fn extend_layers_test(depth: usize) {
start_pruning_at_minus: 4, start_pruning_at_minus: 4,
top_k_children: 2, top_k_children: 2,
up_to_mod: 4, up_to_mod: 4,
max_arena_size: 10_000_000,
}; };
let mut fut = FutureMoves::new(Piece::Black, config); let mut fut = FutureMoves::new(Piece::Black, config);
fut.set_root_from_board(Board::new().starting_pos()); fut.set_root_from_board(Board::new().starting_pos());

View File

@ -13,10 +13,11 @@ pub struct ComplexAgent {
impl ComplexAgent { impl ComplexAgent {
pub const fn new(color: Piece) -> Self { pub const fn new(color: Piece) -> Self {
const CONFIG: FutureMoveConfig = FutureMoveConfig { const CONFIG: FutureMoveConfig = FutureMoveConfig {
max_depth: 7, max_depth: 9,
start_pruning_at_minus: 4, start_pruning_at_minus: 4,
top_k_children: 2, top_k_children: 2,
up_to_mod: 4, up_to_mod: 4,
max_arena_size: 100_000_000,
}; };
Self { Self {
color, color,

View File

@ -36,6 +36,10 @@ pub struct FutureMoveConfig {
// the lower the value, the more conservative the pruning is, what level to stop pruning at? // the lower the value, the more conservative the pruning is, what level to stop pruning at?
// a lower value allows more possible paths // a lower value allows more possible paths
pub up_to_mod: usize, pub up_to_mod: usize,
/// Max size of the arena, will not generate more if
/// the arena is of that size or bigger
pub max_arena_size: usize,
} }
impl FutureMoves { impl FutureMoves {
@ -58,6 +62,11 @@ impl FutureMoves {
/// only `pub` for the sake of benchmarking /// only `pub` for the sake of benchmarking
pub fn extend_layers(&mut self) { pub fn extend_layers(&mut self) {
for i in (self.current_depth + 1)..=self.config.max_depth { for i in (self.current_depth + 1)..=self.config.max_depth {
if self.arena_len() >= self.config.max_arena_size {
dbg!("extend_layers: early break ({})", self.arena_len());
break;
}
(0..self.arena.len()) (0..self.arena.len())
// we want to select all nodes that don't have children, or are lazy (need to maybe be regenerated) // we want to select all nodes that don't have children, or are lazy (need to maybe be regenerated)
.filter(|&idx| { .filter(|&idx| {
@ -81,11 +90,6 @@ impl FutureMoves {
self.prune_bad_children(); self.prune_bad_children();
self.current_depth += 1; self.current_depth += 1;
} }
assert_eq!(
self.current_depth, self.config.max_depth,
"iteration and extention did not extend current_depth ({}) to the max_depth ({})",
self.current_depth, self.config.max_depth
);
} }
/// Determines if a [`Move`] at index `idx` is connected to `self.current_root` /// Determines if a [`Move`] at index `idx` is connected to `self.current_root`