initial BoardValueMap
This commit is contained in:
parent
1fe7658deb
commit
dc9432b07b
20
src/logic/board_value.rs
Normal file
20
src/logic/board_value.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
mod board_value;
|
||||||
mod future_moves;
|
mod future_moves;
|
||||||
mod r#move;
|
mod r#move;
|
||||||
pub use future_moves::FutureMoves;
|
pub use future_moves::FutureMoves;
|
||||||
|
|||||||
@ -26,7 +26,7 @@ type ChainCollection = ArrayVec<Chain, 8>;
|
|||||||
/// Map of all points on the board against some type T
|
/// Map of all points on the board against some type T
|
||||||
/// Used to index like so: example[i][j]
|
/// Used to index like so: example[i][j]
|
||||||
/// with each coordinate
|
/// with each coordinate
|
||||||
struct PosMap<T>(ArrayVec<T, BOARD_AREA>);
|
pub struct PosMap<T>(ArrayVec<T, BOARD_AREA>);
|
||||||
|
|
||||||
impl<T> PosMap<T> {
|
impl<T> PosMap<T> {
|
||||||
pub fn get(&self, row: usize, col: usize) -> &T {
|
pub fn get(&self, row: usize, col: usize) -> &T {
|
||||||
|
|||||||
@ -3,5 +3,5 @@ mod board;
|
|||||||
mod misc;
|
mod misc;
|
||||||
mod piece;
|
mod piece;
|
||||||
|
|
||||||
pub use board::{Board, Winner};
|
pub use board::{Board, PosMap, Winner};
|
||||||
pub use piece::Piece;
|
pub use piece::Piece;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user