From c6b1b6857230bc4a29c4bf8ad827447b8261ab43 Mon Sep 17 00:00:00 2001 From: Vova_rs Date: Tue, 26 May 2026 12:28:00 +0300 Subject: [PATCH] intention is dote --- Cargo.toml | 3 +++ src/world/.mod.rs.kate-swp | Bin 0 -> 324 bytes src/world/agent.rs | 24 +++++++----------------- src/world/intention.rs | 23 +++++++++++++++++++++++ src/world/m_container.rs | 23 ++++++++++++++++++++++- src/world/mod.rs | 19 ++++++++++++++++++- 6 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 src/world/.mod.rs.kate-swp create mode 100644 src/world/intention.rs diff --git a/Cargo.toml b/Cargo.toml index 621c4e1..e72f758 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] +smallvec = "1.15" + + diff --git a/src/world/.mod.rs.kate-swp b/src/world/.mod.rs.kate-swp new file mode 100644 index 0000000000000000000000000000000000000000..241a0e52d426a4f942dde428206a5a064ce0830e GIT binary patch literal 324 zcmZQzU=Z?7EJ;-eE>A2_aLdd|RWQ;sU|?VnsXo|ItzGS*U)>?dK|#S4MTi3=1j0d3bsP)~3_Pf6ctG+n3{%GgvJq9C089;xhN%@`U|^7e qsI`Z { - self.pos.0 += 1; - } - 1 => { - self.pos.1 += 1; - } - 2 => { - self.pos.0 -= 1; - } - 3 => { - self.pos.1 -= 1; - } - _ => {} - } + pub fn wolk_a(&self) -> (i32, i32){ + let a = dir[self.ang as usize].clone(); + (a.0 + self.pos.0, a.1 + self.pos.1) + } + pub fn move_to(&mut self, pos: (i32, i32)){ + self.pos = pos; } pub fn rotate(&mut self, a: i8){ self.ang = ((self.ang + a) % 4 + 4) % 4; diff --git a/src/world/intention.rs b/src/world/intention.rs new file mode 100644 index 0000000..52b4663 --- /dev/null +++ b/src/world/intention.rs @@ -0,0 +1,23 @@ +// use super::Agent; +// use super::{MagicContainer, MCError}; +// use super::TorusGrid; + + +#[derive(Clone)] +pub enum Intention { + MoveTo, + StakedOut, +} + + +#[derive(Clone)] +pub enum LocalItentoin { + Rotate(i8), + SwapCell, +} + +#[derive(Clone)] +pub struct LinkIntention{ + pub it: T, + pub lin: usize, +} diff --git a/src/world/m_container.rs b/src/world/m_container.rs index 10a40fe..d7ea0ac 100644 --- a/src/world/m_container.rs +++ b/src/world/m_container.rs @@ -26,6 +26,9 @@ impl MagicContainer{ } impl MagicContainer { + pub fn len(&self) -> usize { + self.data_index.len() + } pub fn add(&mut self, value: T){ let l = self.data_index.len(); if l == self.data.len() { @@ -80,10 +83,19 @@ impl MagicContainer { Some(&self.data[index]) } + pub fn get_mut(&mut self, entity_id: usize) -> Option<&mut T> { + let index = *self.data_index.get(entity_id)?; + + if index >= self.data.len() { + return None; + } + + Some(&mut self.data[index]) + } } impl MagicContainer{ - pub fn debug(&self) { + pub fn _debug(&self) { println!("data_index: {:?}", self.data_index); println!("id: {:?}", self.id); println!("data: {:?}", self.data); @@ -101,3 +113,12 @@ impl MagicContainer{ println!("-------------------"); } } + +impl IntoIterator for MagicContainer { + type Item = T; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.data.into_iter() + } +} diff --git a/src/world/mod.rs b/src/world/mod.rs index 9f25f74..7bc1887 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -1,3 +1,5 @@ +use smallvec::{SmallVec, smallvec}; + mod grid; use std::sync::{Arc, Mutex}; @@ -9,6 +11,9 @@ pub use agent::Agent; mod m_container; pub use m_container::*; +mod intention; +pub use intention::*; + pub struct World{ grid: TorusGrid, agents: MagicContainer, @@ -47,6 +52,18 @@ impl World { pub fn get_a_grid(&self) -> &TorusGrid>{ &self.a_grid } - // pub fn + 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()); + + + } + } + } }