always use weighted board values
This commit is contained in:
parent
1ebfeb9f65
commit
c9fda80c81
@ -71,11 +71,9 @@ pub fn run() {
|
||||
.to_vec()
|
||||
})
|
||||
.flat_map(move |prev_c| {
|
||||
[ChildrenEvalMethod::MinMax, ChildrenEvalMethod::MinMaxFlat].map(move |method| {
|
||||
FutureMoveConfig {
|
||||
children_eval_method: method,
|
||||
..prev_c
|
||||
}
|
||||
[ChildrenEvalMethod::MinMax].map(move |method| FutureMoveConfig {
|
||||
children_eval_method: method,
|
||||
..prev_c
|
||||
})
|
||||
})
|
||||
.flat_map(move |prev_c| {
|
||||
|
||||
@ -33,10 +33,4 @@ impl BoardValueMap {
|
||||
];
|
||||
Self(PosMap::from(POSITION_VALUES))
|
||||
}
|
||||
|
||||
pub const fn flat() -> Self {
|
||||
Self(PosMap::from(
|
||||
[[1; Board::SIZE as usize]; Board::SIZE as usize],
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use super::r#move::MoveCoord;
|
||||
use super::r#move::{MoveCoord, MoveValueConfig};
|
||||
use crate::{
|
||||
logic::r#move::Move,
|
||||
repr::{Board, Piece, Winner},
|
||||
@ -92,8 +92,6 @@ impl std::fmt::Display for FutureMoveConfig {
|
||||
pub enum ChildrenEvalMethod {
|
||||
/// Best so far?
|
||||
MinMax,
|
||||
|
||||
MinMaxFlat,
|
||||
}
|
||||
|
||||
impl Default for ChildrenEvalMethod {
|
||||
@ -214,16 +212,7 @@ impl FutureMoves {
|
||||
}
|
||||
|
||||
fn create_move(&self, coord: MoveCoord, board: Board, color: Piece) -> Move {
|
||||
Move::new(
|
||||
coord,
|
||||
board,
|
||||
color,
|
||||
self.agent_color,
|
||||
!matches!(
|
||||
self.config.children_eval_method,
|
||||
ChildrenEvalMethod::MinMaxFlat
|
||||
),
|
||||
)
|
||||
Move::new(coord, board, color, self.agent_color, MoveValueConfig {})
|
||||
}
|
||||
|
||||
fn generate_children_raw(&self, parent_idx: usize) -> Vec<Move> {
|
||||
@ -299,7 +288,7 @@ impl FutureMoves {
|
||||
let by_depth_vec = self.by_depth(indexes);
|
||||
|
||||
// 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 {
|
||||
let children_values = self.arena[idx]
|
||||
.children
|
||||
@ -308,7 +297,7 @@ impl FutureMoves {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let children_value = match self.config.children_eval_method {
|
||||
ChildrenEvalMethod::MinMax | ChildrenEvalMethod::MinMaxFlat => {
|
||||
ChildrenEvalMethod::MinMax => {
|
||||
if self.arena[idx].color == self.agent_color {
|
||||
// get best (for the adversary) enemy play
|
||||
// this assumes the adversary is playing optimally
|
||||
|
||||
@ -35,13 +35,15 @@ pub struct Move {
|
||||
pub is_trimmed: bool,
|
||||
}
|
||||
|
||||
pub struct MoveValueConfig {}
|
||||
|
||||
impl Move {
|
||||
pub fn new(
|
||||
coord: MoveCoord,
|
||||
board: Board,
|
||||
color: Piece,
|
||||
agent_color: Piece,
|
||||
use_weighted_bvm: bool,
|
||||
mvc: MoveValueConfig,
|
||||
) -> Self {
|
||||
let mut m = Move {
|
||||
coord,
|
||||
@ -53,11 +55,11 @@ impl Move {
|
||||
is_trimmed: false,
|
||||
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
|
||||
}
|
||||
|
||||
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 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.
|
||||
@ -67,19 +69,10 @@ impl Move {
|
||||
// results in a win for the agent
|
||||
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,
|
||||
// because even in the case of ties, we want to have a higher score
|
||||
|
||||
match use_weighted_bvm {
|
||||
true => const { BoardValueMap::weighted() },
|
||||
false => const { BoardValueMap::flat() },
|
||||
}
|
||||
.board_value(board, agent_color)
|
||||
const { BoardValueMap::weighted() }.board_value(board, agent_color)
|
||||
}
|
||||
|
||||
/// Sort children of the [`Move`] by their self_value in `arena`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user