initial BoardValueMap

This commit is contained in:
Simon Gardling 2025-02-20 16:19:42 -05:00
parent 1fe7658deb
commit dc9432b07b
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
4 changed files with 23 additions and 2 deletions

20
src/logic/board_value.rs Normal file
View File

@ -0,0 +1,20 @@
use crate::repr::{Board, Piece, PosMap};
pub struct BoardValueMap(PosMap<f32>);
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) {
let mut value = *self.0.get(i, j);
if pos_p != color {
// enemy has position
value = -value;
}
board_value += value;
}
}
board_value
}
}

View File

@ -1,3 +1,4 @@
mod board_value;
mod future_moves;
mod r#move;
pub use future_moves::FutureMoves;

View File

@ -26,7 +26,7 @@ type ChainCollection = ArrayVec<Chain, 8>;
/// Map of all points on the board against some type T
/// Used to index like so: example[i][j]
/// with each coordinate
struct PosMap<T>(ArrayVec<T, BOARD_AREA>);
pub struct PosMap<T>(ArrayVec<T, BOARD_AREA>);
impl<T> PosMap<T> {
pub fn get(&self, row: usize, col: usize) -> &T {

View File

@ -3,5 +3,5 @@ mod board;
mod misc;
mod piece;
pub use board::{Board, Winner};
pub use board::{Board, PosMap, Winner};
pub use piece::Piece;