Add another sub-iterator to the PawnMoveGenerator that produces promotion pushes or capture moves (depending on move_type) when a pawn moves to the back rank. Also implement en passant moves. Fix a bug in the Left and Right captures branches where the wrong neighbors used to calculate origin squares. Add a whole bunch of tests. Still missing several cases though.
61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
// Eryn Wells <eryn@erynwells.me>
|
|
|
|
use chessfriend_core::Shape;
|
|
|
|
#[repr(u16)]
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum Kind {
|
|
Quiet = 0b0000,
|
|
DoublePush = 0b0001,
|
|
KingSideCastle = 0b0010,
|
|
QueenSideCastle = 0b0011,
|
|
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,
|
|
}
|
|
|
|
impl PromotionShape {
|
|
pub const NUM: usize = 4;
|
|
|
|
pub const ALL: [PromotionShape; PromotionShape::NUM] = [
|
|
PromotionShape::Knight,
|
|
PromotionShape::Bishop,
|
|
PromotionShape::Rook,
|
|
PromotionShape::Queen,
|
|
];
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|
|
}
|
|
|
|
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(()),
|
|
}
|
|
}
|
|
}
|