diff --git a/src/world/intention.rs b/src/world/intention.rs index 52b4663..b48f4b9 100644 --- a/src/world/intention.rs +++ b/src/world/intention.rs @@ -2,22 +2,20 @@ // use super::{MagicContainer, MCError}; // use super::TorusGrid; - #[derive(Clone)] pub enum Intention { MoveTo, StakedOut, } - #[derive(Clone)] pub enum LocalItentoin { Rotate(i8), - SwapCell, + SwapCell((i32, i32)), } #[derive(Clone)] -pub struct LinkIntention{ +pub struct LinkIntention { pub it: T, pub lin: usize, } diff --git a/src/world/mod.rs b/src/world/mod.rs index 7bc1887..f2f1d64 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -14,7 +14,7 @@ pub use m_container::*; mod intention; pub use intention::*; -pub struct World{ +pub struct World { grid: TorusGrid, agents: MagicContainer, a_grid: TorusGrid>, @@ -26,11 +26,11 @@ impl World { World { grid: TorusGrid::new(false, s), agents: MagicContainer::new(), - a_grid: TorusGrid::new(None, s), + a_grid: TorusGrid::new(None, s), size: s, } } - pub fn get_size(&self) -> (usize, usize){ + pub fn get_size(&self) -> (usize, usize) { self.size.clone() } pub fn add_agent(&mut self, ag: Agent) -> Result<(), &str> { @@ -43,27 +43,33 @@ impl World { *p = Some(id); Ok(()) } - pub fn get_grid(&self) -> &TorusGrid{ + pub fn get_grid(&self) -> &TorusGrid { &self.grid } - pub fn get_mut_grid(&mut self) -> &mut TorusGrid{ + pub fn get_mut_grid(&mut self) -> &mut TorusGrid { &mut self.grid } - pub fn get_a_grid(&self) -> &TorusGrid>{ + pub fn get_a_grid(&self) -> &TorusGrid> { &self.a_grid } - pub fn update(&mut self){ - let mut plane_of_intentions: TorusGrid; 4]>> = TorusGrid::new(SmallVec::new(), self.size.clone()); + pub fn update(&mut self) { + let mut plane_of_intentions: TorusGrid; 4]>> = + TorusGrid::new(SmallVec::new(), self.size.clone()); let mut local_it: Vec> = Vec::new(); for i in 0..self.agents.len() { if let Some(ag) = self.agents.get(i) { let cell = self.grid.get_wrap(ag.get_pos()); - - + local_it.push(LinkIntention { + it: LocalItentoin::Rotate((-1 * *cell as i8) + (1 * !*cell as i8)), + lin: i, + }); + local_it.push(LinkIntention { + it: LocalItentoin::SwapCell(ag.get_pos()), + lin: i, + }); } } } } -