prune agent move tree (8->17 depth)
This commit is contained in:
parent
e257f81fcb
commit
9ffc6ecd01
@ -30,7 +30,7 @@ struct Move {
|
||||
|
||||
impl Move {
|
||||
fn compute_self_value(&self, agent_color: Piece, depth: usize) -> i64 {
|
||||
let mut self_value = self.board.count(agent_color) as i64;
|
||||
let mut self_value = self.value;
|
||||
|
||||
if self.winner == Some(!agent_color) {
|
||||
// if this board results in the opponent winning, MAJORLY negatively weigh this move
|
||||
@ -100,6 +100,14 @@ impl FutureMoves {
|
||||
let arena_len = self.arena.len();
|
||||
next_nodes = next_nodes
|
||||
.into_iter()
|
||||
.progress_with(
|
||||
ProgressBar::new(arena_len as u64).with_style(
|
||||
ProgressStyle::with_template(
|
||||
"Generating children: ({pos}/{len}) {per_sec}",
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
)
|
||||
.flat_map(|node_idx| {
|
||||
self.generate_children(
|
||||
Some(node_idx),
|
||||
@ -107,9 +115,6 @@ impl FutureMoves {
|
||||
next_color,
|
||||
)
|
||||
})
|
||||
.progress_with(ProgressBar::new(arena_len as u64).with_style(
|
||||
ProgressStyle::with_template("Children: ({pos}/{len}) {per_sec}").unwrap(),
|
||||
))
|
||||
.collect();
|
||||
next_color = !next_color;
|
||||
}
|
||||
@ -122,7 +127,7 @@ impl FutureMoves {
|
||||
color: Piece,
|
||||
) -> impl Iterator<Item = usize> {
|
||||
let start_idx = self.arena.len();
|
||||
self.arena.extend(
|
||||
let mut new: Vec<Move> =
|
||||
// use [`Board::all_positions`] here instead of [`Board::possible_moves`]
|
||||
// because we use [`Board::what_if`] later and we want to reduce calls to [`Board::propegate_from_dry`]
|
||||
Board::all_positions()
|
||||
@ -134,9 +139,18 @@ impl FutureMoves {
|
||||
winner: new_board.game_winner(color),
|
||||
parent,
|
||||
children: Vec::new(),
|
||||
value: 0,
|
||||
}),
|
||||
);
|
||||
value: new_board.count(self.agent_color) as i64 - new_board.count(!self.agent_color) as i64,
|
||||
}).collect();
|
||||
|
||||
// we want to keep only the best move of the agent
|
||||
if color == self.agent_color {
|
||||
if new.len() > 1 {
|
||||
new.sort_by_key(|x| x.compute_self_value(self.agent_color, 1));
|
||||
new.drain(1..);
|
||||
}
|
||||
}
|
||||
|
||||
self.arena.extend(new);
|
||||
|
||||
let new_indices = start_idx..self.arena.len();
|
||||
|
||||
@ -277,7 +291,7 @@ pub struct ComplexAgent {
|
||||
|
||||
impl ComplexAgent {
|
||||
pub const fn new(color: Piece) -> Self {
|
||||
const MAX_DEPTH: usize = 8;
|
||||
const MAX_DEPTH: usize = 17;
|
||||
const MAX_ARENA: usize = 100_000_000;
|
||||
Self {
|
||||
color,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user