summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-06-02 13:09:13 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-06-02 13:09:13 +0200
commitbb208dfdebb7dead0e7d68e837c37972498c22d5 (patch)
treebca12d92b906ea0da68cfc8b12f270176604dbe6 /src
parenta81a55fd129b947c347284e271d4c6b214c51068 (diff)
Moved replay-based test to have convenience import from game engine replay
Diffstat (limited to 'src')
-rw-r--r--src/engine/command.rs7
-rw-r--r--src/strategy/monte_carlo.rs4
2 files changed, 9 insertions, 2 deletions
diff --git a/src/engine/command.rs b/src/engine/command.rs
index 17dbd5a..b350d65 100644
--- a/src/engine/command.rs
+++ b/src/engine/command.rs
@@ -29,4 +29,11 @@ impl BuildingType {
use self::BuildingType::*;
[Defence, Attack, Energy]
}
+
+ fn count() -> u8 { BuildingType::Energy as u8 + 1 }
+ pub fn from_u8(id: u8) -> Option<BuildingType> {
+ use std::mem;
+ if id < Self::count() { Some(unsafe { mem::transmute(id) }) } else { None }
+ }
+
}
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index cd4dc35..c2f3561 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -146,8 +146,8 @@ impl CommandScore {
self.next_seed = next_seed;
}
- fn win_ratio(&self) -> u32 {
- self.victories * 1000 / self.attempts
+ fn win_ratio(&self) -> i32 {
+ (self.victories as i32 - self.defeats as i32) * 10000 / (self.attempts as i32)
}
fn init_command_scores(settings: &GameSettings, state: &GameState) -> Vec<CommandScore> {