summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-08-12 21:18:01 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-08-12 21:18:01 +0200
commitf5de63875890cfca2891848f54e8cd35019bea8e (patch)
treee722e518eda42c6920a78a68c687eaa29b924b26 /src
parentc9f09a22bc54b6275913aa3b900b402c56461c32 (diff)
Eliminated assuming opponents might do nothing in random moves
Diffstat (limited to 'src')
-rw-r--r--src/strategy/monte_carlo.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index 866ec0e..4d699c1 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -114,25 +114,23 @@ fn simulate_to_endstate<R: Rng>(command_score: &mut CommandScore, state: &Bitwis
}
}
-// TODO: Given enough energy, most opponents won't do nothing
fn random_move<R: Rng>(player: &Player, rng: &mut R) -> Command {
let all_buildings = sensible_buildings(player);
- let nothing_count = 1;
+ let nothing_count = if all_buildings.len() > 2 { 1 } else { 0 };
let iron_curtain_count = if player.can_build_iron_curtain() { 1 } else { 0 };
let free_positions_count = player.unoccupied_cell_count();
let building_choice_index = rng.gen_range(0, all_buildings.len() + nothing_count + iron_curtain_count);
-
- if building_choice_index == all_buildings.len() {
- Command::Nothing
- } else if iron_curtain_count > 0 && building_choice_index == all_buildings.len() + 1 {
- Command::IronCurtain
- } else if free_positions_count > 0 {
+
+ if building_choice_index < all_buildings.len() && free_positions_count > 0 {
let position_choice = rng.gen_range(0, free_positions_count);
Command::Build(
player.location_of_unoccupied_cell(position_choice),
all_buildings[building_choice_index]
)
+ }
+ else if iron_curtain_count > 0 && building_choice_index == all_buildings.len() {
+ Command::IronCurtain
} else {
Command::Nothing
}