Implement a basic Display for chessfriend_moves::Move
This commit is contained in:
parent
8724c3cdce
commit
3b8b6b36e3
1 changed files with 35 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue