2024-02-09 20:00:47 -08:00
|
|
|
// Eryn Wells <eryn@erynwells.me>
|
|
|
|
|
|
|
|
use chessfriend_core::Shape;
|
|
|
|
|
2025-05-19 14:19:05 -07:00
|
|
|
#[repr(u16)]
|
2025-05-08 17:37:51 -07:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
2025-05-19 14:19:05 -07:00
|
|
|
pub enum Kind {
|
2024-02-10 18:33:13 -07:00
|
|
|
Quiet = 0b0000,
|
|
|
|
DoublePush = 0b0001,
|
|
|
|
KingSideCastle = 0b0010,
|
|
|
|
QueenSideCastle = 0b0011,
|
2024-02-09 20:00:47 -08:00
|
|
|
Capture = 0b0100,
|
|
|
|
EnPassantCapture = 0b0101,
|
|
|
|
Promotion = 0b1000,
|
|
|
|
CapturePromotion = 0b1100,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(u16)]
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
|
|
pub enum PromotionShape {
|
|
|
|
Knight = 0b00,
|
|
|
|
Bishop = 0b01,
|
|
|
|
Rook = 0b10,
|
|
|
|
Queen = 0b11,
|
|
|
|
}
|
|
|
|
|
2025-05-24 18:01:14 -07:00
|
|
|
impl PromotionShape {
|
|
|
|
pub const NUM: usize = 4;
|
|
|
|
|
|
|
|
pub const ALL: [PromotionShape; PromotionShape::NUM] = [
|
|
|
|
PromotionShape::Knight,
|
|
|
|
PromotionShape::Bishop,
|
|
|
|
PromotionShape::Rook,
|
|
|
|
PromotionShape::Queen,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-02-09 20:00:47 -08:00
|
|
|
impl From<PromotionShape> for Shape {
|
|
|
|
fn from(value: PromotionShape) -> Self {
|
|
|
|
match value {
|
|
|
|
PromotionShape::Knight => Shape::Knight,
|
|
|
|
PromotionShape::Bishop => Shape::Bishop,
|
|
|
|
PromotionShape::Rook => Shape::Rook,
|
|
|
|
PromotionShape::Queen => Shape::Queen,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-05-08 17:37:51 -07:00
|
|
|
|
|
|
|
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(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|