35 lines
724 B
Rust
35 lines
724 B
Rust
|
|
const dir: [(i32, i32); 4] = [(1, 0), (0, 1), (-1, 0), (0, -1)];
|
|
|
|
#[derive(Clone)]
|
|
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(&self) -> (i32, i32){
|
|
let a = dir[self.ang as usize].clone();
|
|
(a.0 + self.pos.0, a.1 + self.pos.1)
|
|
}
|
|
pub fn move_to(&mut self, pos: (i32, i32)){
|
|
self.pos = pos;
|
|
}
|
|
pub fn rotate(&mut self, a: i8){
|
|
self.ang = ((self.ang + a) % 4 + 4) % 4;
|
|
}
|
|
pub fn get_pos(&self) -> (i32, i32) {
|
|
self.pos.clone()
|
|
}
|
|
pub fn get_a(&self) -> i8 {
|
|
self.ang.clone()
|
|
}
|
|
}
|