Get en passant move building working (again?)
This commit is contained in:
parent
5d1ad73be6
commit
047eb4fd77
3 changed files with 28 additions and 16 deletions
|
@ -270,16 +270,21 @@ impl Builder<Push> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn capturing_en_passant_on(self, square: Square) -> Builder<EnPassantCapture> {
|
pub fn capturing_en_passant_on(self, square: Square) -> Builder<EnPassantCapture> {
|
||||||
|
match EnPassant::from_target_square(square) {
|
||||||
|
Some(en_passant) => {
|
||||||
let mut style = self.style;
|
let mut style = self.style;
|
||||||
style.to = Some(square);
|
style.to = Some(en_passant.target_square());
|
||||||
|
|
||||||
Builder {
|
Builder {
|
||||||
style: EnPassantCapture {
|
style: EnPassantCapture {
|
||||||
push: self.style,
|
push: style,
|
||||||
capture: Some(square),
|
capture: Some(en_passant.capture_square()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn capturing_piece(self, piece: &PlacedPiece) -> Builder<Capture> {
|
pub fn capturing_piece(self, piece: &PlacedPiece) -> Builder<Capture> {
|
||||||
Builder {
|
Builder {
|
||||||
|
|
|
@ -27,7 +27,9 @@ macro_rules! assert_flags {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn move_flags_quiet() -> Result<(), BuilderError> {
|
fn move_flags_quiet() -> Result<(), BuilderError> {
|
||||||
let mv = Builder::push(&piece!(White Pawn on A4), Square::A5).build()?;
|
let mv = Builder::push(&piece!(White Pawn on A4))
|
||||||
|
.to(Square::A5)
|
||||||
|
.build()?;
|
||||||
assert_flags!(mv, true, false, false, false, false, false);
|
assert_flags!(mv, true, false, false, false, false, false);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -57,21 +59,23 @@ fn move_flags_capture() -> Result<(), BuilderError> {
|
||||||
fn move_flags_en_passant_capture() -> Result<(), BuilderError> {
|
fn move_flags_en_passant_capture() -> Result<(), BuilderError> {
|
||||||
let mv = unsafe {
|
let mv = unsafe {
|
||||||
Builder::new()
|
Builder::new()
|
||||||
.from(Square::A5)
|
.from(Square::A4)
|
||||||
.capturing_en_passant_on(Square::B4)
|
.capturing_en_passant_on(Square::B3)
|
||||||
.build_unchecked()?
|
.build_unchecked()
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_flags!(mv, false, false, true, true, false, false);
|
assert_flags!(mv, false, false, true, true, false, false);
|
||||||
assert_eq!(mv.origin_square(), Square::A5);
|
assert_eq!(mv.origin_square(), Square::A4);
|
||||||
assert_eq!(mv.target_square(), Square::B4);
|
assert_eq!(mv.target_square(), Square::B3);
|
||||||
|
assert_eq!(mv.capture_square(), Some(Square::B4));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn move_flags_promotion() -> Result<(), BuilderError> {
|
fn move_flags_promotion() -> Result<(), BuilderError> {
|
||||||
let mv = Builder::push(&piece!(White Pawn on H7), Square::H8)
|
let mv = Builder::push(&piece!(White Pawn on H7))
|
||||||
|
.to(Square::H8)
|
||||||
.promoting_to(PromotionShape::Queen)
|
.promoting_to(PromotionShape::Queen)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
|
@ -83,7 +87,8 @@ fn move_flags_promotion() -> Result<(), BuilderError> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn move_flags_capture_promotion() -> Result<(), BuilderError> {
|
fn move_flags_capture_promotion() -> Result<(), BuilderError> {
|
||||||
let mv = Builder::push(&piece!(White Pawn on H7), Square::H8)
|
let mv = Builder::push(&piece!(White Pawn on H7))
|
||||||
|
.to(Square::H8)
|
||||||
.capturing_piece(&piece!(Black Knight on G8))
|
.capturing_piece(&piece!(Black Knight on G8))
|
||||||
.promoting_to(PromotionShape::Queen)
|
.promoting_to(PromotionShape::Queen)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
|
@ -5,7 +5,9 @@ use chessfriend_moves::{Builder, BuilderError};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pawn_push() -> Result<(), BuilderError> {
|
fn pawn_push() -> Result<(), BuilderError> {
|
||||||
let mv = Builder::push(&piece!(White Pawn on A3), Square::A4).build()?;
|
let mv = Builder::push(&piece!(White Pawn on A3))
|
||||||
|
.to(Square::A4)
|
||||||
|
.build()?;
|
||||||
|
|
||||||
assert!(mv.is_quiet());
|
assert!(mv.is_quiet());
|
||||||
assert_eq!(mv.origin_square(), Square::A3);
|
assert_eq!(mv.origin_square(), Square::A3);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue