feat: implement reap and sow for direct land access

This commit is contained in:
Nat 2024-12-08 09:21:05 -08:00
parent cc392da7da
commit e224e5ebef
2 changed files with 9 additions and 1 deletions

View File

@ -62,7 +62,7 @@ fn parse_rom(path: &String) -> io::Result<(state::Land, Vec<state::Rule>, HashMa
let x_pos = rom_words.pop_front().unwrap();
let y_pos = rom_words.pop_front().unwrap();
land.map.insert((x_pos % land.width, y_pos % land.height), value);
land.sow(&(x_pos, y_pos), value);
}
println!("World\n=====");

View File

@ -83,6 +83,14 @@ impl Land {
return self.semaphores.get_mut(position).unwrap();
}
pub fn sow(&mut self, position: &(u16, u16), value: u16) {
self.map.insert((position.0 % self.width, position.1 % self.height), value);
}
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 type Rule = VecDeque<u16>;