agent staruct, TorusGrid derive Clone

This commit is contained in:
vova-rs committed 2026-05-15 14:16:14 +03:00
1 parent 2359187628
commit 63f2ba31d0
3 files changed
+100 -56

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
pub struct Agent{
pos: (i32, i32),
ang: i8,
}
impl Agent {
pub fn new(x: i32, y: i32, a: i8) -> Self{
Agent {
pos: (x, y),
ang: a,
}
}
pub fn wolk_a(&mut self){
match self.ang {
0 => {
self.pos.0 += 1;
}
1 => {
self.pos.1 += 1;
}
2 => {
self.pos.0 -= 1;
}
3 => {
self.pos.1 -= 1;
}
_ => {}
}
}
pub fn rotate(&mut self, a: i8){
self.ang = ((self.ang + a) % 4 + 4) % 4;
}
}