summaryrefslogtreecommitdiff
path: root/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/state.rs b/src/state.rs
index 87f73f5..25594a0 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -16,7 +16,8 @@ pub enum GameStatus {
pub struct GameState {
pub status: GameStatus,
pub players: [Player; 2],
- pub obstacles: Rc<BTreeSet<Position>>,
+ pub muds: Rc<BTreeSet<Position>>,
+ pub oil_spills: Rc<BTreeSet<Position>>,
pub powerup_oils: Rc<BTreeSet<Position>>,
pub powerup_boosts: Rc<BTreeSet<Position>>,
}
@@ -37,6 +38,7 @@ pub struct Position {
}
impl GameState {
+ // TODO: Return metadata on what each bot did from this
pub fn update(&mut self, commands: [Command; 2]) {
if self.status != GameStatus::Continue {
return;
@@ -93,12 +95,12 @@ impl GameState {
debug_assert!(self.players[player_index].oils > 0);
self.players[player_index].oils = self.players[player_index].oils.saturating_sub(1);
let player_position = self.players[player_index].position;
- let mut obstacles = (*self.obstacles).clone();
- obstacles.insert(Position {
+ let mut oil_spills = (*self.oil_spills).clone();
+ oil_spills.insert(Position {
x: player_position.x.saturating_sub(1),
y: player_position.y,
});
- self.obstacles = Rc::new(obstacles);
+ self.oil_spills = Rc::new(oil_spills);
}
}
@@ -159,7 +161,8 @@ impl GameState {
for (player, next_position) in self.players.iter_mut().zip(next_positions.iter()) {
player.move_along(
*next_position,
- &self.obstacles,
+ &self.muds,
+ &self.oil_spills,
&self.powerup_oils,
&self.powerup_boosts,
);
@@ -247,7 +250,8 @@ impl Player {
fn move_along(
&mut self,
next_position: Position,
- obstacles: &BTreeSet<Position>,
+ muds: &BTreeSet<Position>,
+ oil_spills: &BTreeSet<Position>,
powerup_oils: &BTreeSet<Position>,
powerup_boosts: &BTreeSet<Position>,
) {
@@ -262,7 +266,10 @@ impl Player {
}),
);
- for _ in obstacles.range(range) {
+ for _ in muds.range(range) {
+ self.decelerate_from_obstacle();
+ }
+ for _ in oil_spills.range(range) {
self.decelerate_from_obstacle();
}
self.oils = self