Implement a basic Display for chessfriend_moves::Move

This commit is contained in:
Eryn Wells 2024-02-10 18:33:29 -07:00
parent 8724c3cdce
commit 3b8b6b36e3

View file

@ -89,6 +89,41 @@ impl Move {
fn special(&self) -> u16 {
self.0 & 0b11
}
fn _transfer_char(&self) -> char {
if self.is_capture() || self.is_en_passant() {
'x'
} else {
'-'
}
}
}
impl fmt::Display for Move {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(castle) = self.castle() {
match castle {
Castle::KingSide => return write!(f, "0-0"),
Castle::QueenSide => return write!(f, "0-0-0"),
}
}
write!(
f,
"{}{}{}",
self.origin_square(),
self._transfer_char(),
self.target_square()
)?;
if let Some(promotion) = self.promotion() {
write!(f, "={}", promotion)?;
} else if self.is_en_passant() {
write!(f, " e.p.")?;
}
Ok(())
}
}
impl fmt::Debug for Move {