summaryrefslogtreecommitdiff
path: root/src/strategy.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/strategy.rs')
-rw-r--r--src/strategy.rs32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/strategy.rs b/src/strategy.rs
index 46cb2cd..502e9f2 100644
--- a/src/strategy.rs
+++ b/src/strategy.rs
@@ -8,7 +8,6 @@ use time::{Duration, PreciseTime};
use rand;
use rand::prelude::*;
-use arrayvec::ArrayVec;
pub fn choose_move(state: &GameBoard, previous_root: Option<Node>, start_time: &PreciseTime, max_time: Duration) -> (Command, Node) {
let mut root_node = match previous_root {
@@ -244,7 +243,7 @@ fn update(node: &mut Node, commands: [Command; 2], score: Score) {
node.score_sum += score;
}
-fn rollout_moves(state: &GameBoard, player_index: usize) -> ArrayVec<[Command; 8]> {
+fn rollout_moves(state: &GameBoard, player_index: usize) -> Vec<Command> {
// TODO: Have this return one move, chosen randomly?
// TODO: Allow new select / bomb moves
if let Some(worm) = state.players[player_index].active_worm() {
@@ -252,31 +251,20 @@ fn rollout_moves(state: &GameBoard, player_index: usize) -> ArrayVec<[Command; 8
let shoots = state.sensible_shoot_commands(player_index, worm.position, worm.weapon_range);
if !shoots.is_empty() {
- return shoots;
+ return shoots.into_iter().collect();
}
- state.valid_move_commands(player_index)
+ state.valid_move_commands(player_index).into_iter().collect()
} else {
[Command::new(Action::DoNothing)].into_iter().cloned().collect()
}
}
-fn valid_moves(state: &GameBoard, player_index: usize) -> ArrayVec<[Command; 17]> {
- // TODO: Move / Dig, Shoot, Bomb, Select to another worm and repeat
- // 24 move/digs
- // 24 shoots
- // 109 bombs (sub those out of range)
- // 1 nothing
- // TOTAL: 158 possible moves
- if let Some(worm) = state.players[player_index].active_worm() {
-
- state.valid_shoot_commands()
- .iter()
- .chain(state.valid_move_commands(player_index).iter())
- .chain(state.valid_bomb_commands(player_index).iter())
- .cloned()
- .collect()
- } else {
- [Command::new(Action::DoNothing)].into_iter().cloned().collect()
- }
+fn valid_moves(state: &GameBoard, player_index: usize) -> Vec<Command> {
+ state.valid_shoot_commands(player_index)
+ .iter()
+ .chain(state.valid_move_commands(player_index).iter())
+ .chain(state.valid_bomb_commands(player_index).iter())
+ .cloned()
+ .collect()
}