feat: implement reap and sow for direct land access
This commit is contained in:
parent
cc392da7da
commit
e224e5ebef
|
@ -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=====");
|
||||
|
|
|
@ -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>;
|
||||
|
|
Loading…
Reference in New Issue