summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-08-06 20:15:39 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-08-06 20:15:39 +0200
commite8b28dbbcde3d00a9d82637644734b6c7e79b544 (patch)
treef0c52dba5233fa984e00bc38d7a1cf1488490780
parent298d67d4fdb36f8fb81ad6d8e817345e3d692558 (diff)
All valid moves list into the game sim
-rw-r--r--src/game.rs13
-rw-r--r--src/strategy/mcts.rs17
-rw-r--r--src/strategy/minimax.rs14
3 files changed, 16 insertions, 28 deletions
diff --git a/src/game.rs b/src/game.rs
index 7ab7725..f49f582 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -434,8 +434,6 @@ impl GameBoard {
}
pub fn simulate_snowballs(&mut self, actions: [Action; 2]) {
- let map_clone: Map = self.map;
-
for player_index in 0..actions.len() {
if let Action::Snowball(p) = actions[player_index] {
if self.map.at(p).is_some() {
@@ -697,6 +695,17 @@ impl GameBoard {
.map(|(dir, _range)| Command::new(Action::Shoot(dir)))
.collect()
}
+
+ // TODO: Include snowball commands
+ pub fn valid_moves(&self, player_index: usize) -> Vec<Command> {
+ self.valid_shoot_commands(player_index)
+ .iter()
+ .chain(self.valid_move_commands(player_index).iter())
+ .chain(self.valid_bomb_commands(player_index).iter())
+ .chain([Command::new(Action::DoNothing)].iter())
+ .cloned()
+ .collect()
+ }
}
#[cfg(test)]
diff --git a/src/strategy/mcts.rs b/src/strategy/mcts.rs
index e393685..5a43c6e 100644
--- a/src/strategy/mcts.rs
+++ b/src/strategy/mcts.rs
@@ -164,8 +164,8 @@ fn mcts(node: &mut Node) -> Score {
}
fn mcts_move_combo(state: &GameBoard) -> Vec<[Command; 2]> {
- let player_moves = valid_moves(state, 0);
- let opponent_moves = valid_moves(state, 1);
+ let player_moves = self.valid_moves(0);
+ let opponent_moves = self.valid_moves(1);
debug_assert!(!player_moves.is_empty(), "No player moves");
debug_assert!(!opponent_moves.is_empty(), "No opponent moves");
@@ -229,15 +229,4 @@ fn update(node: &mut Node, commands: [Command; 2], score: Score) {
node.score_sum += score;
}
-// TODO: Move into game.rs
-// TODO: Include snowball commands
-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())
- .chain([Command::new(Action::DoNothing)].iter())
- .cloned()
- .collect()
-}
+
diff --git a/src/strategy/minimax.rs b/src/strategy/minimax.rs
index 8a45750..4b10014 100644
--- a/src/strategy/minimax.rs
+++ b/src/strategy/minimax.rs
@@ -283,7 +283,8 @@ fn pruned_moves(state: &GameBoard, player_index: usize) -> Vec<Command> {
let my_starting_health = state.players[player_index].health();
let opponent_starting_health = state.players[opponent_index].health();
- valid_moves(state, player_index)
+ state
+ .valid_moves(player_index)
.into_iter()
.filter(|command| {
//NB: These rules should pass for doing nothing, otherwise
@@ -300,14 +301,3 @@ fn pruned_moves(state: &GameBoard, player_index: usize) -> Vec<Command> {
})
.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())
- .chain([Command::new(Action::DoNothing)].iter())
- .cloned()
- .collect()
-}