From fae4aaab6f37b66f24e818b0af7e45c49312e17e Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 27 Feb 2025 11:53:53 -0500 Subject: [PATCH] fix test --- src/logic/future_moves.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index 773f591..2b3e9e0 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -237,17 +237,13 @@ impl FutureMoves { /// The board is supposed to be after the opposing move /// Returns whether or not the arena was regenerated (bool) pub fn update_from_board(&mut self, board: &Board) -> bool { - let curr_board = self - .arena - .iter() - .enumerate() - .filter(|(idx, _)| { - self.current_root - .map(|x| self.arena[x].children.contains(idx)) - .unwrap_or(false) - }) - .find(|(_, m)| &m.board == board) - .map(|(idx, _)| idx); + let curr_board = (0..self.arena.len()) + // needs to be every other generation in order to + // match the agent_color usually root or great-grand child + .filter(|&idx| self.depth_of(idx) % 2 == 0) + .find(|&idx| { + &self.arena[idx].board == board && self.arena[idx].color == !self.agent_color + }); if let Some(curr_board_idx) = curr_board { self.set_root_idx_raw(curr_board_idx); @@ -447,7 +443,7 @@ mod tests { use super::*; const FUTURE_MOVES_CONFIG: FutureMoveConfig = FutureMoveConfig { - max_depth: 1, + max_depth: 3, // we want great-grand children for traversing moves min_arena_depth_sub: 0, top_k_children: 1, up_to_minus: 0, @@ -658,7 +654,9 @@ mod tests { // make sure that the arena should only be // regenerated on the first move - assert!(i <= 0 || update_result, "board regenerated on move #{}", i); + if i > 0 && update_result { + panic!("board regenerated on move #{}", i); + } let best_move = futm.best_move(); assert!(