summaryrefslogtreecommitdiff
path: root/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/state.rs b/src/state.rs
index 0a5fd71..7cc1ab4 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -208,6 +208,25 @@ impl GameState {
}
result
}
+
+ pub fn good_moves(&self, player_index: usize) -> Vec<Command> {
+ let player = &self.players[player_index];
+ let mut result = Vec::with_capacity(7);
+ result.push(Command::Accelerate);
+ if player.position.y > MIN_Y {
+ result.push(Command::TurnLeft);
+ }
+ if player.position.y < MAX_Y - 1 {
+ result.push(Command::TurnRight);
+ }
+ if player.boosts > 0 {
+ result.push(Command::UseBoost);
+ }
+ if player.oils > 0 {
+ result.push(Command::UseOil);
+ }
+ result
+ }
}
impl Player {