Revert "Move: bit madness"

This reverts commit afa80ac597.

Only made a 3% memory decrease, Most memory is used in the children Vec
This commit is contained in:
2025-03-13 09:33:56 -04:00
parent afa80ac597
commit ed5ad738e3
5 changed files with 30 additions and 125 deletions

View File

@@ -104,9 +104,7 @@ impl FutureMoves {
// we want to select all nodes that don't have children, or are lazy (need to maybe be regenerated)
.filter(|&idx| {
let got = &self.arena[idx];
!got.data.get_trimmed()
&& !got.data.get_tried_children()
&& got.data.get_winner() == Winner::None
!got.is_trimmed && !got.tried_children && got.winner == Winner::None
})
.filter(|&idx| self.is_connected_to_root(idx))
.collect::<Vec<usize>>();
@@ -152,7 +150,7 @@ impl FutureMoves {
.progress_with_style(ProgressStyle::with_template(pstyle_inner).unwrap())
.try_for_each(|node_idx| {
self.generate_children(node_idx);
self.arena[node_idx].data.set_tried_children(true);
self.arena[node_idx].tried_children = true;
if self.arena_len() >= self.config.max_arena_size {
ControlFlow::Break(())
@@ -201,7 +199,7 @@ impl FutureMoves {
fn generate_children(&mut self, parent_idx: usize) {
let parent = &self.arena[parent_idx];
let new_color = !parent.data.get_piece();
let new_color = !parent.color;
let parent_board = self
.get_board_from_idx(parent_idx)
.expect("unable to get board");
@@ -316,7 +314,7 @@ impl FutureMoves {
}
let n = &self.arena[parent_idx];
hist.push((n.coord, n.data.get_piece()));
hist.push((n.coord, n.color));
current = n.parent;
}
hist.reverse();
@@ -357,8 +355,7 @@ impl FutureMoves {
})
.inspect(|&&x| {
assert_eq!(
self.arena[x].data.get_piece(),
self.agent_color,
self.arena[x].color, self.agent_color,
"selected move color should be the same as the color of the agent"
);
})
@@ -374,7 +371,7 @@ impl FutureMoves {
// match the agent_color usually root or great-grand child
.filter(|&idx| self.depth_of(idx) % 2 == 0)
.find(|&idx| {
self.arena[idx].data.get_piece() == !self.agent_color
self.arena[idx].color == !self.agent_color
&& self.get_board_from_idx(idx).as_ref() == Some(board)
});
@@ -473,16 +470,16 @@ impl FutureMoves {
}
// only prune moves of the agent
if indexes.first().map(|&i| self.arena[i].data.get_piece()) != Some(self.agent_color) {
if indexes.first().map(|&i| self.arena[i].color) != Some(self.agent_color) {
continue;
}
for idx in indexes {
let mut m = self.arena[idx].clone();
if m.data.get_trimmed() {
if m.is_trimmed {
continue;
}
m.data.set_trimmed(true);
m.is_trimmed = true;
m.sort_children(&self.arena);
if m.children.len() > self.config.top_k_children {
let drained = m.children.drain(self.config.top_k_children..);