diff --git a/core/src/shapes.rs b/core/src/shapes.rs index 0cedc7c..0fa3ab0 100644 --- a/core/src/shapes.rs +++ b/core/src/shapes.rs @@ -1,10 +1,9 @@ // Eryn Wells +use crate::{Direction, score::Score}; use std::{array, fmt, slice, str::FromStr}; use thiserror::Error; -use crate::score::Score; - #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum Shape { Pawn = 0, @@ -93,6 +92,54 @@ pub enum Slider { Queen, } +impl Slider { + pub const NUM: usize = 3; + pub const ALL: [Self; Self::NUM] = [Slider::Bishop, Slider::Rook, Slider::Queen]; + + /// Return the set of directions a slider can move. + /// + /// ## Examples + /// + /// ``` + /// use chessfriend_core::{Direction, Slider}; + /// + /// assert_eq!( + /// Slider::Bishop.ray_directions().collect::>(), + /// vec![ + /// Direction::NorthWest, + /// Direction::NorthEast, + /// Direction::SouthEast, + /// Direction::SouthWest + /// ] + /// ); + /// ``` + /// + #[must_use] + pub fn ray_directions(self) -> Box> { + match self { + Slider::Bishop => Box::new( + [ + Direction::NorthWest, + Direction::NorthEast, + Direction::SouthEast, + Direction::SouthWest, + ] + .into_iter(), + ), + Slider::Rook => Box::new( + [ + Direction::North, + Direction::East, + Direction::South, + Direction::West, + ] + .into_iter(), + ), + Slider::Queen => Box::new(Direction::ALL.into_iter()), + } + } +} + impl From for Shape { fn from(value: Slider) -> Self { match value {