Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b565771db2 | ||
|
|
021d91d1ea | ||
|
|
6708bf5be6 | ||
|
|
7cb55a9485 |
No files matched your search
@@ -83,7 +83,7 @@ impl Render {
|
||||
}
|
||||
pub fn frame(&mut self, grid: &TorusGrid<bool>, a_grid: &TorusGrid<Option<usize>>) {
|
||||
let mut out = self.out.lock();
|
||||
_ = queue!(out, MoveTo(0, 0));
|
||||
_ = queue!(out, Clear(ClearType::All), MoveTo(0, 0));
|
||||
for i in 0..self.rez.0 {
|
||||
for j in 0..self.rez.1 {
|
||||
let ca: Color;
|
||||
|
||||
+8
-5
@@ -24,13 +24,15 @@ fn main() {
|
||||
let rez: (usize, usize) = (100, 100);
|
||||
let mut w = world::World::new(rez);
|
||||
|
||||
for i in 0..rez.0 {
|
||||
for j in 0..rez.1 {
|
||||
if let Some(a) = w.get_mut_grid().get_mut((i as i32, j as i32)) {
|
||||
*a = rnd.gen_range(0..=1) == 1;
|
||||
/*
|
||||
for i in 0..rez.0 {
|
||||
for j in 0..rez.1 {
|
||||
if let Some(a) = w.get_mut_grid().get_mut((i as i32, j as i32)) {
|
||||
*a = rnd.gen_range(0..=1) == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
for mut i in 0..20 {
|
||||
let x = rnd.gen_range(0..=rez.0) as i32;
|
||||
@@ -45,6 +47,7 @@ fn main() {
|
||||
loop {
|
||||
//R.clear();
|
||||
R.frame(w.get_grid(), w.get_a_grid());
|
||||
R.print(&w.debug());
|
||||
match it {
|
||||
InputType::comand => {
|
||||
R.print("Input your comand: ");
|
||||
|
||||
Binary file not shown.
@@ -28,4 +28,7 @@ impl Agent {
|
||||
pub fn get_pos(&self) -> (i32, i32) {
|
||||
self.pos.clone()
|
||||
}
|
||||
pub fn get_a(&self) -> i8 {
|
||||
self.ang.clone()
|
||||
}
|
||||
}
|
||||
+26
-1
@@ -1,7 +1,10 @@
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
|
||||
mod grid;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{
|
||||
fmt::format,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
pub use grid::TorusGrid;
|
||||
|
||||
@@ -124,4 +127,26 @@ impl World {
|
||||
}
|
||||
}
|
||||
}
|
||||
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