summaryrefslogtreecommitdiff
path: root/src/state.rs
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2020-04-25 12:08:49 +0200
committerJustin Wernick <justin@worthe-it.co.za>2020-04-25 12:08:49 +0200
commit52e0c74c506e2331cab8b4b118373c63cdc59364 (patch)
tree68fcf8f0de444ee70fb507acced0a9a246c0c1b9 /src/state.rs
parentbcd5a626c2f8cf0d4ea76c7d1ad50744a0753c03 (diff)
Naive shortest-path based bot
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 {