summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-07-07 12:10:42 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-07-07 12:10:42 +0200
commit352ad4a297511dfe843bad5206879983ad34f3e2 (patch)
tree5e77aa34ea23b9080eaee4885ff1129c4249aec8 /src
parentd385199c48d565d9ffc8948f137d716e534d5d0d (diff)
Cleaned up dead code
Diffstat (limited to 'src')
-rw-r--r--src/bin/benchmark.rs10
-rw-r--r--src/main.rs4
-rw-r--r--src/strategy.rs46
3 files changed, 8 insertions, 52 deletions
diff --git a/src/bin/benchmark.rs b/src/bin/benchmark.rs
index 098192c..0cee8d6 100644
--- a/src/bin/benchmark.rs
+++ b/src/bin/benchmark.rs
@@ -2,19 +2,19 @@ use std::path::Path;
use time::{Duration, PreciseTime};
-use steam_powered_wyrm::strategy::choose_move;
-use steam_powered_wyrm::json;
use steam_powered_wyrm::game;
+use steam_powered_wyrm::json;
+use steam_powered_wyrm::strategy::choose_move;
fn main() {
let max_time = Duration::milliseconds(19950);
let start_time = PreciseTime::now();
-
+
match json::read_state_from_json_file(&Path::new(&format!("./tests/example-state.json"))) {
Ok(json_state) => {
let new_board = game::GameBoard::new(json_state);
- let _ = choose_move(&new_board, None, &start_time, max_time);
- },
+ let _ = choose_move(&new_board, None, start_time, max_time);
+ }
Err(e) => {
eprintln!("WARN: State file could not be parsed: {}", e);
}
diff --git a/src/main.rs b/src/main.rs
index 00b96cf..280df8a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,7 +26,7 @@ fn main() {
None => {
let new_board = game::GameBoard::new(json_state);
let (command, cache) =
- choose_move(&new_board, strategy_cache, &start_time, max_time);
+ choose_move(&new_board, strategy_cache, start_time, max_time);
strategy_cache = Some(cache);
game_board = Some(new_board);
command
@@ -34,7 +34,7 @@ fn main() {
Some(game_board) => {
game_board.update(json_state);
let (command, cache) =
- choose_move(&game_board, strategy_cache, &start_time, max_time);
+ choose_move(&game_board, strategy_cache, start_time, max_time);
strategy_cache = Some(cache);
command
}
diff --git a/src/strategy.rs b/src/strategy.rs
index 036a620..0c86eeb 100644
--- a/src/strategy.rs
+++ b/src/strategy.rs
@@ -6,13 +6,10 @@ use std::collections::HashMap;
use std::ops::*;
use time::{Duration, PreciseTime};
-use rand;
-use rand::prelude::*;
-
pub fn choose_move(
state: &GameBoard,
previous_root: Option<Node>,
- start_time: &PreciseTime,
+ start_time: PreciseTime,
max_time: Duration,
) -> (Command, Node) {
let mut root_node = match previous_root {
@@ -205,28 +202,6 @@ fn rollout(state: &GameBoard) -> Score {
score(state)
}
-// fn rollout(state: &GameBoard) -> Score {
-// let mut s = state.clone();
-// let mut rng = rand::thread_rng();
-// while s.outcome == SimulationOutcome::Continue {
-// let player_moves = rollout_moves(&s, 0);
-// let opponent_moves = rollout_moves(&s, 1);
-
-// s.simulate([
-// player_moves
-// .choose(&mut rng)
-// .cloned()
-// .unwrap_or_else(|| Command::new(Action::DoNothing)),
-// opponent_moves
-// .choose(&mut rng)
-// .cloned()
-// .unwrap_or_else(|| Command::new(Action::DoNothing)),
-// ]);
-// }
-
-// score(&s)
-// }
-
fn choose_existing(node: &Node) -> [Command; 2] {
[choose_one_existing(node, 0), choose_one_existing(node, 1)]
}
@@ -255,25 +230,6 @@ fn update(node: &mut Node, commands: [Command; 2], score: Score) {
node.score_sum += score;
}
-fn rollout_moves(state: &GameBoard, player_index: usize) -> Vec<Command> {
- // TODO: Have this return one move, chosen randomly?
- // TODO: Heuristic based move
- valid_moves(state, player_index)
- //
- // if let Some(worm) = state.players[player_index].active_worm() {
-
- // let shoots = state.sensible_shoot_commands(player_index, worm.position, worm.weapon_range);
-
- // if !shoots.is_empty() {
- // return shoots.into_iter().collect();
- // }
-
- // 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) -> Vec<Command> {
state
.valid_shoot_commands(player_index)