always use weighted board values

This commit is contained in:
Simon Gardling 2025-04-23 10:18:42 -04:00
parent 1ebfeb9f65
commit c9fda80c81
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
4 changed files with 13 additions and 39 deletions

View File

@ -71,11 +71,9 @@ pub fn run() {
.to_vec() .to_vec()
}) })
.flat_map(move |prev_c| { .flat_map(move |prev_c| {
[ChildrenEvalMethod::MinMax, ChildrenEvalMethod::MinMaxFlat].map(move |method| { [ChildrenEvalMethod::MinMax].map(move |method| FutureMoveConfig {
FutureMoveConfig { children_eval_method: method,
children_eval_method: method, ..prev_c
..prev_c
}
}) })
}) })
.flat_map(move |prev_c| { .flat_map(move |prev_c| {

View File

@ -33,10 +33,4 @@ impl BoardValueMap {
]; ];
Self(PosMap::from(POSITION_VALUES)) Self(PosMap::from(POSITION_VALUES))
} }
pub const fn flat() -> Self {
Self(PosMap::from(
[[1; Board::SIZE as usize]; Board::SIZE as usize],
))
}
} }

View File

@ -1,4 +1,4 @@
use super::r#move::MoveCoord; use super::r#move::{MoveCoord, MoveValueConfig};
use crate::{ use crate::{
logic::r#move::Move, logic::r#move::Move,
repr::{Board, Piece, Winner}, repr::{Board, Piece, Winner},
@ -92,8 +92,6 @@ impl std::fmt::Display for FutureMoveConfig {
pub enum ChildrenEvalMethod { pub enum ChildrenEvalMethod {
/// Best so far? /// Best so far?
MinMax, MinMax,
MinMaxFlat,
} }
impl Default for ChildrenEvalMethod { impl Default for ChildrenEvalMethod {
@ -214,16 +212,7 @@ impl FutureMoves {
} }
fn create_move(&self, coord: MoveCoord, board: Board, color: Piece) -> Move { fn create_move(&self, coord: MoveCoord, board: Board, color: Piece) -> Move {
Move::new( Move::new(coord, board, color, self.agent_color, MoveValueConfig {})
coord,
board,
color,
self.agent_color,
!matches!(
self.config.children_eval_method,
ChildrenEvalMethod::MinMaxFlat
),
)
} }
fn generate_children_raw(&self, parent_idx: usize) -> Vec<Move> { fn generate_children_raw(&self, parent_idx: usize) -> Vec<Move> {
@ -299,7 +288,7 @@ impl FutureMoves {
let by_depth_vec = self.by_depth(indexes); let by_depth_vec = self.by_depth(indexes);
// reversed so we build up the value of the closest (in time) moves from the future // reversed so we build up the value of the closest (in time) moves from the future
for (depth, nodes) in by_depth_vec.into_iter().rev() { for (_depth, nodes) in by_depth_vec.into_iter().rev() {
for idx in nodes { for idx in nodes {
let children_values = self.arena[idx] let children_values = self.arena[idx]
.children .children
@ -308,7 +297,7 @@ impl FutureMoves {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let children_value = match self.config.children_eval_method { let children_value = match self.config.children_eval_method {
ChildrenEvalMethod::MinMax | ChildrenEvalMethod::MinMaxFlat => { ChildrenEvalMethod::MinMax => {
if self.arena[idx].color == self.agent_color { if self.arena[idx].color == self.agent_color {
// get best (for the adversary) enemy play // get best (for the adversary) enemy play
// this assumes the adversary is playing optimally // this assumes the adversary is playing optimally

View File

@ -35,13 +35,15 @@ pub struct Move {
pub is_trimmed: bool, pub is_trimmed: bool,
} }
pub struct MoveValueConfig {}
impl Move { impl Move {
pub fn new( pub fn new(
coord: MoveCoord, coord: MoveCoord,
board: Board, board: Board,
color: Piece, color: Piece,
agent_color: Piece, agent_color: Piece,
use_weighted_bvm: bool, mvc: MoveValueConfig,
) -> Self { ) -> Self {
let mut m = Move { let mut m = Move {
coord, coord,
@ -53,11 +55,11 @@ impl Move {
is_trimmed: false, is_trimmed: false,
self_value: 0, self_value: 0,
}; };
m.self_value = m.compute_self_value(agent_color, &board, use_weighted_bvm); m.self_value = m.compute_self_value(agent_color, &board, mvc);
m m
} }
fn compute_self_value(&self, agent_color: Piece, board: &Board, use_weighted_bvm: bool) -> i16 { fn compute_self_value(&self, agent_color: Piece, board: &Board, _mvc: MoveValueConfig) -> i16 {
if self.winner == Winner::Player(!agent_color) { if self.winner == Winner::Player(!agent_color) {
// if this board results in the opponent winning, MAJORLY negatively weigh this move // if this board results in the opponent winning, MAJORLY negatively weigh this move
// NOTE! this branch isn't completely deleted because if so, the bot wouldn't make a move. // NOTE! this branch isn't completely deleted because if so, the bot wouldn't make a move.
@ -67,19 +69,10 @@ impl Move {
// results in a win for the agent // results in a win for the agent
return i16::MAX - 1; return i16::MAX - 1;
} }
// else if self.winner == Winner::Tie {
// // idk what a Tie should be valued?
// return 0;
// }
// I guess ignore Ties here, don't give them an explicit value, // I guess ignore Ties here, don't give them an explicit value,
// because even in the case of ties, we want to have a higher score
match use_weighted_bvm { const { BoardValueMap::weighted() }.board_value(board, agent_color)
true => const { BoardValueMap::weighted() },
false => const { BoardValueMap::flat() },
}
.board_value(board, agent_color)
} }
/// Sort children of the [`Move`] by their self_value in `arena` /// Sort children of the [`Move`] by their self_value in `arena`