This commit is contained in:
Eryn Wells 2025-05-08 17:37:51 -07:00
parent d5cdf273c8
commit 091cc99cb3
42 changed files with 805 additions and 1662 deletions

View file

@ -2,6 +2,7 @@
use chessfriend_core::Shape;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum Kind {
Quiet = 0b0000,
DoublePush = 0b0001,
@ -13,6 +14,12 @@ pub(crate) enum Kind {
CapturePromotion = 0b1100,
}
impl Kind {
fn is_reversible(self) -> bool {
(self as u16) & 0b1100 == 0
}
}
#[repr(u16)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum PromotionShape {
@ -32,3 +39,17 @@ impl From<PromotionShape> for Shape {
}
}
}
impl TryFrom<Shape> for PromotionShape {
type Error = ();
fn try_from(value: Shape) -> Result<Self, Self::Error> {
match value {
Shape::Knight => Ok(PromotionShape::Knight),
Shape::Bishop => Ok(PromotionShape::Bishop),
Shape::Rook => Ok(PromotionShape::Rook),
Shape::Queen => Ok(PromotionShape::Queen),
_ => Err(()),
}
}
}