From 7b95465d47af0c1e74f1d2e4c76fdb7a9b6e960c Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 31 May 2018 21:00:22 +0200 Subject: Clippy suggested changes --- src/engine/command.rs | 6 +++--- src/engine/geometry.rs | 2 +- src/engine/mod.rs | 23 +++++++++-------------- src/json.rs | 6 ++---- src/strategy/monte_carlo.rs | 6 +++--- 5 files changed, 18 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/engine/command.rs b/src/engine/command.rs index c2edb81..17dbd5a 100644 --- a/src/engine/command.rs +++ b/src/engine/command.rs @@ -9,9 +9,9 @@ pub enum Command { impl fmt::Display for Command { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &Command::Nothing => write!(f, ""), - &Command::Build(p, b) => write!(f, "{},{},{}", p.x, p.y, b as u8), + match *self { + Command::Nothing => write!(f, ""), + Command::Build(p, b) => write!(f, "{},{},{}", p.x, p.y, b as u8), } } } diff --git a/src/engine/geometry.rs b/src/engine/geometry.rs index 23e0433..bd0ae25 100644 --- a/src/engine/geometry.rs +++ b/src/engine/geometry.rs @@ -10,7 +10,7 @@ impl Point { } pub fn move_left(&self) -> Option { self.x.checked_sub(1).map(|x| Point { - x: x, + x, ..*self }) } diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 6626c0d..e9cafa4 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -84,16 +84,10 @@ impl GameState { ); GameState { status: GameStatus::Continue, - player: player, - opponent: opponent, - player_unconstructed_buildings: player_unconstructed_buildings, - player_buildings: player_buildings, - unoccupied_player_cells: unoccupied_player_cells, - opponent_unconstructed_buildings: opponent_unconstructed_buildings, - opponent_buildings: opponent_buildings, - unoccupied_opponent_cells: unoccupied_opponent_cells, - player_missiles: player_missiles, - opponent_missiles: opponent_missiles + player, opponent, + player_unconstructed_buildings, player_buildings, unoccupied_player_cells, + opponent_unconstructed_buildings, opponent_buildings, unoccupied_opponent_cells, + player_missiles, opponent_missiles } } @@ -210,6 +204,7 @@ impl GameState { }, Some(point) => { missile.pos = point; + // TODO latest game engine may be checking building health here for hit in opponent_buildings.iter_mut().filter(|b| b.pos == point) { let damage = cmp::min(missile.damage, hit.health); hit.health -= damage; @@ -292,8 +287,8 @@ impl GameStatus { impl Player { pub fn new(energy: u16, health: u8, settings: &GameSettings, buildings: &[Building]) -> Player { Player { - energy: energy, - health: health, + energy, + health, energy_generated: settings.energy_income + buildings.iter().map(|b| b.energy_generated_per_turn).sum::() } } @@ -319,7 +314,7 @@ impl Player { impl UnconstructedBuilding { pub fn new(pos: Point, blueprint: &BuildingSettings) -> UnconstructedBuilding { UnconstructedBuilding { - pos: pos, + pos, health: blueprint.health, construction_time_left: blueprint.construction_time, weapon_damage: blueprint.weapon_damage, @@ -349,7 +344,7 @@ impl UnconstructedBuilding { impl Building { pub fn new(pos: Point, blueprint: &BuildingSettings) -> Building { Building { - pos: pos, + pos, health: blueprint.health, weapon_damage: blueprint.weapon_damage, weapon_speed: blueprint.weapon_speed, diff --git a/src/json.rs b/src/json.rs index 02dbe1b..5830bd9 100644 --- a/src/json.rs +++ b/src/json.rs @@ -136,15 +136,13 @@ impl State { fn player(&self) -> &Player { self.players.iter() - .filter(|p| p.player_type == 'A') - .next() + .find(|p| p.player_type == 'A') .expect("Player character did not appear in state.json") } fn opponent(&self) -> &Player { self.players.iter() - .filter(|p| p.player_type == 'B') - .next() + .find(|p| p.player_type == 'B') .expect("Opponent character did not appear in state.json") } diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs index ab13d87..cd4dc35 100644 --- a/src/strategy/monte_carlo.rs +++ b/src/strategy/monte_carlo.rs @@ -46,7 +46,7 @@ pub fn choose_move(settings: &GameSettings, state: &GameState, start_time: &Prec } match command { - Some(ref command) => command.command, + Some(command) => command.command, _ => Command::Nothing } } @@ -112,13 +112,13 @@ struct CommandScore { impl CommandScore { fn new(command: Command) -> CommandScore { CommandScore { - command: command, + command, victories: 0, defeats: 0, draws: 0, stalemates: 0, attempts: 0, - next_seed: [0x7b6ae1f4, 0x413ce90f, 0x67816799, 0x770a6bda] + next_seed: [0x7b6a_e1f4, 0x413c_e90f, 0x6781_6799, 0x770a_6bda] } } -- cgit v1.2.3