diff options
Diffstat (limited to 'src/board/mod.rs')
-rw-r--r-- | src/board/mod.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs index ce8c076..a3d1fd9 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -148,20 +148,28 @@ impl Board { Self::from_FEN(default_fen) } - pub fn read_move(&self) -> Move { + pub fn read_move(&self) -> Result<Move, String> { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); let chars = &mut s.chars(); - let source = Square::from_notation(chars); - let target = Square::from_notation(chars); + + let source = match Square::from_notation(chars) { + Ok(s) => s, + Err(e) => return Err(e), + }; + let target = match Square::from_notation(chars) { + Ok(s) => s, + Err(e) => return Err(e), + }; let moves = self.generate_pseudolegal_moves(self.color()); let mov = match moves.iter().find(|m| m.source == source && m.target == target) { Some(m) => *m, - None => panic!("Move is not valid"), + None => return Err(String::from("Move is not valid")), }; - mov + + Ok(mov) } /// Color to move at this ply |