[board] Add a test for capturing en passant; fix the bugs

I wrote a test for capturing en passant that revealed some bugs. Cool!

Implement the missing part of move validation that checks for an en passant move.
Implement PositionBuilder::to_move() to set player_to_move.

The most difficult part of this fix was finding the logic error in
Move::is_en_passant(). Instead of checking for non-zero, check for equality against
the en passant flag value. Checking for non-zero was causing this method to return
true in the double push case.
This commit is contained in:
Eryn Wells 2024-01-21 11:21:37 -08:00
parent 683d89b726
commit f90ea2d1be
3 changed files with 69 additions and 3 deletions

View file

@ -193,7 +193,7 @@ impl Move {
}
pub fn is_en_passant(&self) -> bool {
(self.0 & 0b0101) != 0
(self.0 & 0b0101) == 0b0101
}
pub fn is_promotion(&self) -> bool {
@ -272,6 +272,11 @@ impl MoveBuilder {
self
}
pub fn capturing_en_passant(mut self, captured_piece: PlacedPiece) -> Self {
self.kind = Kind::EnPassantCapture(captured_piece);
self
}
pub fn promoting_to(mut self, shape: Shape) -> Self {
if let Some(shape) = PromotableShape::try_from(shape).ok() {
self.kind = match self.kind {