Check boats layout before accepting it
This commit is contained in:
@@ -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)]
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user