diff options
Diffstat (limited to 'src/game.rs')
-rw-r--r-- | src/game.rs | 34 |
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() |