aboutsummaryrefslogtreecommitdiff
path: root/src/board/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/board/mod.rs')
-rw-r--r--src/board/mod.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs
index 19c25ac..2b580b5 100644
--- a/src/board/mod.rs
+++ b/src/board/mod.rs
@@ -77,6 +77,11 @@ const PIECE_CHARS: [&str; 12] = [
"♙", "♘", "♗", "♖", "♕", "♔",
];
+#[derive(Debug)]
+pub enum MakeMoveError {
+ PieceNotFound(String),
+}
+
#[allow(unused)]
impl Board {
@@ -485,10 +490,9 @@ impl Board {
mobility
}
-
/// *Blindlessly* apply a move without any validation
/// Move should be validated beforehand
- pub fn make_move(&mut self, mov: Move) -> Option<PieceType> {
+ pub fn make_move(&mut self, mov: Move) -> Result<Option<PieceType>,MakeMoveError> {
let move_source_bb = mov.source.to_bitboard();
let move_target_bb = mov.target.to_bitboard();
@@ -521,7 +525,11 @@ impl Board {
self.hash ^= self.zobrist_seed[pawn_type * 12 + captured_square as usize];
Some(PieceType::from(pawn_type))
}
- None => panic!("Pawn captured by En Passant was not found"),
+ None => {
+ return Err(MakeMoveError::PieceNotFound(
+ String::from("Pawn captured by En Passant was not found")
+ ))
+ }
}
}
@@ -543,7 +551,9 @@ impl Board {
},
None => {
self.print();
- panic!("{:?} is malformed: source piece not found", mov);
+ return Err(MakeMoveError::PieceNotFound(
+ String::from("Source piece not found")
+ ))
}
};
@@ -617,7 +627,7 @@ impl Board {
self.ply += 1;
self.hash ^= self.zobrist_seed[780];
- captured_piece
+ Ok(captured_piece)
}
/// Completely reverse make_move as if it never happened