summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-09-02 16:55:59 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-09-02 16:55:59 +0200
commit4c8b8667cbd0d16f6da056c1404a841196654e9b (patch)
tree618980c19f7b8ab58cbae335bc7589e8b118814a /src
parenta737142562c57a53a54bed76ef4d37794c79f44d (diff)
Decreased size of big CDF arrays
Diffstat (limited to 'src')
-rw-r--r--src/engine/bitwise_engine.rs16
-rw-r--r--src/strategy/monte_carlo.rs12
2 files changed, 13 insertions, 15 deletions
diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs
index c82e268..afd4bcc 100644
--- a/src/engine/bitwise_engine.rs
+++ b/src/engine/bitwise_engine.rs
@@ -441,23 +441,23 @@ impl Player {
self.missile_towers.iter().fold(0, |acc, next| acc | next)
}
- pub fn count_attack_towers_in_row(&self, y: u8) -> u32 {
+ pub fn count_attack_towers_in_row(&self, y: u8) -> u16 {
let mask = 255u64 << (y * SINGLE_MAP_WIDTH);
- (self.any_missile_towers() & mask).count_ones()
+ (self.any_missile_towers() & mask).count_ones() as u16
}
- pub fn count_energy_towers_in_row(&self, y: u8) -> u32 {
+ pub fn count_energy_towers_in_row(&self, y: u8) -> u16 {
let mask = 255u64 << (y * SINGLE_MAP_WIDTH);
- (self.energy_towers & mask).count_ones()
+ (self.energy_towers & mask).count_ones() as u16
}
- pub fn count_healthy_defence_in_row(&self, y: u8) -> u32 {
+ pub fn count_healthy_defence_in_row(&self, y: u8) -> u16 {
let mask = 255u64 << (y * SINGLE_MAP_WIDTH);
- (self.buildings[1] & mask).count_ones()
+ (self.buildings[1] & mask).count_ones() as u16
}
- pub fn count_towers_in_row(&self, y: u8) -> u32 {
+ pub fn count_towers_in_row(&self, y: u8) -> u16 {
let mask = 255u64 << (y * SINGLE_MAP_WIDTH);
- (self.occupied & mask).count_ones()
+ (self.occupied & mask).count_ones() as u16
}
}
diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs
index 0acaaae..1a4c400 100644
--- a/src/strategy/monte_carlo.rs
+++ b/src/strategy/monte_carlo.rs
@@ -192,7 +192,7 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
let mut cdf_tesla = [0; NUMBER_OF_MAP_POSITIONS];
- let mut other_end: u32 = 0;
+ let mut other_end: u16 = 0;
// Nothing
{
let weight = 1;
@@ -212,7 +212,7 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
}
// Energy
- let mut energy_end: u32 = other_end;
+ let mut energy_end: u16 = other_end;
let needs_energy = player.energy_generated() <= ENERGY_PRODUCTION_CUTOFF ||
player.energy <= ENERGY_STORAGE_CUTOFF;
if needs_energy && player.energy >= ENERGY_PRICE {
@@ -232,7 +232,7 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
}
// Defence
- let mut defence_end: u32 = energy_end;
+ let mut defence_end: u16 = energy_end;
if player.energy >= DEFENCE_PRICE {
for p in 0..NUMBER_OF_MAP_POSITIONS as u8 {
let point = Point::new_index(p);
@@ -249,7 +249,7 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
}
// Attack
- let mut attack_end: u32 = defence_end;
+ let mut attack_end: u16 = defence_end;
if player.energy >= MISSILE_PRICE {
for p in 0..NUMBER_OF_MAP_POSITIONS as u8 {
let point = Point::new_index(p);
@@ -266,7 +266,7 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
}
// Tesla
- let mut tesla_end: u32 = attack_end;
+ let mut tesla_end: u16 = attack_end;
let cant_tesla = player.has_max_teslas() || player.energy < TESLA_PRICE;
if !cant_tesla {
for p in 0..NUMBER_OF_MAP_POSITIONS as u8 {
@@ -290,8 +290,6 @@ fn random_move<R: Rng>(player: &Player, opponent: &Player, rng: &mut R) -> Comma
let choice = rng.gen_range(0, cumulative_distribution);
- // TODO can this be a more efficient lookup?
-
let index = match choice {
c if c < other_end => cdf_other.iter().position(|&c| c > choice).expect("Random number has exceeded cumulative distribution"),
c if c < energy_end => 2 + cdf_energy.iter().position(|&c| c > choice).expect("Random number has exceeded cumulative distribution"),