m_container: is done

This commit is contained in:
vova-rs committed 2026-05-22 12:37:41 +03:00
1 parent 25af75b381
commit 580894ed0a
4 files changed
+149 -10

No files matched your search

+10 -10
View File
@@ -6,10 +6,13 @@ pub use grid::TorusGrid;
mod agent;
pub use agent::Agent;
mod m_container;
pub use m_container::*;
pub struct World{
grid: TorusGrid<bool>,
agents: Vec<Arc<Mutex<Agent>>>,
a_grid: TorusGrid<Option<Arc<Mutex<Agent>>>>,
agents: MagicContainer<Agent>,
a_grid: TorusGrid<Option<usize>>,
size: (usize, usize),
}
@@ -17,7 +20,7 @@ impl World {
pub fn new(s: (usize, usize)) -> Self {
World {
grid: TorusGrid::new(false, s),
agents: Vec::new(),
agents: MagicContainer::new(),
a_grid: TorusGrid::new(None, s),
size: s,
}
@@ -28,15 +31,11 @@ impl World {
pub fn add_agent(&mut self, ag: Agent) -> Result<(), &str> {
let pos = ag.get_pos();
let p = self.a_grid.get_mut_wrap(pos);
// if *p != None {
// return Err("w");
// }
if p.is_some() {
return Err("ERROR: pos занято");
}
let rec_ag = Arc::new(Mutex::new(ag));
self.agents.push(Arc::clone(&rec_ag));
*p = Some(Arc::clone(&rec_ag));
let id = self.agents.add_and_id(ag);
*p = Some(id);
Ok(())
}
pub fn get_grid(&self) -> &TorusGrid<bool>{
@@ -45,8 +44,9 @@ impl World {
pub fn get_mut_grid(&mut self) -> &mut TorusGrid<bool>{
&mut self.grid
}
pub fn get_a_grid(&self) -> &TorusGrid<Option<Arc<Mutex<Agent>>>>{
pub fn get_a_grid(&self) -> &TorusGrid<Option<usize>>{
&self.a_grid
}
// pub fn
}