diff --git a/board/src/piece.rs b/board/src/piece.rs index 26eeeb0..873c3c0 100644 --- a/board/src/piece.rs +++ b/board/src/piece.rs @@ -2,6 +2,7 @@ use crate::Square; use std::fmt; +use std::slice::Iter; #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum Color { @@ -33,16 +34,24 @@ pub enum Shape { } impl Shape { - pub fn iter() -> impl Iterator { - [ + pub fn iter() -> Iter<'static, Shape> { + const ALL_SHAPES: [Shape; 6] = [ Shape::Pawn, Shape::Knight, Shape::Bishop, Shape::Rook, Shape::Queen, Shape::King, - ] - .into_iter() + ]; + + ALL_SHAPES.iter() + } + + pub fn promotable() -> Iter<'static, Shape> { + const PROMOTABLE_SHAPES: [Shape; 4] = + [Shape::Queen, Shape::Rook, Shape::Bishop, Shape::Knight]; + + PROMOTABLE_SHAPES.iter() } fn _ascii_representation(&self) -> char { diff --git a/board/src/position/pieces.rs b/board/src/position/pieces.rs index 99c500e..a8772e8 100644 --- a/board/src/position/pieces.rs +++ b/board/src/position/pieces.rs @@ -11,7 +11,7 @@ pub struct Pieces<'a> { current_shape: Option, - shape_iterator: Box>, + shape_iterator: Box>, square_iterator: Option>>, } @@ -41,7 +41,7 @@ impl<'a> Iterator for Pieces<'a> { let mut next_nonempty_bitboard: Option<&BitBoard> = None; while let Some(shape) = self.shape_iterator.next() { - let piece = Piece::new(self.color, shape); + let piece = Piece::new(self.color, *shape); let bitboard = self.position.bitboard_for_piece(piece); if bitboard.is_empty() { @@ -49,7 +49,7 @@ impl<'a> Iterator for Pieces<'a> { } next_nonempty_bitboard = Some(bitboard); - current_shape = Some(shape); + current_shape = Some(*shape); break; } diff --git a/board/src/position/position.rs b/board/src/position/position.rs index 9d09c4a..c9334bd 100644 --- a/board/src/position/position.rs +++ b/board/src/position/position.rs @@ -129,7 +129,7 @@ impl Position { pub fn piece_on_square(&self, sq: Square) -> Option { for color in Color::iter() { for shape in Shape::iter() { - let piece = Piece::new(color, shape); + let piece = Piece::new(color, *shape); let bb = self.bitboard_for_piece(piece); if bb.has_piece_at(&sq) { return Some(PlacedPiece::new(piece, sq));