From 1e21ebed15321aacbba53121cb40bbc60f4db1cc Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 8 Dec 2018 22:02:19 +0200 Subject: Renamed variable to be more concise --- src/engine/bitwise_engine.rs | 10 +++++----- src/engine/geometry.rs | 4 ++-- src/input/json.rs | 2 +- src/strategy/monte_carlo.rs | 9 ++++----- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs index f03f1c0..694a309 100644 --- a/src/engine/bitwise_engine.rs +++ b/src/engine/bitwise_engine.rs @@ -224,7 +224,7 @@ impl BitwiseGameState { player.energy -= TESLA_FIRING_ENERGY; tesla.cooldown = TESLA_COOLDOWN; - if tesla.pos.to_either_bitfield() & RIGHT_COL_MASK != 0 { + if tesla.pos.to_bitfield() & RIGHT_COL_MASK != 0 { opponent.health = opponent.health.saturating_sub(TESLA_DAMAGE); } @@ -291,7 +291,7 @@ impl BitwiseGameState { fn update_tesla_activity(buildings: &mut Player) { let occupied = buildings.occupied; - buildings.tesla_cooldowns.retain(|t| (t.pos.to_either_bitfield() & occupied) != 0); + buildings.tesla_cooldowns.retain(|t| (t.pos.to_bitfield() & occupied) != 0); } @@ -356,7 +356,7 @@ impl Player { pub fn location_of_unoccupied_cell(&self, i: usize) -> Point { let bit = find_bit_index_from_rank(self.occupied, i as u64); let point = Point { index: bit }; - debug_assert!(point.to_either_bitfield() & self.occupied == 0); + debug_assert!(point.to_bitfield() & self.occupied == 0); point } @@ -365,7 +365,7 @@ impl Player { match command { Command::Nothing => {}, Command::Build(p, b) => { - let bitfield = p.to_either_bitfield(); + let bitfield = p.to_bitfield(); let price = match b { BuildingType::Attack => MISSILE_PRICE, @@ -415,7 +415,7 @@ impl Player { let health = if building_type == BuildingType::Defence { DEFENCE_HEALTH } else { 1 }; let pos = self.unconstructed[i].pos; - let bitfield = pos.to_either_bitfield(); + let bitfield = pos.to_bitfield(); for health_tier in 0..health { self.buildings[health_tier] |= bitfield; diff --git a/src/engine/geometry.rs b/src/engine/geometry.rs index b8b38dd..9cd1d90 100644 --- a/src/engine/geometry.rs +++ b/src/engine/geometry.rs @@ -24,7 +24,7 @@ impl Point { } pub fn new_double_bitfield(x: u8, y: u8, is_left_player: bool) -> (u64, u64) { - let bitfield = Point::new(x, y).to_either_bitfield(); + let bitfield = Point::new(x, y).to_bitfield(); if (x >= SINGLE_MAP_WIDTH) == is_left_player { (0, bitfield) } else { @@ -51,7 +51,7 @@ impl Point { * This involves mirroring the x dimension for the opponent's side */ - pub fn to_either_bitfield(self) -> u64 { + pub fn to_bitfield(self) -> u64 { 1u64 << self.index } } diff --git a/src/input/json.rs b/src/input/json.rs index 4e10f9a..a71d49e 100644 --- a/src/input/json.rs +++ b/src/input/json.rs @@ -89,7 +89,7 @@ impl State { } else { &mut opponent }; - let bitfield = point.to_either_bitfield(); + let bitfield = point.to_bitfield(); bitwise_buildings.occupied |= bitfield; if building.construction_time_left >= 0 { diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs index 543d5d7..adbb911 100644 --- a/src/strategy/monte_carlo.rs +++ b/src/strategy/monte_carlo.rs @@ -2,7 +2,6 @@ use engine::command::*; use engine::status::GameStatus; use engine::bitwise_engine::{Player, BitwiseGameState}; use engine::constants::*; -use engine::geometry::*; use std::fmt; @@ -234,7 +233,7 @@ pub fn random_move(player: &Player, opponent: &Player, rng: &mut R) -> C if needs_energy && player.energy >= ENERGY_PRICE { for p in 0..NUMBER_OF_MAP_POSITIONS as u8 { let point = Point::new_index(p); - let weight = if player.occupied & point.to_either_bitfield() != 0 { + let weight = if player.occupied & point.to_bitfield() != 0 { 0 } else { 2 @@ -252,7 +251,7 @@ pub fn random_move(player: &Player, opponent: &Player, rng: &mut R) -> C let point = Point::new_index(p); let y = usize::from(point.y()); - let weight = if player.occupied & point.to_either_bitfield() != 0 || point.x() < 4 { + let weight = if player.occupied & point.to_bitfield() != 0 || point.x() < 4 { 0 } else { defence_metric_per_row[y] @@ -268,7 +267,7 @@ pub fn random_move(player: &Player, opponent: &Player, rng: &mut R) -> C if player.energy >= MISSILE_PRICE { for p in 0..NUMBER_OF_MAP_POSITIONS as u8 { let point = Point::new_index(p); - let weight = if player.occupied & point.to_either_bitfield() != 0 { + let weight = if player.occupied & point.to_bitfield() != 0 { 0 } else { let y = usize::from(point.y()); @@ -286,7 +285,7 @@ pub fn random_move(player: &Player, opponent: &Player, rng: &mut R) -> C if !cant_tesla { for p in 0..NUMBER_OF_MAP_POSITIONS as u8 { let point = Point::new_index(p); - let weight = if (player.occupied & point.to_either_bitfield() != 0) || point.y() < 7 { + let weight = if (player.occupied & point.to_bitfield() != 0) || point.y() < 7 { 0 } else { 10 -- cgit v1.2.3