diff --git a/moves/src/moves.rs b/moves/src/moves.rs index 94ef0ad..c1fda0c 100644 --- a/moves/src/moves.rs +++ b/moves/src/moves.rs @@ -1,6 +1,7 @@ // Eryn Wells use crate::defs::{Kind, PromotionShape}; +use chessfriend_bitboard::BitBoard; use chessfriend_core::{Rank, Shape, Square, Wing}; use std::fmt; @@ -215,6 +216,19 @@ impl Move { } } +impl Move { + pub fn relevant_squares(&self) -> BitBoard { + [ + Some(self.origin_square()), + Some(self.target_square()), + self.capture_square(), + ] + .into_iter() + .flatten() + .collect() + } +} + impl Move { fn transfer_char(self) -> char { if self.is_capture() || self.is_en_passant() { diff --git a/position/src/position.rs b/position/src/position.rs index 17f36eb..332bf65 100644 --- a/position/src/position.rs +++ b/position/src/position.rs @@ -110,13 +110,21 @@ impl Position { let ply: Move = ply.clone().into(); let record = test_board .make_move(ply, ValidateMove::No) - .expect("unable to make generated move"); + .unwrap_or_else(|err| { + panic!( + "unable to make generated move [{ply}]: {err}\n\n{}", + test_board.display().highlight(ply.relevant_squares()) + ); + }); let move_is_legal = !test_board.color_is_in_check(Some(active_color_before_move)); - test_board - .unmake_move(&record) - .expect("unable to unmake generated move"); + test_board.unmake_move(&record).unwrap_or_else(|err| { + panic!( + "unable to unmake generated move [{ply}]: {err}\n\n{}", + test_board.display().highlight(ply.relevant_squares()) + ); + }); move_is_legal }))