Skip to content

Commit

Permalink
add convenience into_mirrored method
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Sep 1, 2024
1 parent 55a217a commit 812fd3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,23 @@ impl Board {
self.by_color.swap();
}

pub fn into_swapped_colors(mut self) -> Board {
self.swap_colors();
self
}

/// Mirror the board vertically and swap piece colors, so that the resulting
/// board is equivalent modulo color.
pub fn mirror(&mut self) {
self.flip_vertical();
self.swap_colors();
}

pub fn into_mirrored(mut self) -> Board {
self.mirror();
self
}

pub fn pop_front(&mut self) -> Option<(Square, Piece)> {
self.occupied
.first()
Expand Down
10 changes: 10 additions & 0 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ impl Setup {
self.ep_square = None;
}

pub fn into_swapped_turn(mut self) -> Setup {
self.swap_turn();
self
}

/// Mirror vertically and swap turns and all piece colors, so that the
/// resulting setup is equivalent modulo color.
///
Expand All @@ -135,6 +140,11 @@ impl Setup {
}
}

pub fn into_mirrored(mut self) -> Setup {
self.mirror();
self
}

pub fn position<P: FromSetup>(self, mode: CastlingMode) -> Result<P, PositionError<P>> {
P::from_setup(self, mode)
}
Expand Down

0 comments on commit 812fd3d

Please sign in to comment.