Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a2a3937e2 | ||
|
|
a02b40c043 | ||
|
|
60bd764bcf | ||
|
|
93b0c65fed | ||
|
|
d4cfb25c8d | ||
|
|
cac35a4047 | ||
|
|
0eab202b00 | ||
|
|
125fd73625 | ||
|
|
66c0bb839e | ||
|
|
9c61078414 | ||
|
|
d9b301ea04 | ||
|
|
3663c74bd9 | ||
|
|
6f292cbb21 | ||
|
|
b09fa9e2e6 | ||
|
|
88f5f7f61a | ||
|
|
7da7d578e1 | ||
|
|
6534ed18b4 | ||
|
|
d0c051c7b1 | ||
|
|
3196347936 |
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
|
||||
+2
-2
@@ -4,6 +4,6 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
crossterm = "0.29"
|
||||
rand = "0.8"
|
||||
smallvec = "1.15"
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use std::{
|
||||
error,
|
||||
fmt::format,
|
||||
io::{Stdout, Write, stdout},
|
||||
process::Output,
|
||||
};
|
||||
|
||||
use crossterm::{
|
||||
cursor::MoveTo,
|
||||
execute, queue,
|
||||
style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor},
|
||||
terminal::{Clear, ClearType, enable_raw_mode},
|
||||
};
|
||||
|
||||
use super::Agent;
|
||||
use super::TorusGrid;
|
||||
|
||||
pub enum PosCom {
|
||||
UP,
|
||||
DW,
|
||||
LF,
|
||||
RH,
|
||||
}
|
||||
|
||||
pub struct Render {
|
||||
out: Stdout,
|
||||
rez: (usize, usize),
|
||||
pos: (i32, i32),
|
||||
}
|
||||
|
||||
impl Render {
|
||||
pub fn new() -> Self {
|
||||
Render {
|
||||
out: stdout(),
|
||||
rez: (10, 10),
|
||||
pos: (0, 0),
|
||||
}
|
||||
}
|
||||
pub fn set_rez(&mut self, a: usize, b: usize) -> Result<(), String> {
|
||||
if a == 0 || b == 0 {
|
||||
return Err("Invalid resolution\n".to_string());
|
||||
}
|
||||
self.rez = (a, b);
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_pos(&mut self, a: i32, b: i32) {
|
||||
self.pos = (a, b);
|
||||
}
|
||||
pub fn offset_pos(&mut self, a: PosCom) {
|
||||
match a {
|
||||
PosCom::LF => {
|
||||
self.pos.1 -= 1;
|
||||
}
|
||||
PosCom::UP => {
|
||||
self.pos.0 -= 1;
|
||||
}
|
||||
PosCom::DW => {
|
||||
self.pos.0 += 1;
|
||||
}
|
||||
PosCom::RH => {
|
||||
self.pos.1 += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn clear(&mut self) {
|
||||
_ = execute!(self.out, Clear(ClearType::All), MoveTo(0, 0));
|
||||
}
|
||||
pub fn print(&mut self, out_str: &str) {
|
||||
_ = execute!(self.out, Print(out_str));
|
||||
}
|
||||
pub fn print_c(&mut self, out_str: &str, c: Color) {
|
||||
_ = execute!(self.out, SetForegroundColor(c), Print(out_str), ResetColor);
|
||||
}
|
||||
pub fn print_err(&mut self, out_err: &str) {
|
||||
_ = execute!(
|
||||
self.out,
|
||||
SetForegroundColor(Color::Red),
|
||||
Print(out_err),
|
||||
ResetColor
|
||||
);
|
||||
}
|
||||
pub fn frame(&mut self, grid: &TorusGrid<bool>, a_grid: &TorusGrid<Option<usize>>) {
|
||||
let mut out = self.out.lock();
|
||||
_ = queue!(out, MoveTo(0, 0));
|
||||
for i in 0..self.rez.0 {
|
||||
for j in 0..self.rez.1 {
|
||||
let ca: Color;
|
||||
let cg: Color;
|
||||
let a = a_grid.get_wrap((i as i32 + self.pos.0, j as i32 + self.pos.1));
|
||||
let g = grid.get_wrap((i as i32 + self.pos.0, j as i32 + self.pos.1));
|
||||
let c = *g as u8 * 200;
|
||||
cg = Color::Rgb { r: c, g: c, b: c };
|
||||
if a.is_some() {
|
||||
//c = Color::Red;
|
||||
ca = Color::Red;
|
||||
} else {
|
||||
ca = cg;
|
||||
}
|
||||
_ = queue!(
|
||||
out,
|
||||
SetBackgroundColor(cg),
|
||||
SetForegroundColor(ca),
|
||||
Print("#"),
|
||||
ResetColor
|
||||
);
|
||||
}
|
||||
_ = queue!(out, Print("\r\n"));
|
||||
}
|
||||
_ = out.flush();
|
||||
self.print_c(
|
||||
&format!("pos is: {} {} \n", self.pos.1, self.pos.0),
|
||||
Color::Yellow,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
use core::error;
|
||||
use crossterm::{
|
||||
cursor::Show,
|
||||
event::{self, Event, KeyCode},
|
||||
terminal::{disable_raw_mode, enable_raw_mode},
|
||||
};
|
||||
use std::io::{self, Write, stdout};
|
||||
|
||||
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();
|
||||
let mut out = stdout();
|
||||
_ = crossterm::execute!(out, crossterm::cursor::Hide);
|
||||
return Ok(ComandEvent::Key);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(ComandEvent::None)
|
||||
}
|
||||
|
||||
pub enum KeyEvent {
|
||||
//KeuEvent for your input
|
||||
None,
|
||||
Exit,
|
||||
Comand,
|
||||
A,
|
||||
W,
|
||||
S,
|
||||
D,
|
||||
P,
|
||||
}
|
||||
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();
|
||||
let mut out = stdout();
|
||||
_ = crossterm::execute!(out, crossterm::cursor::Show);
|
||||
return Ok(Some(KeyEvent::Exit));
|
||||
}
|
||||
KeyCode::Char('c') => {
|
||||
_ = disable_raw_mode();
|
||||
let mut out = stdout();
|
||||
_ = crossterm::execute!(out, crossterm::cursor::Show);
|
||||
return Ok(Some(KeyEvent::Comand));
|
||||
}
|
||||
KeyCode::Char('a') => {
|
||||
return Ok(Some(KeyEvent::A));
|
||||
}
|
||||
KeyCode::Char('w') => {
|
||||
return Ok(Some(KeyEvent::W));
|
||||
}
|
||||
KeyCode::Char('s') => {
|
||||
return Ok(Some(KeyEvent::S));
|
||||
}
|
||||
KeyCode::Char('d') => {
|
||||
return Ok(Some(KeyEvent::D));
|
||||
}
|
||||
KeyCode::Char('p') => {
|
||||
return Ok(Some(KeyEvent::P));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(Some(KeyEvent::None))
|
||||
}
|
||||
+92
-29
@@ -1,43 +1,106 @@
|
||||
use std::{clone, sync::atomic::AtomicI32};
|
||||
|
||||
|
||||
use rand::Rng;
|
||||
mod world;
|
||||
use world::*;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, dev!");
|
||||
mod input;
|
||||
use input::*;
|
||||
|
||||
let mut ma: MagicContainer<i32> = MagicContainer::new();
|
||||
mod console_render;
|
||||
use console_render::*;
|
||||
|
||||
ma.add(2);
|
||||
ma.add(3);
|
||||
ma.add(4);
|
||||
ma.add(5);
|
||||
ma.add(6);
|
||||
enum InputType {
|
||||
comand,
|
||||
keybard,
|
||||
}
|
||||
fn main() {
|
||||
let mut rnd = rand::thread_rng();
|
||||
let mut it = InputType::comand;
|
||||
let mut R = Render::new();
|
||||
R.clear();
|
||||
_ = R.set_rez(40, 80);
|
||||
|
||||
ma.debug_log();
|
||||
let rez: (usize, usize) = (100, 100);
|
||||
let mut w = world::World::new(rez);
|
||||
|
||||
if let Err(a) = ma.rm(1) {
|
||||
println!("ERROR: {:?}", a);
|
||||
return;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ma.debug_log();
|
||||
for mut i in 0..20 {
|
||||
let x = rnd.gen_range(0..=rez.0) as i32;
|
||||
let y = rnd.gen_range(0..=rez.1) as i32;
|
||||
let a = w.add_agent(world::Agent::new(x, y, 0));
|
||||
if a.is_err() {
|
||||
R.print_err(a.err().unwrap());
|
||||
i -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(a) = ma.rm(0) {
|
||||
println!("ERROR: {:?}", a);
|
||||
loop {
|
||||
//R.clear();
|
||||
R.frame(w.get_grid(), w.get_a_grid());
|
||||
match it {
|
||||
InputType::comand => {
|
||||
R.print("Input your comand: ");
|
||||
let input = Comand_pars();
|
||||
if input.is_err() {
|
||||
R.print_err(&format!("ERROR: {}\n", input.err().unwrap()));
|
||||
} else {
|
||||
match input.unwrap() {
|
||||
ComandEvent::Exit => {
|
||||
R.print("progarm is end\n");
|
||||
return;
|
||||
}
|
||||
ComandEvent::Key => {
|
||||
R.print("jamp to keybard\n");
|
||||
it = InputType::keybard
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
InputType::keybard => {
|
||||
let input = Key_pars();
|
||||
if input.is_err() {
|
||||
R.print_err(&format!("ERROR: {}", input.err().unwrap()));
|
||||
} else {
|
||||
if let Some(k) = input.unwrap() {
|
||||
match k {
|
||||
KeyEvent::Exit => {
|
||||
R.print("progarm is end\n");
|
||||
return;
|
||||
}
|
||||
KeyEvent::Comand => {
|
||||
R.print("jamp to comand");
|
||||
it = InputType::comand
|
||||
}
|
||||
KeyEvent::A => {
|
||||
R.offset_pos(PosCom::LF);
|
||||
}
|
||||
KeyEvent::W => {
|
||||
R.offset_pos(PosCom::UP);
|
||||
}
|
||||
KeyEvent::S => {
|
||||
R.offset_pos(PosCom::DW);
|
||||
}
|
||||
|
||||
ma.debug_log();
|
||||
|
||||
|
||||
ma.add(8);
|
||||
|
||||
ma.debug_log();
|
||||
|
||||
ma.add(9);
|
||||
ma.add(10);
|
||||
ma.add(11);
|
||||
|
||||
ma.debug_log();
|
||||
KeyEvent::D => {
|
||||
R.offset_pos(PosCom::RH);
|
||||
}
|
||||
KeyEvent::P => {
|
||||
w.update();
|
||||
w.render_grid_updaete();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -28,7 +28,4 @@ impl Agent {
|
||||
pub fn get_pos(&self) -> (i32, i32) {
|
||||
self.pos.clone()
|
||||
}
|
||||
pub fn get_a(&self) -> i8 {
|
||||
self.ang.clone()
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,19 @@
|
||||
// use super::{MagicContainer, MCError};
|
||||
// use super::TorusGrid;
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[derive(PartialEq, Clone)]
|
||||
pub enum Intention {
|
||||
MoveTo,
|
||||
StakedOut,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[derive(PartialEq, Clone)]
|
||||
pub enum LocalItentoin {
|
||||
Rotate(i8),
|
||||
SwapCell((i32, i32)),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[derive(PartialEq, Clone)]
|
||||
pub struct LinkIntention<T: Clone> {
|
||||
pub it: T,
|
||||
pub lin: usize,
|
||||
|
||||
+22
-55
@@ -1,7 +1,7 @@
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
|
||||
mod grid;
|
||||
use std::{fmt::format, sync::{Arc, Mutex}};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub use grid::TorusGrid;
|
||||
|
||||
@@ -52,7 +52,10 @@ impl World {
|
||||
pub fn get_a_grid(&self) -> &TorusGrid<Option<usize>> {
|
||||
&self.a_grid
|
||||
}
|
||||
pub fn locl_itention(&self) -> Vec<LinkIntention<LocalItentoin>> {
|
||||
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() {
|
||||
@@ -68,37 +71,6 @@ impl World {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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) => {
|
||||
@@ -114,12 +86,25 @@ impl World {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut grid_it = self.grid_itention();
|
||||
|
||||
for i in 0..self.agents.len() {
|
||||
if let Some(ag) = self.agents.get(i) {
|
||||
let pos = ag.get_pos();
|
||||
let mut p = plane_of_intentions.get_mut_wrap(pos);
|
||||
p.push(LinkIntention {
|
||||
it: Intention::StakedOut,
|
||||
lin: i,
|
||||
});
|
||||
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 = grid_it.get_mut_wrap((i as i32, j as i32));
|
||||
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();
|
||||
@@ -139,22 +124,4 @@ 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