Share get_world

This commit is contained in:
Adrian Heine 2021-07-23 15:13:41 +02:00
parent 9b92497c3b
commit 1892f7e9f5
3 changed files with 18 additions and 23 deletions

View file

@ -1,3 +1,16 @@
pub mod agent;
pub mod view;
pub mod world;
use agent::{Agent, SimpleAgent};
use world::ActualWorld;
pub fn get_world(width: isize, height: isize, spacing: usize, validating: bool) -> ActualWorld {
let mut agents: Vec<(_, Box<dyn Agent>)> = vec![];
for x in (0..width).step_by(spacing) {
for y in (0..height).step_by(spacing) {
agents.push(((x, y).into(), Box::new(SimpleAgent)));
}
}
ActualWorld::new((width, height).into(), agents, validating)
}

View file

@ -1,6 +1,5 @@
use gntag::agent::{Agent, SimpleAgent};
use gntag::get_world;
use gntag::view::{Backend, TerminalView};
use gntag::world::ActualWorld;
use std::io;
use std::io::Read;
use std::process::exit;
@ -36,13 +35,7 @@ fn run_simulation(view: &Arc<Mutex<Option<TerminalView<impl Backend>>>>) {
.unwrap()
.content_size()
.unwrap();
let mut agents: Vec<(_, Box<dyn Agent>)> = vec![];
for x in (0..width).step_by(10) {
for y in (0..height).step_by(10) {
agents.push(((x, y).into(), Box::new(SimpleAgent)));
}
}
let mut world = ActualWorld::new((width, height).into(), agents, true);
let mut world = get_world(width, height, 10, true);
let mut gen = 0;
loop {