From e4684649566cd5af21cb8fa5c85b7be3a24fe4c1 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 26 Feb 2025 22:47:28 -0500 Subject: [PATCH] FutureMoves: add (failing) test for situation encountered during testing --- src/logic/future_moves.rs | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index cb963cd..6e7f7c2 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -637,4 +637,49 @@ mod tests { vec![(0, vec![0, 2]), (1, vec![1]), (2, vec![3])] ); } + + #[test] + fn best_move_failure() { + let mut futm = FutureMoves::new(Piece::Black, FUTURE_MOVES_CONFIG); + let mut board = Board::new().starting_pos(); + + // replay of a test I did + // TODO! make this as small of a test as possible + let moves = vec![ + (Some((5, 4)), Piece::Black), + (Some((5, 5)), Piece::White), + (Some((5, 6)), Piece::Black), + (Some((6, 4)), Piece::White), + (Some((7, 3)), Piece::Black), + (Some((7, 4)), Piece::White), + (Some((7, 5)), Piece::Black), + (Some((2, 4)), Piece::White), + (Some((1, 4)), Piece::Black), + (Some((1, 5)), Piece::White), + (Some((1, 6)), Piece::Black), + (Some((0, 6)), Piece::White), + (Some((3, 2)), Piece::Black), + (Some((1, 7)), Piece::White), + (None, Piece::Black), // black skips a move + (Some((0, 4)), Piece::White), + (None, Piece::Black), // black skips a move + (Some((4, 2)), Piece::White), + ]; + + for (coords, color) in moves { + if color == futm.agent_color { + // my turn + futm.update_from_board(&board); + let best_move = futm.best_move(); + if coords.is_none() { + assert_eq!(best_move, None); + } else { + assert_ne!(best_move, None); + } + } + if let Some((i, j)) = coords { + board.place(i, j, color).unwrap(); + } + } + } }