summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-09-01 22:01:28 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-09-01 22:01:28 +0200
commitdafb9cf03cc5e8ad0a2b2d1857bb635d237f47b0 (patch)
treee1cf8200d5bd148b446c77a7826e9e6c37ea42a7 /src
parentf7a7d40dede261bc29edf88e8a8d2bfb71c58513 (diff)
Corrected which player's attack towers to consider
Diffstat (limited to 'src')
-rw-r--r--src/engine/bitwise_engine.rs10
-rw-r--r--src/strategy/monte_carlo.rs6
2 files changed, 13 insertions, 3 deletions
diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs
index 75acb7d..c82e268 100644
--- a/src/engine/bitwise_engine.rs
+++ b/src/engine/bitwise_engine.rs
@@ -450,4 +450,14 @@ impl Player {
let mask = 255u64 << (y * SINGLE_MAP_WIDTH);
(self.energy_towers & mask).count_ones()
}
+
+ pub fn count_healthy_defence_in_row(&self, y: u8) -> u32 {
+ let mask = 255u64 << (y * SINGLE_MAP_WIDTH);
+ (self.buildings[1] & mask).count_ones()
+ }
+
+ pub fn count_towers_in_row(&self, y: u8) -> u32 {
+ let mask = 255u64 << (y * SINGLE_MAP_WIDTH);
+ (self.occupied & mask).count_ones()
+ }
}
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index 1e4483b..347af96 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -249,7 +249,8 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
let weight = if player.energy < MISSILE_PRICE || player.occupied & point.to_either_bitfield() != 0 {
0
} else {
- 8 + opponent.count_energy_towers_in_row(point.y()) - opponent.count_attack_towers_in_row(point.y())
+ // TODO: take into account opponent attacks and defence in row?
+ 8 + opponent.count_energy_towers_in_row(point.y()) - player.count_attack_towers_in_row(point.y())
};
cumulative_distribution += weight;
@@ -272,7 +273,7 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
cdf[i] = cumulative_distribution;
}
- assert_eq!(MOVES.len(), t_base + NUMBER_OF_MAP_POSITIONS);
+ debug_assert_eq!(MOVES.len(), t_base + NUMBER_OF_MAP_POSITIONS);
if cumulative_distribution == 0 {
return Command::Nothing;
@@ -280,7 +281,6 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
let choice = rng.gen_range(0, cumulative_distribution);
- // find maximum index where choice <= cdf[index]
// TODO can this be a more efficient lookup?
let index = cdf.iter().position(|&c| c > choice).expect("Random number has exceeded cumulative distribution");