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.

47 lines
891 B

3 years ago
3 years ago
3 years ago
  1. use gntag::{get_view, get_world, DefaultView};
  2. fn main() {
  3. let view = get_view();
  4. loop {
  5. run_simulation(&view);
  6. }
  7. }
  8. fn run_simulation(view: &DefaultView) {
  9. let (width, height) = (*view.lock().unwrap())
  10. .as_mut()
  11. .unwrap()
  12. .content_size()
  13. .unwrap();
  14. let mut world = get_world(width, height, 10, true);
  15. let mut gen = 0;
  16. loop {
  17. let resized = (*view.lock().unwrap())
  18. .as_mut()
  19. .unwrap()
  20. .draw(
  21. gen,
  22. world
  23. .state
  24. .agent_positions
  25. .get(&world.state.tagged)
  26. .map(|pos| (pos.x, pos.y))
  27. .unwrap(),
  28. world
  29. .state
  30. .agent_positions
  31. .iter()
  32. .map(|(_id, pos)| (pos.x, pos.y))
  33. .collect::<Vec<_>>()
  34. .as_ref(),
  35. )
  36. .unwrap();
  37. if resized {
  38. return;
  39. };
  40. world.do_step();
  41. gen += 1;
  42. }
  43. }