cargo fmt
This commit is contained in:
parent
e17b64a416
commit
b36f2d4f20
@ -71,7 +71,7 @@ impl BoatDirection {
|
||||
}
|
||||
|
||||
#[derive(
|
||||
serde::Serialize, serde::Deserialize, Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd,
|
||||
serde::Serialize, serde::Deserialize, Debug, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd,
|
||||
)]
|
||||
pub struct Coordinates {
|
||||
y: i32,
|
||||
@ -80,8 +80,8 @@ pub struct Coordinates {
|
||||
|
||||
impl Coordinates {
|
||||
pub fn new<E>(x: E, y: E) -> Self
|
||||
where
|
||||
E: Into<i32>,
|
||||
where
|
||||
E: Into<i32>,
|
||||
{
|
||||
Self {
|
||||
x: x.into(),
|
||||
@ -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!",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,9 +194,9 @@ impl BoatsLayout {
|
||||
// Check if the boat touch another boat in a configuration where is it forbidden
|
||||
if !rules.boats_can_touch
|
||||
&& pos
|
||||
.neighbor_coordinates(&rules)
|
||||
.iter()
|
||||
.any(|c| self.find_boat_at_position(*c).is_some())
|
||||
.neighbor_coordinates(&rules)
|
||||
.iter()
|
||||
.any(|c| self.find_boat_at_position(*c).is_some())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -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]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user