This commit is contained in:
Simon Gardling 2025-03-03 23:50:11 -05:00
parent d48670dbdb
commit e8521ac96d
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 54 additions and 23 deletions

View File

@ -17,16 +17,12 @@ pub fn run() {
min_arena_depth: 14,
top_k_children: 2,
up_to_minus: 10,
max_arena_size: usize::MAX,
max_arena_size: 1_000_000,
do_not_prune: true,
print: false,
};
let mut arena = PlayerArena::new(vec![
// (
// "RandomAgent".into(),
// Box::new(|piece| Box::new(RandomAgent::new(piece))),
// ),
(
"ComplexAgentD1".into(),
Box::new(|piece| {
@ -39,6 +35,18 @@ pub fn run() {
))
}),
),
(
"ComplexAgentD2".into(),
Box::new(|piece| {
Box::new(ComplexAgent::new(
piece,
FutureMoveConfig {
max_depth: 2,
..FMV_BASE
},
))
}),
),
(
"ComplexAgentD3".into(),
Box::new(|piece| {
@ -52,24 +60,24 @@ pub fn run() {
}),
),
(
"ComplexAgentD8".into(),
"ComplexAgentD4".into(),
Box::new(|piece| {
Box::new(ComplexAgent::new(
piece,
FutureMoveConfig {
max_depth: 8,
max_depth: 4,
..FMV_BASE
},
))
}),
),
// (
// "ComplexAgent5M".into(),
// "ComplexAgentD8".into(),
// Box::new(|piece| {
// Box::new(ComplexAgent::new(
// piece,
// FutureMoveConfig {
// max_arena_size: 5_000_000,
// max_depth: 8,
// ..FMV_BASE
// },
// ))
@ -77,17 +85,9 @@ pub fn run() {
// ),
]);
// arena.play(
// &(0..arena.players.len())
// .zip([0].into_iter().cycle())
// .filter(|(i, j)| i != j)
// .collect::<Vec<_>>()
// .repeat(1000),
// );
for _ in 0..10 {
arena.prop_arena(2);
arena.prop_arena(1000);
println!("{}", arena);
}
}
pub struct PlayerArena {
@ -176,8 +176,13 @@ impl PlayerArena {
}
fn play_two_inner(player_1: Box<dyn Agent>, player_2: Box<dyn Agent>) -> Outcomes {
let result =
GameInner::new(player_1, player_2, false, Board::random(5)).loop_until_result();
let result = GameInner::new(
player_1,
player_2,
false,
Board::random(rand::random_range(3..8)),
)
.loop_until_result();
match result {
Winner::Player(piece) => match piece {

View File

@ -123,13 +123,39 @@ impl FutureMoves {
});
self.prune_bad_children();
self.current_depth += 1;
if cf.is_break() {
// pruning unfinished level
let by_depth = self.by_depth(0..self.arena.len());
let mut bdh = HashMap::new();
for (a, b) in by_depth {
bdh.insert(a, b);
}
for &i in bdh.get(&(self.current_depth + 1)).unwrap_or(&Vec::new()) {
self.remove(i);
}
for &i in bdh.get(&self.current_depth).unwrap_or(&Vec::new()) {
self.arena[i].tried_children = false;
}
self.refocus_tree();
return;
}
self.current_depth += 1;
}
}
fn remove(&mut self, index: usize) {
if let Some(parent) = self.arena[index].parent {
self.arena[parent].children.retain(|&j| j != index);
}
self.arena[index].parent = None;
}
/// Determines if a [`Move`] at index `idx` is connected to `self.current_root`
/// Returns `false` if `self.current_root` is None
fn is_connected_to_root(&self, idx: usize) -> bool {