summaryrefslogtreecommitdiff
path: root/src/strategy
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-05-14 21:51:36 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-05-14 21:51:36 +0200
commit6c7eac5e5fc166759dbbf22f0ca28fd1b636de52 (patch)
treed892b7a712c7d49d8bb870eeef8eefe672d1795a /src/strategy
parent91c5c52431c894315d5ef72a7c9480b3b09d1745 (diff)
Added profiling target with perf
Diffstat (limited to 'src/strategy')
-rw-r--r--src/strategy/monte_carlo.rs13
-rw-r--r--src/strategy/sample.rs4
2 files changed, 8 insertions, 9 deletions
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index 86960eb..7e62cae 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -8,12 +8,8 @@ const MAX_MOVES: u16 = 400;
use time::{Duration, PreciseTime};
-// TODO Round start time here
-pub fn choose_move(settings: &GameSettings, state: &GameState, start_time: &PreciseTime) -> Command {
+pub fn choose_move(settings: &GameSettings, state: &GameState, start_time: &PreciseTime, max_time: Duration) -> Command {
println!("Using MONTE_CARLO strategy");
-
- //just under the max of 2 seconds, to avoid issues like overhead in the bot being run, and we still need to write the result of this to file
- let max_time = Duration::milliseconds(1950);
let mut rng = thread_rng();
let mut command_scores = CommandScore::init_command_scores(settings, state);
@@ -27,8 +23,13 @@ pub fn choose_move(settings: &GameSettings, state: &GameState, start_time: &Prec
}
}
- println!("{:#?}", command_scores);
let command = command_scores.iter().max_by_key(|&c| c.win_ratio());
+
+ #[cfg(feature = "benchmarking")]
+ {
+ let total_iterations: u32 = command_scores.iter().map(|c| c.attempts).sum();
+ println!("Iterations: {}", total_iterations);
+ }
match command {
Some(ref command) => command.command,
diff --git a/src/strategy/sample.rs b/src/strategy/sample.rs
index 72ab66c..2dad924 100644
--- a/src/strategy/sample.rs
+++ b/src/strategy/sample.rs
@@ -1,11 +1,9 @@
use engine;
use engine::command::*;
-use time::PreciseTime;
-
use rand::{thread_rng, Rng};
-pub fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState, _start_time: &PreciseTime) -> Command {
+pub fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState) -> Command {
let mut rng = thread_rng();
if state.player.can_afford_defence_buildings(settings) {