Skip to content

Commit

Permalink
add Board::swap_colors (and ByColor::swap for consistency) (closes #74)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Dec 7, 2023
1 parent f6061ef commit ceaf0d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ impl Board {
self.transform(Bitboard::rotate_270);
}

/// Makes black pieces white and vice versa.
pub fn swap_colors(&mut self) {
self.by_color.swap();
}

pub fn pop_front(&mut self) -> Option<(Square, Piece)> {
self.occupied
.first()
Expand Down
7 changes: 6 additions & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ impl<T> ByColor<T> {
unsafe { &mut *(self as *mut ByColor<T>).cast::<T>().offset(color as isize) }
}

#[deprecated = "Use ByColor::swap()"]
pub fn flip(&mut self) {
self.swap();
}

pub fn swap(&mut self) {
mem::swap(&mut self.white, &mut self.black);
}

Expand Down Expand Up @@ -327,7 +332,7 @@ impl ByColor<ByRole<u8>> {
impl<T: PartialOrd> ByColor<T> {
pub fn normalize(&mut self) {
if self.white < self.black {
self.flip();
self.swap();
}
}

Expand Down

0 comments on commit ceaf0d6

Please sign in to comment.