Fix off-by-ones at world's end
This commit is contained in:
parent
894ebbd736
commit
9b92497c3b
2 changed files with 9 additions and 4 deletions
|
|
@ -110,7 +110,7 @@ fn random_move_within(
|
|||
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 {
|
||||
if top + y >= 0 && bottom - y >= 0 && left + x >= 0 && right - x >= 0 {
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
src/world.rs
11
src/world.rs
|
|
@ -57,7 +57,12 @@ impl ActualWorld {
|
|||
self_id: *id,
|
||||
tagged_by: self.state.tagged_by,
|
||||
tagged: self.state.tagged,
|
||||
bounds_distance: (pos.y, self.size.x - pos.x, self.size.y - pos.y, pos.x),
|
||||
bounds_distance: (
|
||||
pos.y,
|
||||
self.size.x - pos.x - 1,
|
||||
self.size.y - pos.y - 1,
|
||||
pos.x,
|
||||
),
|
||||
other_agents: &mut self
|
||||
.state
|
||||
.agent_positions
|
||||
|
|
@ -123,9 +128,9 @@ impl ActualWorld {
|
|||
assert!(dir.y.abs() <= 1);
|
||||
let pos = self.state.agent_positions.get(&id).unwrap();
|
||||
let size = &self.size;
|
||||
assert!(pos.x + dir.x > 0);
|
||||
assert!(pos.x + dir.x >= 0);
|
||||
assert!(pos.x + dir.x < size.x);
|
||||
assert!(pos.y + dir.y > 0);
|
||||
assert!(pos.y + dir.y >= 0);
|
||||
assert!(pos.y + dir.y < size.y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue