Browse Source

Make SimpleAgent actually hunt others

main
Adrian Heine 6 months ago
parent
commit
6294d72190
  1. 33
      src/agent.rs
  2. 1
      src/main.rs

33
src/agent.rs

@ -119,12 +119,33 @@ fn random_move_within(
impl Agent for SimpleAgent {
fn next_move(&self, view: WorldView) -> Move {
if view.self_id == view.tagged {
match view
.other_agents
.iter()
.find(|(dist, id)| dist.x.abs() <= 1 && dist.y.abs() <= 1 && Some(*id) != view.tagged_by)
{
Some((_, other)) => Move::TryTag(*other),
let mut cur = None;
for (dist, id) in view.other_agents {
if Some(id) == view.tagged_by {
continue;
}
if dist.x.abs() <= 1 && dist.y.abs() <= 1 {
cur = Some((id, 0, dist));
break;
}
let total_dist = dist.x.abs() + dist.y.abs();
let cur_dist = if let Some((_, dist, _)) = cur {
dist
} else {
isize::MAX
};
if total_dist < cur_dist {
cur = Some((id, total_dist, dist));
}
}
match cur {
Some((other, total_dist, dist)) => {
if total_dist == 0 {
Move::TryTag(other)
} else {
Move::TryMove((dist.x.signum(), dist.y.signum()).into())
}
}
None => random_move_within(view.bounds_distance),
}
} else {

1
src/main.rs

@ -63,6 +63,7 @@ fn main() {
};
world.do_step();
gen += 1;
//std::thread::sleep(std::time::Duration::from_millis(500));
}
}
}
Loading…
Cancel
Save