initial BVM usage (halfs performance :( )
This commit is contained in:
@@ -1,20 +1,33 @@
|
||||
use crate::repr::{Board, Piece, PosMap};
|
||||
|
||||
pub struct BoardValueMap(PosMap<f32>);
|
||||
pub struct BoardValueMap(PosMap<i8>);
|
||||
|
||||
impl BoardValueMap {
|
||||
pub fn board_value(&self, board: &Board, color: Piece) -> f32 {
|
||||
let mut board_value: f32 = 0.0;
|
||||
for (i, j) in Board::all_positions() {
|
||||
if let Some(pos_p) = board.get(i, j) {
|
||||
pub fn board_value(&self, board: &Board, color: Piece) -> i8 {
|
||||
Board::all_positions()
|
||||
.filter_map(|(i, j)| board.get(i, j).map(|p| (i, j, p)))
|
||||
.map(|(i, j, pos_p)| {
|
||||
let mut value = *self.0.get(i, j);
|
||||
if pos_p != color {
|
||||
// enemy has position
|
||||
value = -value;
|
||||
}
|
||||
board_value += value;
|
||||
}
|
||||
value
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
let mut map = PosMap::new();
|
||||
|
||||
for (i, j) in Board::all_positions() {
|
||||
map.set(i, j, 1);
|
||||
}
|
||||
board_value
|
||||
|
||||
for (i, j) in Board::sides() {
|
||||
map.set(i, j, 4);
|
||||
}
|
||||
|
||||
Self(map)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user