use crate::repr::{Board, Piece, PosMap}; pub struct BoardValueMap(PosMap); impl BoardValueMap { pub fn board_value(&self, board: &Board, color: Piece) -> i64 { Board::all_positions() .filter_map(|(i, j)| board.get(i, j).map(|p| (i, j, p))) .map(|(i, j, pos_p)| (*self.0.get(i, j), pos_p)) .map(|(value, pos_p)| { if pos_p != color { // enemy has position return -value; } // target has position value }) .sum() } /// Weights from: https://repub.eur.nl/pub/7142/ei2005-47.pdf pub fn new() -> Self { let mut map = PosMap::new(); assert_eq!( Board::BOARD_SIZE, 8, "BVM only supports Board::BOARD_SIZE of 8" ); const POSITION_VALUES: [[i64; 8]; 8] = [ [100, -20, 10, 5, 5, 10, -20, 100], [-20, -50, -2, -2, -2, -2, -50, -20], [10, -2, -1, -1, -1, -1, -2, 10], [5, -2, -1, -1, -1, -1, -2, 5], [5, -2, -1, -1, -1, -1, -2, 5], [10, -2, -1, -1, -1, -1, -2, 10], [-20, -50, -2, -2, -2, -2, -50, -20], [100, -20, 10, 5, 5, 10, -20, 100], ]; for (i, j) in Board::all_positions() { map.set(i, j, POSITION_VALUES[i][j]) } Self(map) } }