Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b09fa9e2e6 | ||
|
|
88f5f7f61a |
No files matched your search
@@ -1,71 +0,0 @@
|
|||||||
[33mcommit 6708bf5be66910315c0081ca08fe1d64ef320e97[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mdev-world[m[33m)[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Sat May 30 14:14:22 2026 +0300
|
|
||||||
|
|
||||||
debug fn
|
|
||||||
|
|
||||||
[33mcommit 7cb55a9485b9e0c9a352dc15ee0cb3e77fca7c77[m[33m ([m[1;31morigin/dev-world[m[33m)[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Sat May 30 13:45:13 2026 +0300
|
|
||||||
|
|
||||||
actual world merge
|
|
||||||
|
|
||||||
[33mcommit c6b1b6857230bc4a29c4bf8ad827447b8261ab43[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Tue May 26 12:28:00 2026 +0300
|
|
||||||
|
|
||||||
intention is dote
|
|
||||||
|
|
||||||
[33mcommit 580894ed0a6fafe5d0b6c8b2364c81fc9b2eeaf3[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Fri May 22 12:37:41 2026 +0300
|
|
||||||
|
|
||||||
m_container: is done
|
|
||||||
|
|
||||||
[33mcommit 25af75b381fa022dd7b89c3c31fcef53c085904f[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Fri May 15 17:33:20 2026 +0300
|
|
||||||
|
|
||||||
refactor add_agent
|
|
||||||
|
|
||||||
[33mcommit f9842f635b1cb88e40b6f0415d5844e4390d5988[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Fri May 15 16:06:03 2026 +0300
|
|
||||||
|
|
||||||
add fn add_agent(), temporary mutable access privileges in Word
|
|
||||||
|
|
||||||
[33mcommit 63f2ba31d0445c9a47e01e24944d327c28091284[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Fri May 15 14:16:14 2026 +0300
|
|
||||||
|
|
||||||
agent staruct, TorusGrid derive Clone
|
|
||||||
|
|
||||||
[33mcommit 23591876282ed1b189ae37df1a873f2f30d5d6aa[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Thu May 14 14:50:48 2026 +0300
|
|
||||||
|
|
||||||
fix: add pub to TorusGrid
|
|
||||||
|
|
||||||
[33mcommit 1bca11eb4cec723ee296d3e702b83aec875f35f0[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Thu May 14 13:25:39 2026 +0300
|
|
||||||
|
|
||||||
TorusGrid: был завершон
|
|
||||||
|
|
||||||
[33mcommit 7067e3985c079fde0533aa8c170b98c95907d5b2[m[33m ([m[1;31morigin/vova-rs[m[33m, [m[1;31morigin/dev[m[33m, [m[1;32mdev[m[33m)[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Mon May 11 16:15:42 2026 +0300
|
|
||||||
|
|
||||||
hello
|
|
||||||
|
|
||||||
[33mcommit b6f74c160c8559648edd74c31e5edd1189377173[m[33m ([m[1;31morigin/main[m[33m, [m[1;31morigin/HEAD[m[33m, [m[1;32mmain[m[33m)[m
|
|
||||||
Author: Vova_rs <kolesnik2019v.s@gmail.com>
|
|
||||||
Date: Mon May 11 15:30:33 2026 +0300
|
|
||||||
|
|
||||||
caro init & gitignire set
|
|
||||||
|
|
||||||
[33mcommit 226ef5838b075f284aeb41d137ecfadbb476de2b[m
|
|
||||||
Author: vova-rs <1+vova-rs@noreply.localhost>
|
|
||||||
Date: Mon May 11 14:23:13 2026 +0200
|
|
||||||
|
|
||||||
Initial commit
|
|
||||||
+1
-3
@@ -4,6 +4,4 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
smallvec = "1.15"
|
crossterm = "0.29"
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
use core::error;
|
||||||
|
use crossterm::{
|
||||||
|
event::{self, Event, KeyCode},
|
||||||
|
terminal::{disable_raw_mode, enable_raw_mode},
|
||||||
|
};
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
use crate::input;
|
||||||
|
|
||||||
|
pub enum ComandEvent {
|
||||||
|
//who is this
|
||||||
|
None,
|
||||||
|
Exit,
|
||||||
|
Key,
|
||||||
|
}
|
||||||
|
pub fn Comand_pars() -> Result<ComandEvent, String> {
|
||||||
|
let mut input = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut input)
|
||||||
|
.expect("error input scan\n");
|
||||||
|
let mut words: Vec<&str> = input.trim().split(" ").collect();
|
||||||
|
if words.len() == 0 {
|
||||||
|
return Err(String::from("Zerro lenth comand\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
match words[0] {
|
||||||
|
"q" => {
|
||||||
|
return Ok(ComandEvent::Exit);
|
||||||
|
}
|
||||||
|
"key" => {
|
||||||
|
_ = enable_raw_mode();
|
||||||
|
return Ok(ComandEvent::Key);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(ComandEvent::None)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum KeyEvent {
|
||||||
|
//KeuEvent for your input
|
||||||
|
None,
|
||||||
|
Exit,
|
||||||
|
Comand,
|
||||||
|
}
|
||||||
|
pub fn Key_pars() -> Result<Option<KeyEvent>, std::io::Error> {
|
||||||
|
if let Event::Key(key) = event::read()? {
|
||||||
|
match key.code {
|
||||||
|
KeyCode::Char('q') => {
|
||||||
|
_ = disable_raw_mode();
|
||||||
|
return Ok(Some(KeyEvent::Exit));
|
||||||
|
}
|
||||||
|
KeyCode::Char('c') => {
|
||||||
|
_ = disable_raw_mode();
|
||||||
|
return Ok(Some(KeyEvent::Comand));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Some(KeyEvent::None))
|
||||||
|
}
|
||||||
+47
-37
@@ -1,43 +1,53 @@
|
|||||||
|
mod input;
|
||||||
|
use input::*;
|
||||||
mod world;
|
enum Input_type {
|
||||||
use world::*;
|
comand,
|
||||||
|
keybard,
|
||||||
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, dev!");
|
println!("Hello, world!");
|
||||||
|
let mut it = Input_type::comand;
|
||||||
let mut ma: MagicContainer<i32> = MagicContainer::new();
|
loop {
|
||||||
|
match it {
|
||||||
ma.add(2);
|
Input_type::comand => {
|
||||||
ma.add(3);
|
println!("input your comand: ");
|
||||||
ma.add(4);
|
let input = Comand_pars();
|
||||||
ma.add(5);
|
if input.is_err() {
|
||||||
ma.add(6);
|
println!("ERROR: {}", input.err().unwrap());
|
||||||
|
} else {
|
||||||
ma.debug_log();
|
match input.unwrap() {
|
||||||
|
ComandEvent::Exit => {
|
||||||
if let Err(a) = ma.rm(1) {
|
println!("progarm is end");
|
||||||
println!("ERROR: {:?}", a);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ComandEvent::Key => {
|
||||||
ma.debug_log();
|
println!("jamp to keybard");
|
||||||
|
it = Input_type::keybard
|
||||||
if let Err(a) = ma.rm(0) {
|
}
|
||||||
println!("ERROR: {:?}", a);
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Input_type::keybard => {
|
||||||
|
let input = Key_pars();
|
||||||
|
if input.is_err() {
|
||||||
|
println!("ERROR: {}", input.err().unwrap())
|
||||||
|
} else {
|
||||||
|
if let Some(k) = input.unwrap() {
|
||||||
|
match k {
|
||||||
|
KeyEvent::Exit => {
|
||||||
|
println!("progarm is end");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
KeyEvent::Comand => {
|
||||||
ma.debug_log();
|
println!("jamp to comand");
|
||||||
|
it = Input_type::comand
|
||||||
|
}
|
||||||
ma.add(8);
|
_ => {}
|
||||||
|
}
|
||||||
ma.debug_log();
|
}
|
||||||
|
}
|
||||||
ma.add(9);
|
}
|
||||||
ma.add(10);
|
}
|
||||||
ma.add(11);
|
}
|
||||||
|
|
||||||
ma.debug_log();
|
|
||||||
}
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
|
|
||||||
const dir: [(i32, i32); 4] = [(1, 0), (0, 1), (-1, 0), (0, -1)];
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Agent{
|
|
||||||
pos: (i32, i32),
|
|
||||||
ang: i8,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Agent {
|
|
||||||
pub fn new(x: i32, y: i32, a: i8) -> Self{
|
|
||||||
Agent {
|
|
||||||
pos: (x, y),
|
|
||||||
ang: a,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
pub fn get_pos(&self) -> (i32, i32) {
|
|
||||||
self.pos.clone()
|
|
||||||
}
|
|
||||||
pub fn get_a(&self) -> i8 {
|
|
||||||
self.ang.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
fn wrap_pos(p: (i32, i32), s: (usize, usize)) -> (usize, usize) {
|
|
||||||
let x = ((p.0 % s.0 as i32 + s.0 as i32) % s.0 as i32) as usize;
|
|
||||||
let y = ((p.1 % s.1 as i32 + s.1 as i32) % s.1 as i32) as usize;
|
|
||||||
|
|
||||||
(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct TorusGrid<T: Clone>{
|
|
||||||
vec: Vec<T>,
|
|
||||||
size: (usize, usize),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Clone> TorusGrid<T> {
|
|
||||||
pub fn new(value: T, s: (usize, usize)) -> Self{
|
|
||||||
let v = vec![value; s.0 * s.1];
|
|
||||||
TorusGrid {
|
|
||||||
vec: v,
|
|
||||||
size: s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn index(&self, x: usize, y: usize) -> usize {
|
|
||||||
y * self.size.0 + x
|
|
||||||
}
|
|
||||||
pub fn if_in_grid(&self, s: (i32, i32)) -> bool{
|
|
||||||
if s.0 < 0 || s.0 > self.size.0 as i32 - 1{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if s.1 < 0 || s.1 > self.size.1 as i32 - 1{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
pub fn get(&self, s: (i32, i32)) -> Option<&T> {
|
|
||||||
if self.if_in_grid(s) {
|
|
||||||
return Some(&self.vec[self.index(s.0 as usize, s.1 as usize)]);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
pub fn get_mut(&mut self, s: (i32, i32)) -> Option<&mut T> {
|
|
||||||
if self.if_in_grid(s) {
|
|
||||||
let idx = self.index(s.0 as usize, s.1 as usize);
|
|
||||||
return Some(&mut self.vec[idx]);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
pub fn get_wrap(&self, p: (i32, i32)) -> &T {
|
|
||||||
let a = wrap_pos(p, self.size);
|
|
||||||
&self.vec[self.index(a.0, a.1)]
|
|
||||||
}
|
|
||||||
pub fn get_mut_wrap(&mut self, p: (i32, i32)) -> &mut T {
|
|
||||||
let a = wrap_pos(p, self.size);
|
|
||||||
let idx = self.index(a.0, a.1);
|
|
||||||
&mut self.vec[idx]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
// use super::Agent;
|
|
||||||
// use super::{MagicContainer, MCError};
|
|
||||||
// use super::TorusGrid;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
|
||||||
pub enum Intention {
|
|
||||||
MoveTo,
|
|
||||||
StakedOut,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
|
||||||
pub enum LocalItentoin {
|
|
||||||
Rotate(i8),
|
|
||||||
SwapCell((i32, i32)),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
|
||||||
pub struct LinkIntention<T: Clone> {
|
|
||||||
pub it: T,
|
|
||||||
pub lin: usize,
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum MCError {
|
|
||||||
BrocenLen,
|
|
||||||
EntityNotExisit,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub struct MagicContainer<T>{
|
|
||||||
data_index: Vec<usize>,
|
|
||||||
id: Vec<usize>,
|
|
||||||
data: Vec<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Clone> MagicContainer<T>{
|
|
||||||
pub fn new() -> Self {
|
|
||||||
MagicContainer {
|
|
||||||
data_index: Vec::new(),
|
|
||||||
id: Vec::new(),
|
|
||||||
data: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> MagicContainer<T> {
|
|
||||||
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() {
|
|
||||||
self.data_index.push(l);
|
|
||||||
self.id.push(l);
|
|
||||||
self.data.push(value);
|
|
||||||
} else if l > self.data.len() {
|
|
||||||
self.data.push(value);
|
|
||||||
} else {
|
|
||||||
panic!("data_index < data");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn add_and_id(&mut self, value: T) -> usize{
|
|
||||||
let l = self.data_index.len();
|
|
||||||
if l == self.data.len() {
|
|
||||||
self.data_index.push(l);
|
|
||||||
self.id.push(l);
|
|
||||||
self.data.push(value);
|
|
||||||
} else if l > self.data.len() {
|
|
||||||
self.data.push(value);
|
|
||||||
} else {
|
|
||||||
panic!("data_index < data");
|
|
||||||
}
|
|
||||||
|
|
||||||
self.id[self.data.len() -1]
|
|
||||||
}
|
|
||||||
pub fn rm(&mut self, entity_id: usize) -> Result<(), MCError>{
|
|
||||||
let index = self.data_index[entity_id];
|
|
||||||
let last = self.data.len() - 1;
|
|
||||||
|
|
||||||
if self.data.len() > self.data_index.len() {
|
|
||||||
return Err(MCError::BrocenLen);
|
|
||||||
}
|
|
||||||
if index > last {
|
|
||||||
return Err(MCError::EntityNotExisit);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.id.swap(last, index);
|
|
||||||
self.data.swap(last, index);
|
|
||||||
self.data_index[self.id[index]] = index;
|
|
||||||
self.data_index[self.id[last]] = last;
|
|
||||||
self.data.pop();
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub fn get(&self, entity_id: usize) -> Option<&T> {
|
|
||||||
let index = *self.data_index.get(entity_id)?;
|
|
||||||
|
|
||||||
if index >= self.data.len() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
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>{
|
|
||||||
pub fn _debug(&self) {
|
|
||||||
println!("data_index: {:?}", self.data_index);
|
|
||||||
println!("id: {:?}", self.id);
|
|
||||||
println!("data: {:?}", self.data);
|
|
||||||
}
|
|
||||||
pub fn debug_log(&self){
|
|
||||||
println!("--- access test ---");
|
|
||||||
|
|
||||||
for id in 0..self.data_index.len() {
|
|
||||||
match self.get(id) {
|
|
||||||
Some(v) => println!("ID {} => {:?}", id, v),
|
|
||||||
None => println!("ID {} => <deleted>", id),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
use smallvec::{SmallVec, smallvec};
|
|
||||||
|
|
||||||
mod grid;
|
|
||||||
use std::{fmt::format, sync::{Arc, Mutex}};
|
|
||||||
|
|
||||||
pub use grid::TorusGrid;
|
|
||||||
|
|
||||||
mod agent;
|
|
||||||
pub use agent::Agent;
|
|
||||||
|
|
||||||
mod m_container;
|
|
||||||
pub use m_container::*;
|
|
||||||
|
|
||||||
mod intention;
|
|
||||||
pub use intention::*;
|
|
||||||
|
|
||||||
pub struct World {
|
|
||||||
grid: TorusGrid<bool>,
|
|
||||||
agents: MagicContainer<Agent>,
|
|
||||||
a_grid: TorusGrid<Option<usize>>,
|
|
||||||
size: (usize, usize),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl World {
|
|
||||||
pub fn new(s: (usize, usize)) -> Self {
|
|
||||||
World {
|
|
||||||
grid: TorusGrid::new(false, s),
|
|
||||||
agents: MagicContainer::new(),
|
|
||||||
a_grid: TorusGrid::new(None, s),
|
|
||||||
size: s,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn get_size(&self) -> (usize, usize) {
|
|
||||||
self.size.clone()
|
|
||||||
}
|
|
||||||
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.is_some() {
|
|
||||||
return Err("ERROR: pos занято");
|
|
||||||
}
|
|
||||||
let id = self.agents.add_and_id(ag);
|
|
||||||
*p = Some(id);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub fn get_grid(&self) -> &TorusGrid<bool> {
|
|
||||||
&self.grid
|
|
||||||
}
|
|
||||||
pub fn get_mut_grid(&mut self) -> &mut TorusGrid<bool> {
|
|
||||||
&mut self.grid
|
|
||||||
}
|
|
||||||
pub fn get_a_grid(&self) -> &TorusGrid<Option<usize>> {
|
|
||||||
&self.a_grid
|
|
||||||
}
|
|
||||||
pub fn locl_itention(&self) -> Vec<LinkIntention<LocalItentoin>> {
|
|
||||||
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());
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local_it
|
|
||||||
}
|
|
||||||
pub fn grid_itention(&self) -> TorusGrid<SmallVec<[LinkIntention<Intention>; 4]>> {
|
|
||||||
let mut grid_it: TorusGrid<SmallVec<[LinkIntention<Intention>; 4]>> =
|
|
||||||
TorusGrid::new(SmallVec::new(), self.size.clone());
|
|
||||||
|
|
||||||
for i in 0..self.agents.len() {
|
|
||||||
if let Some(ag) = self.agents.get(i) {
|
|
||||||
let pos = ag.get_pos();
|
|
||||||
let mut p = grid_it.get_mut_wrap(pos);
|
|
||||||
p.push(LinkIntention {
|
|
||||||
it: Intention::StakedOut,
|
|
||||||
lin: i,
|
|
||||||
});
|
|
||||||
let mv = ag.wolk_a();
|
|
||||||
p = grid_it.get_mut_wrap(mv);
|
|
||||||
p.push(LinkIntention {
|
|
||||||
it: Intention::MoveTo,
|
|
||||||
lin: i,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
grid_it
|
|
||||||
}
|
|
||||||
pub fn update(&mut self) {
|
|
||||||
|
|
||||||
|
|
||||||
let mut local_it = self.locl_itention();
|
|
||||||
|
|
||||||
for i in 0..local_it.len() {
|
|
||||||
match local_it[i].it {
|
|
||||||
LocalItentoin::Rotate(r) => {
|
|
||||||
if let Some(ag) = self.agents.get_mut(local_it[i].lin) {
|
|
||||||
ag.rotate(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LocalItentoin::SwapCell(cell) => {
|
|
||||||
let g = self.get_mut_grid();
|
|
||||||
if let Some(s) = g.get_mut(cell) {
|
|
||||||
*s = !*s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut grid_it = self.grid_itention();
|
|
||||||
|
|
||||||
for i in 0..self.size.0 {
|
|
||||||
for j in 0..self.size.1 {
|
|
||||||
let cell = grid_it.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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn render_grid_updaete(&mut self) {
|
|
||||||
self.a_grid = TorusGrid::new(None, self.size);
|
|
||||||
for i in 0..self.agents.len() {
|
|
||||||
if let Some(ag) = self.agents.get(i) {
|
|
||||||
let pos = ag.get_pos();
|
|
||||||
let cell = self.a_grid.get_mut_wrap(pos);
|
|
||||||
*cell = Some(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn debug_a(&self, n: usize) -> Option<String> {
|
|
||||||
if let Some(a) = self.agents.get(n) {
|
|
||||||
return Some(format!("pos: {:?}, ang: {:?}, id: {n}", a.get_pos(), a.get_a()));
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
pub fn debug(&self) -> String {
|
|
||||||
let mut a: String = String::new();
|
|
||||||
for i in 0..self.agents.len() {
|
|
||||||
if let Some(t) = self.debug_a(i) {
|
|
||||||
a.push_str(&t);
|
|
||||||
} else {
|
|
||||||
a.push_str("None\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
a
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user