diff options
Diffstat (limited to 'planetwars-rules')
-rw-r--r-- | planetwars-rules/src/config.rs | 20 | ||||
-rw-r--r-- | planetwars-rules/src/lib.rs | 4 | ||||
-rw-r--r-- | planetwars-rules/src/rules.rs | 4 | ||||
-rw-r--r-- | planetwars-rules/src/serializer.rs | 4 |
4 files changed, 15 insertions, 17 deletions
diff --git a/planetwars-rules/src/config.rs b/planetwars-rules/src/config.rs index 57c77eb..14a4ac2 100644 --- a/planetwars-rules/src/config.rs +++ b/planetwars-rules/src/config.rs @@ -25,8 +25,8 @@ impl Config { .collect(); PwState { - players: players, - planets: planets, + players, + planets, expeditions: Vec::new(), expedition_num: 0, turn_num: 0, @@ -37,8 +37,7 @@ impl Config { fn load_map(&self, num_players: usize) -> Vec<Planet> { let map = self.read_map().expect("[PLANET_WARS] reading map failed"); - return map - .planets + map.planets .into_iter() .enumerate() .map(|(num, planet)| { @@ -55,27 +54,26 @@ impl Config { }); if planet.ship_count > 0 { fleets.push(Fleet { - owner: owner, + owner, ship_count: planet.ship_count, }); } - return Planet { + Planet { id: num, name: planet.name, x: planet.x, y: planet.y, - fleets: fleets, - }; + fleets, + } }) - .collect(); + .collect() } fn read_map(&self) -> io::Result<Map> { let mut file = File::open(&self.map_file)?; let mut buf = String::new(); file.read_to_string(&mut buf)?; - let map = serde_json::from_str(&buf)?; - return Ok(map); + Ok(serde_json::from_str(&buf)?) } } diff --git a/planetwars-rules/src/lib.rs b/planetwars-rules/src/lib.rs index 48034ee..26382f1 100644 --- a/planetwars-rules/src/lib.rs +++ b/planetwars-rules/src/lib.rs @@ -50,7 +50,7 @@ impl PlanetWars { serializer::serialize_rotated(&self.state, player_id - 1) } - pub fn state<'a>(&'a self) -> &'a PwState { + pub fn state(&self) -> &PwState { &self.state } @@ -62,7 +62,7 @@ impl PlanetWars { ) -> Result<(), CommandError> { let dispatch = self.parse_command(player_num, cmd)?; self.state.dispatch(&dispatch); - return Ok(()); + Ok(()) } /// Check the given command for validity. diff --git a/planetwars-rules/src/rules.rs b/planetwars-rules/src/rules.rs index 587098f..e339b4e 100644 --- a/planetwars-rules/src/rules.rs +++ b/planetwars-rules/src/rules.rs @@ -128,7 +128,7 @@ impl PwState { pub fn is_finished(&self) -> bool { let remaining = self.players.iter().filter(|p| p.alive).count(); - return remaining < 2 || self.turn_num >= self.max_turns; + remaining < 2 || self.turn_num >= self.max_turns } pub fn living_players(&self) -> Vec<usize> { @@ -187,6 +187,6 @@ impl Planet { fn distance(&self, other: &Planet) -> u64 { let dx = self.x - other.x; let dy = self.y - other.y; - return (dx.powi(2) + dy.powi(2)).sqrt().ceil() as u64; + (dx.powi(2) + dy.powi(2)).sqrt().ceil() as u64 } } diff --git a/planetwars-rules/src/serializer.rs b/planetwars-rules/src/serializer.rs index 7eb2e01..22ba52e 100644 --- a/planetwars-rules/src/serializer.rs +++ b/planetwars-rules/src/serializer.rs @@ -20,7 +20,7 @@ struct Serializer<'a> { impl<'a> Serializer<'a> { fn new(state: &'a PwState, offset: usize) -> Self { Serializer { - state: state, + state, player_num_offset: offset, } } @@ -49,7 +49,7 @@ impl<'a> Serializer<'a> { let num_players = self.state.players.len(); let rotated_id = (player_id + num_players - self.player_num_offset) % num_players; // protocol player ids start at 1 - return rotated_id + 1; + rotated_id + 1 } fn serialize_planet(&self, planet: &Planet) -> proto::Planet { |