|
@ -119,12 +119,33 @@ fn random_move_within( |
|
|
impl Agent for SimpleAgent {
|
|
|
impl Agent for SimpleAgent {
|
|
|
fn next_move(&self, view: WorldView) -> Move {
|
|
|
fn next_move(&self, view: WorldView) -> Move {
|
|
|
if view.self_id == view.tagged {
|
|
|
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),
|
|
|
None => random_move_within(view.bounds_distance),
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
} else {
|
|
|