[moves] Clean up implementation of Move and export Kind enum
This commit is contained in:
parent
9010f1e9c2
commit
6816e350eb
4 changed files with 16 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use crate::builder::Builder;
|
||||
use crate::defs::Kind;
|
||||
use chessfriend_board::castle::Castle;
|
||||
use chessfriend_core::{Rank, Shape, Square};
|
||||
|
@ -57,7 +58,7 @@ impl Move {
|
|||
|
||||
#[must_use]
|
||||
pub fn is_castle(&self) -> bool {
|
||||
self.castle().is_some()
|
||||
(self.0 & 0b0010) != 0
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
@ -71,17 +72,17 @@ impl Move {
|
|||
|
||||
#[must_use]
|
||||
pub fn is_capture(&self) -> bool {
|
||||
(self.0 & 0b0100) != 0
|
||||
(self.0 & Kind::Capture as u16) != 0
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_en_passant(&self) -> bool {
|
||||
self.flags() == 0b0101
|
||||
self.0 == Kind::EnPassantCapture as u16
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_promotion(&self) -> bool {
|
||||
(self.0 & 0b1000) != 0
|
||||
(self.0 & Kind::Promotion as u16) != 0
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
@ -113,7 +114,7 @@ impl Move {
|
|||
}
|
||||
|
||||
impl Move {
|
||||
fn _transfer_char(self) -> char {
|
||||
fn transfer_char(self) -> char {
|
||||
if self.is_capture() || self.is_en_passant() {
|
||||
'x'
|
||||
} else {
|
||||
|
@ -122,18 +123,21 @@ impl Move {
|
|||
}
|
||||
}
|
||||
|
||||
const KINGSIDE_CASTLE_STR: &str = "0-0";
|
||||
const QUEENSIDE_CASTLE_STR: &str = "0-0-0";
|
||||
|
||||
impl fmt::Display for Move {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if let Some(castle) = self.castle() {
|
||||
return match castle {
|
||||
Castle::KingSide => write!(f, "0-0"),
|
||||
Castle::QueenSide => write!(f, "0-0-0"),
|
||||
Castle::KingSide => write!(f, "{KINGSIDE_CASTLE_STR}"),
|
||||
Castle::QueenSide => write!(f, "{QUEENSIDE_CASTLE_STR}"),
|
||||
};
|
||||
}
|
||||
|
||||
let origin = self.origin_square();
|
||||
let target = self.target_square();
|
||||
let transfer_char = self._transfer_char();
|
||||
let transfer_char = self.transfer_char();
|
||||
write!(f, "{origin}{transfer_char}{target}")?;
|
||||
|
||||
if let Some(promotion) = self.promotion() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue