Fix the remaining tests

Well… all the tests except the Peter Ellis Jones tests.

Pass around whole EnPassant types instead of pulling out just the e.p. square.
Make sure that Castling moves have their target and origin squares populated.
Add a color field to the Castle move style to make this possible.
This commit is contained in:
Eryn Wells 2024-02-25 12:38:55 -08:00
parent d2fe546824
commit 5f1fce6cc2
10 changed files with 142 additions and 83 deletions

View file

@ -72,7 +72,7 @@ pub struct Capture {
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EnPassantCapture {
push: Push,
capture: Option<Square>,
capture: Option<EnPassant>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@ -83,9 +83,16 @@ pub struct Promotion<S> {
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Castle {
color: Color,
castle: castle::Castle,
}
impl EnPassantCapture {
fn _build_move_bits(&self, origin_square: Square, target_square: Square) -> u16 {
(origin_square as u16 & 0b111111) << 4 | (target_square as u16 & 0b111111) << 10
}
}
impl Style for Null {}
impl Style for Push {
@ -108,7 +115,17 @@ impl Style for Capture {
}
}
impl Style for Castle {}
impl Style for Castle {
fn origin_square(&self) -> Option<Square> {
let parameters = self.castle.parameters(self.color);
Some(parameters.king_origin_square())
}
fn target_square(&self) -> Option<Square> {
let parameters = self.castle.parameters(self.color);
Some(parameters.king_target_square())
}
}
impl Style for DoublePush {
fn origin_square(&self) -> Option<Square> {
@ -143,12 +160,6 @@ impl Style for EnPassantCapture {
}
}
impl EnPassantCapture {
fn _build_move_bits(&self, origin_square: Square, target_square: Square) -> u16 {
(origin_square as u16 & 0b111111) << 4 | (target_square as u16 & 0b111111) << 10
}
}
impl Style for Promotion<Push> {
fn origin_square(&self) -> Option<Square> {
self.style.from
@ -236,9 +247,9 @@ impl Builder<Null> {
}
}
pub fn castling(castle: castle::Castle) -> Builder<Castle> {
pub fn castling(color: Color, castle: castle::Castle) -> Builder<Castle> {
Builder {
style: Castle { castle },
style: Castle { color, castle },
}
}
@ -283,8 +294,8 @@ impl Builder<Push> {
}
}
pub fn capturing_en_passant_on(&self, square: Square) -> Builder<EnPassantCapture> {
match EnPassant::from_target_square(square) {
pub fn capturing_en_passant_on(&self, target_square: Square) -> Builder<EnPassantCapture> {
match EnPassant::from_target_square(target_square) {
Some(en_passant) => {
let mut style = self.style.clone();
style.to = Some(en_passant.target_square());
@ -292,7 +303,7 @@ impl Builder<Push> {
Builder {
style: EnPassantCapture {
push: style,
capture: Some(en_passant.capture_square()),
capture: Some(en_passant),
},
}
}
@ -333,8 +344,8 @@ impl Builder<Castle> {
bits as u16
}
pub fn build(&self) -> Move {
Move(self.bits())
pub fn build(&self) -> Result {
Ok(Move(self.bits() | self.style.into_move_bits()?))
}
}

View file

@ -101,7 +101,7 @@ fn move_flags_capture_promotion() -> TestResult {
#[test]
fn move_flags_castle() -> TestResult {
let mv = Builder::castling(Castle::KingSide).build();
let mv = Builder::castling(Color::White, Castle::KingSide).build()?;
assert_flags!(mv, false, false, false, false, true, false);