A simple actor-based simulation of tag, implemented 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.

42 lines
1.0 KiB

3 years ago
3 years ago
  1. use gntag::agent::{Agent, SimpleAgent};
  2. use gntag::view::TerminalView;
  3. use gntag::world::ActualWorld;
  4. fn main() {
  5. let mut view = TerminalView::try_new().unwrap();
  6. loop {
  7. let (width, height) = view.content_size().unwrap();
  8. let mut agents: Vec<(_, Box<dyn Agent>)> = vec![];
  9. for x in (0..width).step_by(10) {
  10. for y in (0..height).step_by(10) {
  11. agents.push(((x, y).into(), Box::new(SimpleAgent)));
  12. }
  13. }
  14. let mut world = ActualWorld::new((width, height).into(), agents);
  15. let mut gen = 0;
  16. loop {
  17. let resized = view
  18. .draw(
  19. gen,
  20. world
  21. .agent_positions
  22. .get(&world.tagged)
  23. .map(|pos| (pos.x, pos.y))
  24. .unwrap(),
  25. world
  26. .agent_positions
  27. .iter()
  28. .map(|(_id, pos)| (pos.x, pos.y))
  29. .collect::<Vec<_>>()
  30. .as_ref(),
  31. )
  32. .unwrap();
  33. if resized {
  34. break;
  35. };
  36. world.do_step();
  37. gen += 1;
  38. }
  39. }
  40. }