summaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-06-27 18:58:04 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-06-27 18:58:04 +0200
commit81e869d0579a257bd823f9629a1b4ec3b6a297f9 (patch)
tree11b8e2b00d32de52f122b19262cff8e7552dffc2 /src/game.rs
parent0e3548c13634e078b71c022ac49a3cea7e0c420d (diff)
Starting to allow selecting from all of the new moves
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/game.rs b/src/game.rs
index d3d6636..9423e72 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -377,8 +377,21 @@ impl GameBoard {
(player_index + 1)%2
}
+ pub fn valid_selects(&self, player_index: usize) -> ArrayVec<[i32; 2]> {
+ if self.players[player_index].select_moves > 0 {
+ self.players[player_index].worms
+ .iter()
+ .enumerate()
+ .filter(|(p, _w)| self.players[player_index].active_worm != *p)
+ .map(|(_p, w)| w.id)
+ .collect()
+ } else {
+ ArrayVec::new()
+ }
+ }
+
pub fn valid_move_commands(&self, player_index: usize) -> ArrayVec<[Command;8]> {
- // TODO: This might also involve selects
+ // TODO: Select and move
if let Some(worm) = self.players[player_index].active_worm() {
Direction::all()
.iter()
@@ -395,11 +408,24 @@ impl GameBoard {
ArrayVec::new()
}
}
+
+ pub fn valid_shoot_commands(&self) -> ArrayVec<[Command;24]> {
+ // TODO: Select and shoot
+ Direction::all()
+ .iter()
+ .map(|d| Command::new(Action::Shoot(*d)))
+ .collect()
+ }
+
+ pub fn valid_bomb_commands(&self, player_index: usize) -> Vec<Command> {
+ // TODO: Bombs
+ // TODO: Select and bomb
+ unimplemented!("TODO")
+ }
- pub fn valid_shoot_commands(&self, player_index: usize, center: Point2d<i8>, weapon_range: u8) -> ArrayVec<[Command;8]> {
- // TODO: We might also throw bombs
+ pub fn sensible_shoot_commands(&self, player_index: usize, center: Point2d<i8>, weapon_range: u8) -> ArrayVec<[Command;8]> {
let range = weapon_range as i8;
- let dir_range = ((weapon_range as f32 + 1.) / 2f32.sqrt()).floor() as i8;
+ let dir_range = ((f32::from(weapon_range) + 1.) / 2f32.sqrt()).floor() as i8;
self.players[GameBoard::opponent(player_index)].worms
.iter()