aboutsummaryrefslogtreecommitdiff
path: root/src/board
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-28 01:01:15 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-28 01:01:15 +0300
commit70315e4652bb49981108a9b920b95ab82a53edb7 (patch)
treef0bb316ebd5fface6f01aa164bf29afd7e4d6495 /src/board
parent690af97aa6c49a8ad76e47a2cee0c0b23b84ae6e (diff)
downloadchessnost-70315e4652bb49981108a9b920b95ab82a53edb7.tar.gz
feat: interactively play in main loop
Diffstat (limited to 'src/board')
-rw-r--r--src/board/mod.rs18
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