Browse Source

Don't remove previous agent position

It might still be used by check_move
main
Adrian Heine 3 years ago
parent
commit
449644ade6
  1. 1
      src/agent.rs
  2. 9
      src/world.rs

1
src/agent.rs

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

9
src/world.rs

@ -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;
}

Loading…
Cancel
Save