Check boats layout before accepting it

This commit is contained in:
2022-09-15 19:56:11 +02:00
parent d3d5feda4f
commit 8fac31e97b
5 changed files with 78 additions and 11 deletions

View File

@@ -216,7 +216,8 @@ impl BoatsLayout {
true
}
pub fn errors(&self, rules: &GameRules) -> Vec<&str> {
/// Check if this boats layout is valid or not
pub fn errors(&self, rules: &GameRules) -> Vec<&'static str> {
let mut errors = vec![];
// Check the number of boats
@@ -272,12 +273,6 @@ impl BoatsLayout {
pub fn number_of_boats(&self) -> usize {
self.0.len()
}
/// Check for layout invalid configuration
pub fn layouts_errors(&self, _rules: &GameRules) -> Vec<&'static str> {
//TODO : implement
vec![]
}
}
#[cfg(test)]

View File

@@ -44,6 +44,21 @@ impl GameRules {
.collect()
}
/// Remove last boat
pub fn pop_boat(&mut self) -> usize {
let list = self.boats_list();
self.set_boats_list(&list[0..list.len() - 1]);
*list.last().unwrap()
}
/// Add a boat to the list of boats
pub fn add_boat(&mut self, len: usize) {
let mut list = self.boats_list();
list.push(len);
self.set_boats_list(&list[0..list.len() - 1]);
}
/// Check game rules errors
pub fn get_errors(&self) -> Vec<&str> {
let config = PlayConfiguration::default();