diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-08-18 22:18:01 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-08-18 22:18:01 +0200 |
commit | 0c1636355918a82df0ec188252c8f90487206c7b (patch) | |
tree | 6a232a17a83f34b5a13f517164618b7230ae8653 /src/engine | |
parent | c36278ec2593ff9b25bf3f5bad22ab547cca5447 (diff) |
Implemented maximum number of energy buildings in a row
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/bitwise_engine.rs | 25 | ||||
-rw-r--r-- | src/engine/constants.rs | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs index a4842ec..27c1bd8 100644 --- a/src/engine/bitwise_engine.rs +++ b/src/engine/bitwise_engine.rs @@ -453,4 +453,29 @@ impl Player { debug_assert!(point.to_either_bitfield() & self.occupied == 0); point } + + pub fn energy_occupied_energy_with_heuristics(&self) -> u64 { + let mut result = 0; + for y in 0..MAP_HEIGHT { + let mask = 255 << y*SINGLE_MAP_WIDTH; + let isolated_row = self.energy_towers & mask; + let row_count = isolated_row.count_ones(); + result |= if row_count > ENERGY_MAX_IN_ROW { + mask + } else { + self.occupied & mask + }; + } + result + } + + pub fn unoccupied_energy_cell_count(&self) -> usize { + self.energy_occupied_energy_with_heuristics().count_zeros() as usize + } + pub fn location_of_unoccupied_energy_cell(&self, i: usize) -> Point { + let bit = find_bit_index_from_rank(self.energy_occupied_energy_with_heuristics(), i as u64); + let point = Point { index: bit }; + debug_assert!(point.to_either_bitfield() & self.occupied == 0); + point + } } diff --git a/src/engine/constants.rs b/src/engine/constants.rs index 9ece36d..60e8101 100644 --- a/src/engine/constants.rs +++ b/src/engine/constants.rs @@ -26,6 +26,8 @@ pub const ENERGY_GENERATED_TOWER: u16 = 3; pub const ENERGY_PRICE: u16 = 20; pub const ENERGY_CONSTRUCTION_TIME: u8 = 1; +pub const ENERGY_MAX_IN_ROW: u32 = 2; + pub const IRON_CURTAIN_PRICE: u16 = 100; pub const IRON_CURTAIN_UNLOCK_INTERVAL: u16 = 30; pub const IRON_CURTAIN_DURATION: u8 = 6; |