Clippy suggested changes
authorJustin Worthe <justin@worthe-it.co.za>
Thu, 31 May 2018 19:00:22 +0000 (21:00 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Thu, 31 May 2018 19:00:22 +0000 (21:00 +0200)
src/engine/command.rs
src/engine/geometry.rs
src/engine/mod.rs
src/json.rs
src/strategy/monte_carlo.rs

index c2edb81..17dbd5a 100644 (file)
@@ -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),
         }
     }
 }
index 23e0433..bd0ae25 100644 (file)
@@ -10,7 +10,7 @@ impl Point {
     }
     pub fn move_left(&self) -> Option<Point> {
         self.x.checked_sub(1).map(|x| Point {
-            x: x,
+            x,
             ..*self
         })
     }
index 6626c0d..e9cafa4 100644 (file)
@@ -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::<u16>()
         }
     }
@@ -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,
index 02dbe1b..5830bd9 100644 (file)
@@ -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")
     }
 
index ab13d87..cd4dc35 100644 (file)
@@ -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]
         }
     }