diff --git a/src/world/intention.rs b/src/world/intention.rs index dfd8156..c5daf42 100644 --- a/src/world/intention.rs +++ b/src/world/intention.rs @@ -2,19 +2,19 @@ // use super::{MagicContainer, MCError}; // use super::TorusGrid; -#[derive(Clone)] +#[derive(PartialEq, Clone)] pub enum Intention { - MoveTo((i32, i32)), - StakedOut((i32, i32)), + MoveTo, + StakedOut, } -#[derive(Clone)] +#[derive(PartialEq, Clone)] pub enum LocalItentoin { Rotate(i8), SwapCell((i32, i32)), } -#[derive(Clone)] +#[derive(PartialEq, Clone)] pub struct LinkIntention { pub it: T, pub lin: usize, diff --git a/src/world/mod.rs b/src/world/mod.rs index 941a7a8..2d29a36 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -86,18 +86,32 @@ impl World { } } } - let mut global_it: Vec> = Vec::new(); for i in 0..self.agents.len() { if let Some(ag) = self.agents.get(i) { - global_it.push(LinkIntention { - it: Intention::MoveTo(ag.wolk_a()), + let pos = ag.get_pos(); + let mut p = plane_of_intentions.get_mut_wrap(pos); + p.push(LinkIntention { + it: Intention::StakedOut, lin: i, }); - global_it.push(LinkIntention { - it: Intention::StakedOut(ag.get_pos()), + let mv = ag.wolk_a(); + p = plane_of_intentions.get_mut_wrap(mv); + p.push(LinkIntention { + it: Intention::MoveTo, lin: i, }); } } + for i in 0..self.size.0 { + for j in 0..self.size.1 { + let cell = plane_of_intentions.get_mut_wrap((i as i32, j as i32)); + if cell.len() == 1 { + if cell[0].it == Intention::MoveTo { + let ag = self.agents.get_mut(cell[0].lin).unwrap(); + ag.move_to(ag.wolk_a()); + } + } + } + } } }