simple ant colony program written in rust i originally started with C but then started to miss data structures so I re-wrote it in rust
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
antf/tests/ai_test.rs

70 lines
1.9 KiB

use antf::lib::ai::AIGoal;
use antf::lib::entity::{Ant, Entities, Food, FoodGenerator};
use antf::lib::point::Point;
use antf::lib::screen::{init_screen, Screen};
use antf::lib::world::{render, simulate, World};
use ncurses::*;
use std::thread::sleep;
use std::time;
// make sure to run with --test-threads 1! otherwise output will be bugged
#[test]
fn test_reach_astar() {
let mut board = init_screen(); //Screen::new(40,40);
let mut world = World::new();
world.clear(Point(0, 0));
let mut entities = Entities::new();
let a = Ant::new(0, 0);
let id = entities.add_entity(&a);
let a = entities.data.get_mut(&id).unwrap();
let ant: &mut Ant = a.downcast_mut::<Ant>().unwrap();
/*ant.plan.push(AIGoal::Reach(Point(0, 0)));
ant.plan.push(AIGoal::Reach(Point(20, 20)));
ant.plan.push(AIGoal::Reach(Point(0, 0)));
ant.plan.push(AIGoal::Reach(Point(20, 20)));*/
9 months ago
// craps out... need to make sure unwrap() is safe
for t in 0..420 {
// TODO: add way to break out of the loop by hitting a random key
simulate(&mut entities, &mut world, &mut board, t);
render(&entities, &world, &board);
sleep(time::Duration::from_millis(100));
refresh();
}
clear();
endwin();
}
9 months ago
/*#[test]
fn test_drag() {
let mut board = init_screen();
9 months ago
let mut world = World::new();
let mut entities = Entities::new();
9 months ago
let f = Food::new(10,10);
let a = Ant::new(0,0);
let fid = entities.add_entity(&f);
let id = entities.add_entity(&a);
9 months ago
let a = entities.data.get_mut(&id).unwrap();
let ant: &mut Ant = a.downcast_mut::<Ant>().unwrap();
//ant.goal =
9 months ago
for _ in 0..60 {
// TODO: add way to break out of the loop by hitting a random key
simulate(&mut entities, &mut world, &mut board);
render(&entities, &world, &board);
sleep(time::Duration::from_millis(100));
refresh();
}
clear();
endwin();
9 months ago
}*/