This commit is contained in:
Eryn Wells 2025-05-08 17:37:51 -07:00
parent d5cdf273c8
commit 091cc99cb3
42 changed files with 805 additions and 1662 deletions

View file

@ -7,23 +7,23 @@ use std::iter::FromIterator;
pub(crate) struct Mailbox([Option<Piece>; Square::NUM]);
impl Mailbox {
pub(crate) fn new() -> Self {
pub fn new() -> Self {
Self::default()
}
pub(crate) fn get(&self, square: Square) -> Option<Piece> {
pub fn get(&self, square: Square) -> Option<Piece> {
self.0[square as usize]
}
pub(crate) fn set(&mut self, piece: Piece, square: Square) {
pub fn set(&mut self, piece: Piece, square: Square) {
self.0[square as usize] = Some(piece);
}
pub(crate) fn remove(&mut self, square: Square) {
pub fn remove(&mut self, square: Square) {
self.0[square as usize] = None;
}
pub(crate) fn iter(&self) -> impl Iterator<Item = PlacedPiece> {
pub fn iter(&self) -> impl Iterator<Item = PlacedPiece> {
self.0
.into_iter()
.flatten() // Remove the Nones
@ -50,7 +50,7 @@ impl FromIterator<PlacedPiece> for Mailbox {
fn from_iter<T: IntoIterator<Item = PlacedPiece>>(iter: T) -> Self {
iter.into_iter()
.fold(Self::new(), |mut mailbox, placed_piece| {
mailbox.set(placed_piece.piece(), placed_piece.square());
mailbox.set(placed_piece.piece(), placed_piece.square);
mailbox
})
}