feat: reconcile tree span with land at each generation

This commit is contained in:
Nat 2024-12-11 09:59:11 -08:00
parent 5db045990c
commit ca66fbc895
2 changed files with 23 additions and 0 deletions

View File

@ -134,6 +134,13 @@ fn main() -> io::Result<()> {
continue;
}
// Reconcile the tree's span with the current state of the land
for x in 0..8 {
for y in 0..8 {
tree.span[x][y] = land.get(&(x.try_into().unwrap(), y.try_into().unwrap()));
}
}
let instructions = &rules[tree.rule_id as usize];
// tree.resume_from will be 0, unless it's awoken after having to
@ -183,6 +190,18 @@ fn main() -> io::Result<()> {
instruction_pointer += 1;
}
// Update the land with the new state of every tree.
for tree_index in 0..scheduled_trees.len() {
let tree_id = &scheduled_trees[tree_index];
let tree = trees.get(tree_id).unwrap();
for x in 0..8 {
for y in 0..8 {
land.sow(&(x, y), tree.span[x as usize][y as usize]);
}
}
}
}
while let Some(tree_index) = trees_to_compost_by_index.pop_first() {

View File

@ -91,6 +91,10 @@ impl Land {
pub fn reap(&mut self, position: &(u16, u16)) -> u16 {
self.map.insert((position.0 % self.width, position.1 % self.height), 0).unwrap_or(0)
}
pub fn get(&self, position: &(u16, u16)) -> u16 {
*self.map.get(&(position.0 % self.width, position.1 % self.height)).unwrap_or(&0)
}
}
pub type Rule = VecDeque<u16>;