1use crate::types::{Board, PieceKind, Square};
2
3#[cfg_attr(feature = "flamegraph", inline(never))]
10pub fn evaluate_single_board(board: &Board) -> f32 {
11 let mut total = 0f32;
13
14 for piece in board.board.iter() {
15 if let Some(piece) = piece {
16 total += piece.side.multi() * piece_kind_to_point(piece.kind);
17 }
18 }
19
20 total
21}
22
23fn piece_kind_to_point(piece: PieceKind) -> f32 {
24 match piece {
25 PieceKind::Rook => 5f32,
26 PieceKind::Knight | PieceKind::Bishop => 3f32,
27 PieceKind::King => 99f32,
28 PieceKind::Queen => 9f32,
29 PieceKind::Pawn => 1f32,
30 PieceKind::Duck => 0f32,
31 }
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub struct BitBoard {
36 board: u64,
37}
38
39impl BitBoard {
40 pub fn new() -> Self {
41 Self { board: 0 }
42 }
43
44 #[inline]
45 pub fn set(&mut self, square: Square) {
46 self.board |= 1 << square as u8
47 }
48
49 #[inline]
50 pub fn set_val(&mut self, square: Square, val: bool) {
51 self.board |= (val as u64) << square as u8
52 }
53
54 #[inline]
55 pub const fn is_set(&self, square: Square) -> bool {
56 self.board & (1 << square as u8) > 0
57 }
58
59 #[inline]
60 pub const fn invert(&self) -> Self {
61 Self { board: !self.board }
62 }
63}