cargo fmt

This commit is contained in:
Pierre HUBERT 2022-09-13 17:26:40 +02:00
parent e17b64a416
commit b36f2d4f20
2 changed files with 24 additions and 16 deletions

View File

@ -164,8 +164,11 @@ impl BoatsLayout {
break; break;
} }
if attempt >= rules.map_width * rules.map_height { if attempt >= rules.map_width * rules.map_height * 4 {
return Err(std::io::Error::new(ErrorKind::Other, "Un-usable game rules!")); return Err(std::io::Error::new(
ErrorKind::Other,
"Un-usable game rules!",
));
} }
} }
} }
@ -210,9 +213,7 @@ impl BoatsLayout {
} }
// Check the length of the boats // Check the length of the boats
let mut len = self.0.iter() let mut len = self.0.iter().map(|l| l.len).collect::<Vec<_>>();
.map(|l| l.len)
.collect::<Vec<_>>();
len.sort(); len.sort();
let mut boats = rules.boats_list(); let mut boats = rules.boats_list();
boats.sort(); boats.sort();
@ -238,14 +239,17 @@ impl BoatsLayout {
errors.push("A collision between two boats has been detected!"); errors.push("A collision between two boats has been detected!");
} }
if !rules.boats_can_touch && self.0[boat_i].neighbor_coordinates(&rules).iter() if !rules.boats_can_touch
.any(|c| boat_j_coords.contains(c)) { && self.0[boat_i]
.neighbor_coordinates(&rules)
.iter()
.any(|c| boat_j_coords.contains(c))
{
errors.push("A collision between two boats has been detected!"); errors.push("A collision between two boats has been detected!");
} }
} }
} }
errors errors
} }
@ -256,9 +260,9 @@ impl BoatsLayout {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::data::{BotType, GameRules, PlayConfiguration};
use crate::data::boats_layout::{BoatDirection, BoatPosition, BoatsLayout, Coordinates}; use crate::data::boats_layout::{BoatDirection, BoatPosition, BoatsLayout, Coordinates};
use crate::data::game_map::GameMap; use crate::data::game_map::GameMap;
use crate::data::{BotType, GameRules, PlayConfiguration};
use crate::game::Game; use crate::game::Game;
#[test] #[test]

View File

@ -29,7 +29,11 @@ impl GameRules {
/// Set the list of boats for this configuration /// Set the list of boats for this configuration
pub fn set_boats_list(&mut self, boats: &[usize]) { pub fn set_boats_list(&mut self, boats: &[usize]) {
self.boats_str = boats.iter().map(usize::to_string).collect::<Vec<_>>().join(","); self.boats_str = boats
.iter()
.map(usize::to_string)
.collect::<Vec<_>>()
.join(",");
} }
/// Get the list of boats for this configuration /// Get the list of boats for this configuration