Skip to content

Commit

Permalink
provide Board::{is_empty,first,last}
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Jan 4, 2025
1 parent a5e70fd commit ff7b332
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,23 @@ impl Board {
self
}

#[inline]
pub fn is_empty(&self) -> bool {
self.occupied.is_empty()
}

pub fn first(&self) -> Option<(Square, Piece)> {
self.occupied
.first()
.and_then(|sq| self.piece_at(sq).map(|piece| (sq, piece)))
}

pub fn last(&self) -> Option<(Square, Piece)> {
self.occupied
.last()
.and_then(|sq| self.piece_at(sq).map(|piece| (sq, piece)))
}

pub fn pop_front(&mut self) -> Option<(Square, Piece)> {
self.occupied
.first()
Expand Down Expand Up @@ -532,6 +549,10 @@ impl Iterator for IntoIter {
let len = self.len();
(len, Some(len))
}

fn last(self) -> Option<(Square, Piece)> {
self.inner.last()
}
}

impl ExactSizeIterator for IntoIter {
Expand Down

0 comments on commit ff7b332

Please sign in to comment.