Don't remove previous agent position

It might still be used by check_move
This commit is contained in:
Adrian Heine 2021-07-23 00:57:10 +02:00
parent 637bec67f8
commit 449644ade6
2 changed files with 5 additions and 5 deletions

View file

@ -1,5 +1,6 @@
pub type Distance = isize;
#[derive(Clone)]
pub struct Position {
pub x: Distance,
pub y: Distance,

View file

@ -87,6 +87,7 @@ impl ActualWorld {
self.check_move(id, &mv);
}
let mut new_pos = None;
let pos = self.state.agent_positions.get(&id).unwrap();
match mv {
Move::Noop => {}
Move::TryTag(other_id) => {
@ -94,14 +95,12 @@ impl ActualWorld {
new_state.tagged_by = Some(id);
}
Move::TryMove(dir) => {
let pos = self.state.agent_positions.get(&id).unwrap();
new_pos = Some((pos.x + dir.x, pos.y + dir.y).into());
}
}
new_state.agent_positions.insert(
id,
new_pos.unwrap_or_else(|| self.state.agent_positions.remove(&id).unwrap()),
);
new_state
.agent_positions
.insert(id, new_pos.unwrap_or_else(|| pos.clone()));
}
self.state = new_state;
}