add local itention for agent
This commit is contained in:
1 parent
c6b1b68572
commit
d4cfb25c8d
2 files changed
+18
-14
No files matched your search
@@ -2,22 +2,20 @@
|
|||||||
// use super::{MagicContainer, MCError};
|
// use super::{MagicContainer, MCError};
|
||||||
// use super::TorusGrid;
|
// use super::TorusGrid;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Intention {
|
pub enum Intention {
|
||||||
MoveTo,
|
MoveTo,
|
||||||
StakedOut,
|
StakedOut,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum LocalItentoin {
|
pub enum LocalItentoin {
|
||||||
Rotate(i8),
|
Rotate(i8),
|
||||||
SwapCell,
|
SwapCell((i32, i32)),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct LinkIntention<T: Clone>{
|
pub struct LinkIntention<T: Clone> {
|
||||||
pub it: T,
|
pub it: T,
|
||||||
pub lin: usize,
|
pub lin: usize,
|
||||||
}
|
}
|
||||||
+16
-10
@@ -14,7 +14,7 @@ pub use m_container::*;
|
|||||||
mod intention;
|
mod intention;
|
||||||
pub use intention::*;
|
pub use intention::*;
|
||||||
|
|
||||||
pub struct World{
|
pub struct World {
|
||||||
grid: TorusGrid<bool>,
|
grid: TorusGrid<bool>,
|
||||||
agents: MagicContainer<Agent>,
|
agents: MagicContainer<Agent>,
|
||||||
a_grid: TorusGrid<Option<usize>>,
|
a_grid: TorusGrid<Option<usize>>,
|
||||||
@@ -30,7 +30,7 @@ impl World {
|
|||||||
size: s,
|
size: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_size(&self) -> (usize, usize){
|
pub fn get_size(&self) -> (usize, usize) {
|
||||||
self.size.clone()
|
self.size.clone()
|
||||||
}
|
}
|
||||||
pub fn add_agent(&mut self, ag: Agent) -> Result<(), &str> {
|
pub fn add_agent(&mut self, ag: Agent) -> Result<(), &str> {
|
||||||
@@ -43,27 +43,33 @@ impl World {
|
|||||||
*p = Some(id);
|
*p = Some(id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn get_grid(&self) -> &TorusGrid<bool>{
|
pub fn get_grid(&self) -> &TorusGrid<bool> {
|
||||||
&self.grid
|
&self.grid
|
||||||
}
|
}
|
||||||
pub fn get_mut_grid(&mut self) -> &mut TorusGrid<bool>{
|
pub fn get_mut_grid(&mut self) -> &mut TorusGrid<bool> {
|
||||||
&mut self.grid
|
&mut self.grid
|
||||||
}
|
}
|
||||||
pub fn get_a_grid(&self) -> &TorusGrid<Option<usize>>{
|
pub fn get_a_grid(&self) -> &TorusGrid<Option<usize>> {
|
||||||
&self.a_grid
|
&self.a_grid
|
||||||
}
|
}
|
||||||
pub fn update(&mut self){
|
pub fn update(&mut self) {
|
||||||
let mut plane_of_intentions: TorusGrid<SmallVec<[LinkIntention<Intention>; 4]>> = TorusGrid::new(SmallVec::new(), self.size.clone());
|
let mut plane_of_intentions: TorusGrid<SmallVec<[LinkIntention<Intention>; 4]>> =
|
||||||
|
TorusGrid::new(SmallVec::new(), self.size.clone());
|
||||||
|
|
||||||
let mut local_it: Vec<LinkIntention<LocalItentoin>> = Vec::new();
|
let mut local_it: Vec<LinkIntention<LocalItentoin>> = Vec::new();
|
||||||
|
|
||||||
for i in 0..self.agents.len() {
|
for i in 0..self.agents.len() {
|
||||||
if let Some(ag) = self.agents.get(i) {
|
if let Some(ag) = self.agents.get(i) {
|
||||||
let cell = self.grid.get_wrap(ag.get_pos());
|
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,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user