aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-27 03:02:07 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-27 03:02:07 +0300
commit221a771b8eedb804272ab7f4ebae2030b548626d (patch)
tree8456f3b35021f290b03501111160ae06670e3422
parentb3b63041b6920fdf3dab79d8c81bfda33fcf8012 (diff)
downloadchessnost-221a771b8eedb804272ab7f4ebae2030b548626d.tar.gz
fix: correctly parse promotions
-rw-r--r--src/moves.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/moves.rs b/src/moves.rs
index 188e1e0..da66247 100644
--- a/src/moves.rs
+++ b/src/moves.rs
@@ -33,6 +33,17 @@ impl Move {
pub fn from_notation(mut notation: Chars) -> Self {
let source = Square::from_notation(&mut notation).unwrap();
let target = Square::from_notation(&mut notation).unwrap();
+
+ if let Some(promotion) = notation.next() {
+ let piece = match promotion {
+ 'r' => Piece::Rook,
+ 'q' => Piece::Queen,
+ 'b' => Piece::Bishop,
+ 'k' => Piece::Knight,
+ _ => panic!("Illegal promotion piece: {:?}", promotion)
+ };
+ return Move { source, target, kind: MoveKind::Promotion(piece) }
+ }
Move { source, target, kind: MoveKind::Quiet }
}
}