use crate::consts::*; /// Specifies the kind of boat to use #[derive(serde::Serialize, serde::Deserialize, Debug, Copy, Clone, Eq, PartialEq)] pub enum BotType { Random, Linear, Intermediate, Smart, } impl BotType { pub fn description(&self) -> &'static BotDescription { BOTS_TYPES.iter().find(|d| d.r#type == *self).unwrap() } } #[derive(serde::Serialize, Clone)] pub struct BotDescription { pub r#type: BotType, pub name: &'static str, pub description: &'static str, } const BOTS_TYPES: [BotDescription; 4] = [ BotDescription { r#type: BotType::Linear, name: "Linear", description: "Linear strike. Shoot A1, A2, A3, ..., B1, B2, ...", }, BotDescription { r#type: BotType::Random, name: "Random", description: "Random search. Random strike.", }, BotDescription { r#type: BotType::Intermediate, name: "Intermediate", description: "Random search. Intelligent strike.", }, BotDescription { r#type: BotType::Smart, name: "Smart", description: "Smart search. Smart strike.", }, ]; #[derive(serde::Serialize)] pub struct PlayConfiguration { pub min_boat_len: usize, pub max_boat_len: usize, pub min_map_width: usize, pub max_map_width: usize, pub min_map_height: usize, pub max_map_height: usize, pub min_boats_number: usize, pub max_boats_number: usize, pub bot_types: &'static [BotDescription], pub ordinate_alphabet: &'static str, pub min_player_name_len: usize, pub max_player_name_len: usize, pub min_strike_timeout: u64, pub max_strike_timeout: u64, } impl Default for PlayConfiguration { fn default() -> Self { Self { min_boat_len: MIN_BOATS_LENGTH, max_boat_len: MAX_BOATS_LENGTH, min_map_width: MIN_MAP_WIDTH, max_map_width: MAX_MAP_WIDTH, min_map_height: MIN_MAP_HEIGHT, max_map_height: MAX_MAP_HEIGHT, min_boats_number: MIN_BOATS_NUMBER, max_boats_number: MAX_BOATS_NUMBER, bot_types: &BOTS_TYPES, ordinate_alphabet: ALPHABET, min_player_name_len: MIN_PLAYER_NAME_LENGTH, max_player_name_len: MAX_PLAYER_NAME_LENGTH, min_strike_timeout: MIN_STRIKE_TIMEOUT, max_strike_timeout: MAX_STRIKE_TIMEOUT, } } }