From a02b40c0436a9478e575815e7704fd6e5aa3b8ff Mon Sep 17 00:00:00 2001 From: lemon-cat Date: Wed, 27 May 2026 12:48:31 +0300 Subject: [PATCH] relese global intention --- src/world/intention.rs | 10 +++++----- src/world/mod.rs | 24 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) 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()); + } + } + } + } } }