MinMax is much better
This commit is contained in:
@@ -79,10 +79,18 @@ impl std::fmt::Display for FutureMoveConfig {
|
||||
#[allow(dead_code)]
|
||||
pub enum ChildrenEvalMethod {
|
||||
Average,
|
||||
/// AverageDivDepth gives the agent a sense of
|
||||
/// time when it comes to how far away a potential win or gain
|
||||
/// is. This performs much better in the Elo Arena than `Average`
|
||||
AverageDivDepth,
|
||||
|
||||
MinAvgDivDepth,
|
||||
|
||||
/// Best so far?
|
||||
MinMax,
|
||||
}
|
||||
|
||||
impl Default for ChildrenEvalMethod {
|
||||
fn default() -> Self {
|
||||
Self::MinMax
|
||||
}
|
||||
}
|
||||
|
||||
impl FutureMoves {
|
||||
@@ -287,6 +295,31 @@ impl FutureMoves {
|
||||
.sum::<i32>()
|
||||
.checked_div(self.arena[idx].children.len() as i32)
|
||||
.and_then(|x| x.checked_div(depth as i32)),
|
||||
ChildrenEvalMethod::MinAvgDivDepth => {
|
||||
if self.arena[idx].color == self.agent_color {
|
||||
// get best (for the adversary) enemy play
|
||||
// this assumes the adversary is playing optimally
|
||||
|
||||
children_values.into_iter().min()
|
||||
} else {
|
||||
children_values
|
||||
.into_iter()
|
||||
.sum::<i32>()
|
||||
.checked_div(self.arena[idx].children.len() as i32)
|
||||
.and_then(|x| x.checked_div(depth as i32))
|
||||
}
|
||||
}
|
||||
|
||||
ChildrenEvalMethod::MinMax => {
|
||||
if self.arena[idx].color == self.agent_color {
|
||||
// get best (for the adversary) enemy play
|
||||
// this assumes the adversary is playing optimally
|
||||
|
||||
children_values.into_iter().min()
|
||||
} else {
|
||||
children_values.into_iter().max()
|
||||
}
|
||||
}
|
||||
}
|
||||
.unwrap_or(0);
|
||||
|
||||
@@ -571,22 +604,26 @@ impl FutureMoves {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use super::*;
|
||||
|
||||
const FUTURE_MOVES_CONFIG: FutureMoveConfig = FutureMoveConfig {
|
||||
max_depth: 3, // we want great-grand children for traversing moves
|
||||
min_arena_depth: 0,
|
||||
top_k_children: 1,
|
||||
up_to_minus: 0,
|
||||
max_arena_size: 100,
|
||||
do_prune: false,
|
||||
print: false,
|
||||
children_eval_method: ChildrenEvalMethod::AverageDivDepth,
|
||||
};
|
||||
static FUTURE_MOVES_CONFIG: LazyLock<FutureMoveConfig> = LazyLock::new(|| {
|
||||
FutureMoveConfig {
|
||||
max_depth: 3, // we want great-grand children for traversing moves
|
||||
min_arena_depth: 0,
|
||||
top_k_children: 1,
|
||||
up_to_minus: 0,
|
||||
max_arena_size: 100,
|
||||
do_prune: false,
|
||||
print: false,
|
||||
children_eval_method: Default::default(),
|
||||
}
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn prune_tree_test() {
|
||||
let mut futm = FutureMoves::new(Piece::Black, FUTURE_MOVES_CONFIG);
|
||||
let mut futm = FutureMoves::new(Piece::Black, *FUTURE_MOVES_CONFIG);
|
||||
|
||||
futm.update_from_board(&Board::new());
|
||||
|
||||
@@ -628,7 +665,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn expand_layer_test() {
|
||||
let mut futm = FutureMoves::new(Piece::Black, FUTURE_MOVES_CONFIG);
|
||||
let mut futm = FutureMoves::new(Piece::Black, *FUTURE_MOVES_CONFIG);
|
||||
futm.config.max_depth = 1;
|
||||
|
||||
futm.update_from_board(&Board::STARTING_POSITION);
|
||||
@@ -653,7 +690,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn depth_of_test() {
|
||||
let mut futm = FutureMoves::new(Piece::Black, FUTURE_MOVES_CONFIG);
|
||||
let mut futm = FutureMoves::new(Piece::Black, *FUTURE_MOVES_CONFIG);
|
||||
|
||||
futm.update_from_board(&Board::new());
|
||||
|
||||
@@ -681,7 +718,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn by_depth_test() {
|
||||
let mut futm = FutureMoves::new(Piece::Black, FUTURE_MOVES_CONFIG);
|
||||
let mut futm = FutureMoves::new(Piece::Black, *FUTURE_MOVES_CONFIG);
|
||||
|
||||
futm.update_from_board(&Board::new());
|
||||
|
||||
@@ -707,7 +744,7 @@ mod tests {
|
||||
/// tests whether or not FutureMoves can recover from multiple skips and then manually regenerating the arena
|
||||
#[test]
|
||||
fn skip_move_recovery() {
|
||||
let mut futm = FutureMoves::new(Piece::Black, FUTURE_MOVES_CONFIG);
|
||||
let mut futm = FutureMoves::new(Piece::Black, *FUTURE_MOVES_CONFIG);
|
||||
let mut board = Board::STARTING_POSITION;
|
||||
|
||||
// replay of a test I did
|
||||
@@ -770,7 +807,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn derive_board() {
|
||||
let mut futm = FutureMoves::new(Piece::White, FUTURE_MOVES_CONFIG);
|
||||
let mut futm = FutureMoves::new(Piece::White, *FUTURE_MOVES_CONFIG);
|
||||
|
||||
let mut b = Board::STARTING_POSITION;
|
||||
futm.update_from_board(&b);
|
||||
@@ -838,7 +875,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
let mut futm = FutureMoves::new(Piece::White, FUTURE_MOVES_CONFIG);
|
||||
let mut futm = FutureMoves::new(Piece::White, *FUTURE_MOVES_CONFIG);
|
||||
futm.update_from_board(&board);
|
||||
futm.generate();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user