From e8521ac96d75e13d90e181ec28585990c35e8f9e Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 3 Mar 2025 23:50:11 -0500 Subject: [PATCH] testing --- src/elo.rs | 49 +++++++++++++++++++++------------------ src/logic/future_moves.rs | 28 +++++++++++++++++++++- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/src/elo.rs b/src/elo.rs index 41f4de1..4c2d2ab 100644 --- a/src/elo.rs +++ b/src/elo.rs @@ -17,16 +17,12 @@ pub fn run() { min_arena_depth: 14, top_k_children: 2, up_to_minus: 10, - max_arena_size: usize::MAX, + max_arena_size: 1_000_000, do_not_prune: true, print: false, }; let mut arena = PlayerArena::new(vec![ - // ( - // "RandomAgent".into(), - // Box::new(|piece| Box::new(RandomAgent::new(piece))), - // ), ( "ComplexAgentD1".into(), Box::new(|piece| { @@ -39,6 +35,18 @@ pub fn run() { )) }), ), + ( + "ComplexAgentD2".into(), + Box::new(|piece| { + Box::new(ComplexAgent::new( + piece, + FutureMoveConfig { + max_depth: 2, + ..FMV_BASE + }, + )) + }), + ), ( "ComplexAgentD3".into(), Box::new(|piece| { @@ -52,24 +60,24 @@ pub fn run() { }), ), ( - "ComplexAgentD8".into(), + "ComplexAgentD4".into(), Box::new(|piece| { Box::new(ComplexAgent::new( piece, FutureMoveConfig { - max_depth: 8, + max_depth: 4, ..FMV_BASE }, )) }), ), // ( - // "ComplexAgent5M".into(), + // "ComplexAgentD8".into(), // Box::new(|piece| { // Box::new(ComplexAgent::new( // piece, // FutureMoveConfig { - // max_arena_size: 5_000_000, + // max_depth: 8, // ..FMV_BASE // }, // )) @@ -77,17 +85,9 @@ pub fn run() { // ), ]); - // arena.play( - // &(0..arena.players.len()) - // .zip([0].into_iter().cycle()) - // .filter(|(i, j)| i != j) - // .collect::>() - // .repeat(1000), - // ); - for _ in 0..10 { - arena.prop_arena(2); - println!("{}", arena); - } + arena.prop_arena(1000); + + println!("{}", arena); } pub struct PlayerArena { @@ -176,8 +176,13 @@ impl PlayerArena { } fn play_two_inner(player_1: Box, player_2: Box) -> Outcomes { - let result = - GameInner::new(player_1, player_2, false, Board::random(5)).loop_until_result(); + let result = GameInner::new( + player_1, + player_2, + false, + Board::random(rand::random_range(3..8)), + ) + .loop_until_result(); match result { Winner::Player(piece) => match piece { diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index 7066499..7138358 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -123,13 +123,39 @@ impl FutureMoves { }); self.prune_bad_children(); - self.current_depth += 1; + if cf.is_break() { + // pruning unfinished level + let by_depth = self.by_depth(0..self.arena.len()); + let mut bdh = HashMap::new(); + for (a, b) in by_depth { + bdh.insert(a, b); + } + + for &i in bdh.get(&(self.current_depth + 1)).unwrap_or(&Vec::new()) { + self.remove(i); + } + + for &i in bdh.get(&self.current_depth).unwrap_or(&Vec::new()) { + self.arena[i].tried_children = false; + } + + self.refocus_tree(); + return; } + self.current_depth += 1; } } + fn remove(&mut self, index: usize) { + if let Some(parent) = self.arena[index].parent { + self.arena[parent].children.retain(|&j| j != index); + } + + self.arena[index].parent = None; + } + /// Determines if a [`Move`] at index `idx` is connected to `self.current_root` /// Returns `false` if `self.current_root` is None fn is_connected_to_root(&self, idx: usize) -> bool {