aboutsummaryrefslogtreecommitdiff
path: root/src/board/piece.rs
blob: 3de27caa9a698e337768fa8121420ce0ca5baceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::color::Color;

#[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)
    }

    /// Note: assumes self is without color!
    pub fn colored(&self, color: Color) -> Self {
        match color {
            Color::White => *self,
            Color::Black => Self::from(*self as usize + 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"),
        }
    }
}