change handling of current_depth
This commit is contained in:
parent
0d81dca8df
commit
cf21f981e5
@ -24,9 +24,6 @@ pub struct FutureMoves {
|
|||||||
/// Index of the [`Move`] tree's root node
|
/// Index of the [`Move`] tree's root node
|
||||||
current_root: Option<usize>,
|
current_root: Option<usize>,
|
||||||
|
|
||||||
/// Current generated depth of the Arena
|
|
||||||
current_depth: usize,
|
|
||||||
|
|
||||||
/// Color w.r.t
|
/// Color w.r.t
|
||||||
agent_color: Piece,
|
agent_color: Piece,
|
||||||
|
|
||||||
@ -110,7 +107,6 @@ impl FutureMoves {
|
|||||||
Self {
|
Self {
|
||||||
arena: Vec::new(),
|
arena: Vec::new(),
|
||||||
current_root: None,
|
current_root: None,
|
||||||
current_depth: 0,
|
|
||||||
agent_color,
|
agent_color,
|
||||||
config,
|
config,
|
||||||
board: Board::new(),
|
board: Board::new(),
|
||||||
@ -139,30 +135,27 @@ impl FutureMoves {
|
|||||||
indexes
|
indexes
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the current depth of the arena by
|
/// Return the current depth of the tree
|
||||||
/// looking at leaf moves and finding the smallest value
|
fn current_depth(&self) -> usize {
|
||||||
fn determine_current_depth(&self) -> Option<usize> {
|
|
||||||
// leaf_moves is sorted from min to max depth
|
// leaf_moves is sorted from min to max depth
|
||||||
self.leaf_moves().first().map(|&i| self.depth_of(i))
|
self.leaf_moves()
|
||||||
|
.first()
|
||||||
|
.map(|&i| self.depth_of(i))
|
||||||
|
.unwrap_or(0) // handle empty trees
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate children for all children of `nodes`
|
/// Generate children for all children of `nodes`
|
||||||
/// only `pub` for the sake of benchmarking
|
/// only `pub` for the sake of benchmarking
|
||||||
pub fn extend_layers(&mut self) {
|
pub fn extend_layers(&mut self) {
|
||||||
// recover from partial tree extention
|
|
||||||
if let Some(current_depth) = self.determine_current_depth() {
|
|
||||||
self.current_depth = current_depth;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut leafs = self.leaf_moves().into_iter().collect::<Vec<usize>>();
|
let mut leafs = self.leaf_moves().into_iter().collect::<Vec<usize>>();
|
||||||
|
|
||||||
for _ in self.current_depth..self.config.max_depth {
|
for _ in self.current_depth()..self.config.max_depth {
|
||||||
let pstyle_inner = if cfg!(test) || !self.config.print {
|
let pstyle_inner = if cfg!(test) || !self.config.print {
|
||||||
""
|
""
|
||||||
} else {
|
} else {
|
||||||
&format!(
|
&format!(
|
||||||
"Generating children (depth: {}/{}): ({{pos}}/{{len}}) {{per_sec}}",
|
"Generating children (depth: {}/{}): ({{pos}}/{{len}}) {{per_sec}}",
|
||||||
self.current_depth + 1,
|
self.current_depth() + 1,
|
||||||
self.config.max_depth
|
self.config.max_depth
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
@ -197,7 +190,6 @@ impl FutureMoves {
|
|||||||
let got_len = curr_size.load(Ordering::Acquire);
|
let got_len = curr_size.load(Ordering::Acquire);
|
||||||
|
|
||||||
self.prune_bad_children();
|
self.prune_bad_children();
|
||||||
self.current_depth += 1;
|
|
||||||
if got_len == allowed_size {
|
if got_len == allowed_size {
|
||||||
// arena has hit the upper limit of size permitted
|
// arena has hit the upper limit of size permitted
|
||||||
break;
|
break;
|
||||||
@ -430,7 +422,6 @@ impl FutureMoves {
|
|||||||
fn rebuild_from_board(&mut self, board: Board) {
|
fn rebuild_from_board(&mut self, board: Board) {
|
||||||
self.arena = vec![self.create_move(None, board, !self.agent_color)];
|
self.arena = vec![self.create_move(None, board, !self.agent_color)];
|
||||||
self.current_root = Some(0);
|
self.current_root = Some(0);
|
||||||
self.current_depth = 0;
|
|
||||||
self.board = board;
|
self.board = board;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +429,6 @@ impl FutureMoves {
|
|||||||
let board = self
|
let board = self
|
||||||
.get_board_from_idx(idx)
|
.get_board_from_idx(idx)
|
||||||
.expect("unable to get board at idx");
|
.expect("unable to get board at idx");
|
||||||
self.current_depth -= self.depth_of(idx);
|
|
||||||
self.current_root = Some(idx);
|
self.current_root = Some(idx);
|
||||||
self.board = board;
|
self.board = board;
|
||||||
self.refocus_tree();
|
self.refocus_tree();
|
||||||
@ -490,7 +480,7 @@ impl FutureMoves {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prune_bad_children(&mut self) {
|
fn prune_bad_children(&mut self) {
|
||||||
if self.current_depth < self.config.min_arena_depth || !self.config.do_prune {
|
if self.current_depth() < self.config.min_arena_depth || !self.config.do_prune {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +489,7 @@ impl FutureMoves {
|
|||||||
|
|
||||||
for (depth, indexes) in self.by_depth(0..self.arena.len()) {
|
for (depth, indexes) in self.by_depth(0..self.arena.len()) {
|
||||||
// TODO! maybe update by_depth every iteration or something?
|
// TODO! maybe update by_depth every iteration or something?
|
||||||
if depth > self.current_depth.saturating_sub(self.config.up_to_minus) {
|
if depth > self.current_depth().saturating_sub(self.config.up_to_minus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user