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

View File

@ -29,7 +29,11 @@ impl GameRules {
/// Set the list of boats for this configuration
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