aboutsummaryrefslogtreecommitdiff
path: root/src/moves.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2024-01-25 11:24:36 +0100
committereug-vs <eugene@eug-vs.xyz>2024-01-25 11:24:36 +0100
commit746e3bf17463a377b6c54b291ebef9a736d6ceb7 (patch)
treea4e965669871084b98d3ce89ac95fa9d50131699 /src/moves.rs
parent299c6d6dee96a50f9366955192f922d449d11f20 (diff)
downloadchessnost-746e3bf17463a377b6c54b291ebef9a736d6ceb7.tar.gz
chore: autoformat codecanary
Use #[rustfmt:skip] to preserve aligned blocks
Diffstat (limited to 'src/moves.rs')
-rw-r--r--src/moves.rs41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/moves.rs b/src/moves.rs
index b338afe..5dc769c 100644
--- a/src/moves.rs
+++ b/src/moves.rs
@@ -1,6 +1,6 @@
-use std::{str::Chars, fmt::Display};
+use std::{fmt::Display, str::Chars};
-use crate::{square::Square, bitboard::BitboardFns, board::piece::Piece};
+use crate::{bitboard::BitboardFns, board::piece::Piece, square::Square};
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
pub enum MoveKind {
@@ -27,7 +27,10 @@ impl Move {
/// Tactical move is a move that changes material score
pub fn is_tactical(&self) -> bool {
- matches!(self.kind, MoveKind::Capture | MoveKind::EnPassant | MoveKind::Promotion(_))
+ matches!(
+ self.kind,
+ MoveKind::Capture | MoveKind::EnPassant | MoveKind::Promotion(_)
+ )
}
pub fn from_notation(mut notation: Chars) -> Self {
@@ -40,27 +43,33 @@ impl Move {
'q' => Piece::Queen,
'b' => Piece::Bishop,
'n' => Piece::Knight,
- _ => panic!("Illegal promotion piece: {:?}", promotion)
+ _ => panic!("Illegal promotion piece: {:?}", promotion),
};
- return Move { source, target, kind: MoveKind::Promotion(piece) }
+ return Move {
+ source,
+ target,
+ kind: MoveKind::Promotion(piece),
+ };
+ }
+ Move {
+ source,
+ target,
+ kind: MoveKind::Quiet,
}
- Move { source, target, kind: MoveKind::Quiet }
}
}
impl Display for Move {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let promotion_postfix = match self.kind {
- MoveKind::Promotion(piece) => {
- match piece.without_color() {
- Piece::Rook => "r",
- Piece::Queen => "q",
- Piece::Bishop => "b",
- Piece::Knight => "n",
- _ => panic!("Illegal promotion piece: {:?}", piece)
- }
- }
- _ => ""
+ MoveKind::Promotion(piece) => match piece.without_color() {
+ Piece::Rook => "r",
+ Piece::Queen => "q",
+ Piece::Bishop => "b",
+ Piece::Knight => "n",
+ _ => panic!("Illegal promotion piece: {:?}", piece),
+ },
+ _ => "",
};
write!(f, "{}{}{}", self.source, self.target, promotion_postfix)
}