|
@@ -168,9 +168,9 @@ impl Board {
|
|
|
Self::from_fen(fen_parts.collect::<Vec<&str>>().as_slice())
|
|
|
}
|
|
|
|
|
|
- pub fn parse_move(&self, mov: &str) -> Result<Move, ()> {
|
|
|
+ pub fn parse_move(&self, mov: &str) -> Result<Move, String> {
|
|
|
if mov.len() < 4 {
|
|
|
- Err(())
|
|
|
+ Err("string too short".to_owned())
|
|
|
}
|
|
|
else {
|
|
|
let origin = Move::parse_square(&mov[0..2]);
|
|
@@ -182,7 +182,7 @@ impl Board {
|
|
|
Some('N') | Some('n') => KNIGHT,
|
|
|
Some('B') | Some('b') => BISHOP,
|
|
|
Some('R') | Some('r') => ROOK,
|
|
|
- _ => panic!("invalid move: {}", mov)
|
|
|
+ _ => return Err("invalid promotion".to_owned())
|
|
|
})
|
|
|
}
|
|
|
else {
|
|
@@ -190,7 +190,7 @@ impl Board {
|
|
|
};
|
|
|
|
|
|
if let (Some(from), Some(to)) = (origin, target) {
|
|
|
- let (piece_type, side) = self.get_square(from).unwrap_or(Err(())?);
|
|
|
+ let (piece_type, side) = self.get_square(from).ok_or("no piece at from square")?;
|
|
|
//println!("from: {}", from);
|
|
|
|
|
|
let target = self.get_square(to);
|
|
@@ -198,19 +198,19 @@ impl Board {
|
|
|
|
|
|
if let Some((_cap, cs)) = target {
|
|
|
if cs == side {
|
|
|
- // cannot capture own piece
|
|
|
- return Err(());
|
|
|
+ return Err("cannot capture own piece".to_owned());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- if side != self.turn { // wrong side to move
|
|
|
- return Err(());
|
|
|
+ if side != self.turn {
|
|
|
+ return Err("wrong side to move".to_owned());
|
|
|
}
|
|
|
|
|
|
if let Some(promote_to) = promote_to {
|
|
|
if piece_type != PAWN {
|
|
|
- return Err(());
|
|
|
+ // should never happen
|
|
|
+ return Err("cannot promote to pawn".to_owned());
|
|
|
}
|
|
|
Ok(Move::Promotion{ mov: SimpleMove{ from, to }, pc: PieceCaptureType::new(promote_to, captured) })
|
|
|
}
|
|
@@ -237,7 +237,7 @@ impl Board {
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- Err(())
|
|
|
+ Err("no valid squares".to_owned())
|
|
|
}
|
|
|
}
|
|
|
}
|