intention is dote

This commit is contained in:
vova-rs committed 2026-05-26 12:28:00 +03:00
1 parent 580894ed0a
commit c6b1b68572
6 files changed
+73 -19

No files matched your search

+3
View File
@@ -4,3 +4,6 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
smallvec = "1.15"
Binary file not shown.
+7 -17
View File
@@ -1,5 +1,5 @@
const dir: [(i32, i32); 4] = [(1, 0), (0, 1), (-1, 0), (0, -1)];
#[derive(Clone)] #[derive(Clone)]
pub struct Agent{ pub struct Agent{
@@ -15,22 +15,12 @@ impl Agent {
ang: a, ang: a,
} }
} }
pub fn wolk_a(&mut self){ pub fn wolk_a(&self) -> (i32, i32){
match self.ang { let a = dir[self.ang as usize].clone();
0 => { (a.0 + self.pos.0, a.1 + self.pos.1)
self.pos.0 += 1; }
} pub fn move_to(&mut self, pos: (i32, i32)){
1 => { self.pos = pos;
self.pos.1 += 1;
}
2 => {
self.pos.0 -= 1;
}
3 => {
self.pos.1 -= 1;
}
_ => {}
}
} }
pub fn rotate(&mut self, a: i8){ pub fn rotate(&mut self, a: i8){
self.ang = ((self.ang + a) % 4 + 4) % 4; self.ang = ((self.ang + a) % 4 + 4) % 4;
+23
View File
@@ -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<T: Clone>{
pub it: T,
pub lin: usize,
}
+22 -1
View File
@@ -26,6 +26,9 @@ impl<T: Clone> MagicContainer<T>{
} }
impl<T> MagicContainer<T> { impl<T> MagicContainer<T> {
pub fn len(&self) -> usize {
self.data_index.len()
}
pub fn add(&mut self, value: T){ pub fn add(&mut self, value: T){
let l = self.data_index.len(); let l = self.data_index.len();
if l == self.data.len() { if l == self.data.len() {
@@ -80,10 +83,19 @@ impl<T> MagicContainer<T> {
Some(&self.data[index]) 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<T: Debug> MagicContainer<T>{ impl<T: Debug> MagicContainer<T>{
pub fn debug(&self) { pub fn _debug(&self) {
println!("data_index: {:?}", self.data_index); println!("data_index: {:?}", self.data_index);
println!("id: {:?}", self.id); println!("id: {:?}", self.id);
println!("data: {:?}", self.data); println!("data: {:?}", self.data);
@@ -101,3 +113,12 @@ impl<T: Debug> MagicContainer<T>{
println!("-------------------"); println!("-------------------");
} }
} }
impl<T> IntoIterator for MagicContainer<T> {
type Item = T;
type IntoIter = std::vec::IntoIter<T>;
fn into_iter(self) -> Self::IntoIter {
self.data.into_iter()
}
}
+18 -1
View File
@@ -1,3 +1,5 @@
use smallvec::{SmallVec, smallvec};
mod grid; mod grid;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@@ -9,6 +11,9 @@ pub use agent::Agent;
mod m_container; mod m_container;
pub use m_container::*; pub use m_container::*;
mod intention;
pub use intention::*;
pub struct World{ pub struct World{
grid: TorusGrid<bool>, grid: TorusGrid<bool>,
agents: MagicContainer<Agent>, agents: MagicContainer<Agent>,
@@ -47,6 +52,18 @@ impl World {
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 pub fn update(&mut self){
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();
for i in 0..self.agents.len() {
if let Some(ag) = self.agents.get(i) {
let cell = self.grid.get_wrap(ag.get_pos());
}
}
}
} }