|
|
@ -103,6 +103,18 @@ fn random_move() -> Move { |
|
|
|
.into(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
fn random_move_within(
|
|
|
|
(top, right, bottom, left): (Distance, Distance, Distance, Distance),
|
|
|
|
) -> Move {
|
|
|
|
loop {
|
|
|
|
let mv = random_move();
|
|
|
|
if let Move::TryMove(Direction { x, y }) = mv {
|
|
|
|
if top + y > 0 && bottom - y > 0 && left + x > 0 && right - x > 0 {
|
|
|
|
return mv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Agent for SimpleAgent {
|
|
|
|
fn next_move(&self, view: WorldView) -> Move {
|
|
|
@ -113,10 +125,10 @@ impl Agent for SimpleAgent { |
|
|
|
.find(|(dist, id)| dist.x.abs() <= 1 && dist.y.abs() <= 1 && Some(*id) != view.tagged_by)
|
|
|
|
{
|
|
|
|
Some((_, other)) => Move::TryTag(*other),
|
|
|
|
None => random_move(),
|
|
|
|
None => random_move_within(view.bounds_distance),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
random_move()
|
|
|
|
random_move_within(view.bounds_distance)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|