From 88c0638d83ae1da6c640943ac7614d7d3d2ae5bc Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Wed, 24 Jan 2024 17:10:10 -0800 Subject: [PATCH] [board] Check that move is in sight of piece If it's not, return an error from MoveBuilder::make() --- board/src/position/builders/move_builder.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/board/src/position/builders/move_builder.rs b/board/src/position/builders/move_builder.rs index 4530543..ae1c0fd 100644 --- a/board/src/position/builders/move_builder.rs +++ b/board/src/position/builders/move_builder.rs @@ -62,9 +62,14 @@ where .position .piece_on_square(from_square) .ok_or(MakeMoveError::NoPiece)?; - println!("{}", &piece); let to_square = mv.to_square(); + + let sight = piece.sight_in_position(self.position); + if !sight.is_set(to_square) { + return Err(MakeMoveError::IllegalSquare(to_square)); + } + let player = self.position.player_to_move(); let captured_piece: Option = if mv.is_en_passant() {