From 69f3c48fb99d96f3fbc4ab49f5fb6d1d8e90e270 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 21 Feb 2023 14:19:34 +0300 Subject: refactor: split Board module into submodules --- src/board/piece.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/board/piece.rs (limited to 'src/board/piece.rs') diff --git a/src/board/piece.rs b/src/board/piece.rs new file mode 100644 index 0000000..1889e94 --- /dev/null +++ b/src/board/piece.rs @@ -0,0 +1,36 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)] +#[repr(usize)] +pub enum Piece { + #[default] + Pawn, + Knight, + Bishop, + Rook, + Queen, + King, + PawnBlack, + KnightBlack, + BishopBlack, + RookBlack, + QueenBlack, + KingBlack, +} + +impl Piece { + pub fn without_color(&self) -> Self { + let index = *self as usize; + Self::from(index % 6) + } + // Return the price of the peice + pub fn static_eval(&self) -> f32 { + match self.without_color() { + Piece::Pawn => 1.0, + Piece::Bishop => 3.3, + Piece::Knight => 3.2, + Piece::Rook => 5.0, + Piece::Queen => 9.0, + Piece::King => 0., + _ => panic!("Piece should be without color"), + } + } +} -- cgit v1.2.3