diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index 6460baf..f225ce7 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -759,4 +759,61 @@ mod tests { } } } + + #[test] + fn derive_board() { + let mut futm = FutureMoves::new(Piece::White, FUTURE_MOVES_CONFIG); + + let mut b = Board::new().starting_pos(); + let _ = b.place((2, 3).into(), Piece::Black); + + futm.arena.push(Move::new( + Some((2, 3).into()), + b, + Piece::Black, + Piece::White, + )); + } + + // I can't actually reproduce the issue I got, this is my best attempt + // Can't get it to fail! + #[test] + fn corr_moves() { + let mut board = Board::new(); + board.place_unchecked((5, 4).into(), Piece::Black); + board.place_unchecked((4, 4).into(), Piece::Black); + board.place_unchecked((4, 3).into(), Piece::Black); + + board.place_unchecked((3, 5).into(), Piece::White); + board.place_unchecked((3, 4).into(), Piece::Black); + board.place_unchecked((3, 3).into(), Piece::White); + + board.place_unchecked((2, 4).into(), Piece::Black); + + let move_log = vec![ + (Some((4, 6)), Piece::Black), + (Some((5, 5)), Piece::White), + // (Some((3, 1)), Piece::Black), // invalid move + ]; + for (m, c) in move_log { + if let Some(m) = m { + board.place(m.into(), c).expect("invalid move"); + } + } + + let mut futm = FutureMoves::new(Piece::White, FUTURE_MOVES_CONFIG); + futm.update_from_board(&board); + futm.extend_layers(); + let best_move = futm.best_move(); + + if let Some(best_move) = best_move { + assert!( + board + .possible_moves(futm.agent_color) + .find(|x| Some(x) == best_move.as_ref()) + .is_some(), + "futm played an invalid move" + ); + } + } }