use crate::constants::{GAME_SERVER_PORT, SIMULATION_LISTENER_PORT};
use crate::grid::standard_grid::StandardGrid;
use crate::messages::{ExtraOptsTypes, FrequentServerToRobot};
use crate::names::{RobotName, NUM_ROBOT_NAMES};
use nalgebra::Point2;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
pub struct PacbotSettings {
pub host_http: bool,
pub safe_mode: bool,
pub standard_grid: StandardGrid,
pub pacman: RobotName,
pub do_target_path: ShouldDoTargetPath,
pub cv_location_source: CvLocationSource,
pub target_speed: f32,
pub simulation: SimulationSettings,
pub game_server: GameServerSettings,
pub robots: [RobotSettings; NUM_ROBOT_NAMES],
pub driving: DriveSettings,
}
impl Default for PacbotSettings {
fn default() -> Self {
Self {
host_http: false,
safe_mode: false,
pacman: RobotName::Pierre,
do_target_path: Default::default(),
cv_location_source: Default::default(),
target_speed: 3.0,
simulation: Default::default(),
standard_grid: Default::default(),
robots: RobotName::get_all().map(RobotSettings::new),
game_server: Default::default(),
driving: Default::default(),
}
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, PartialOrd)]
pub enum ShouldDoTargetPath {
Yes,
No,
#[default]
DoWhilePlayed,
}
impl ShouldDoTargetPath {
pub fn get_all() -> [ShouldDoTargetPath; 3] {
[
ShouldDoTargetPath::No,
ShouldDoTargetPath::Yes,
ShouldDoTargetPath::DoWhilePlayed,
]
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, PartialOrd)]
pub enum CvLocationSource {
#[default]
GameState,
Constant(Option<Point2<i8>>),
Localization,
}
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
pub struct ConnectionSettings {
pub connect: bool,
pub ipv4: [u8; 4],
pub port: u16,
}
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
pub struct SimulationSettings {
pub simulate: bool,
pub connection: ConnectionSettings,
pub robots: [bool; NUM_ROBOT_NAMES],
}
impl Default for SimulationSettings {
fn default() -> Self {
Self {
simulate: false,
connection: ConnectionSettings {
connect: false,
ipv4: [127, 0, 0, 1],
port: SIMULATION_LISTENER_PORT,
},
robots: RobotName::get_all().map(|name| name == RobotName::Stella),
}
}
}
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
pub struct GameServerSettings {
pub connection: ConnectionSettings,
}
impl Default for GameServerSettings {
fn default() -> Self {
Self {
connection: ConnectionSettings {
connect: false,
ipv4: [127, 0, 0, 1],
port: GAME_SERVER_PORT,
},
}
}
}
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
pub struct RobotSettings {
pub name: RobotName,
pub connection: ConnectionSettings,
pub config: FrequentServerToRobot,
pub extra_opts_enabled: bool,
pub extra_opts: ExtraOptsTypes,
}
impl RobotSettings {
pub fn new(name: RobotName) -> Self {
Self {
name,
connection: ConnectionSettings {
connect: false,
ipv4: name.default_ip(),
port: name.port(),
},
config: FrequentServerToRobot::new(name),
extra_opts_enabled: false,
extra_opts: ExtraOptsTypes::default(),
}
}
}
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
pub struct DriveSettings {
pub strategy: StrategyChoice,
pub speed_base: f32,
pub speed_multiplier: f32,
pub speed_cap: f32,
pub manual_speed: f32,
pub manual_rotation_speed: f32,
}
impl Default for DriveSettings {
fn default() -> Self {
Self {
strategy: StrategyChoice::default(),
speed_base: 3.0,
speed_multiplier: 2.0,
speed_cap: 8.0,
manual_speed: 8.0,
manual_rotation_speed: 2.0,
}
}
}
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Hash, Serialize, Deserialize, Ord, Eq)]
pub enum KnownRLModel {
QNet,
Endgame,
}
impl KnownRLModel {
pub fn path(&self) -> &'static str {
match self {
KnownRLModel::QNet => "checkpoints/q_net.safetensors",
KnownRLModel::Endgame => "checkpoints/endgame.safetensors",
}
}
}
#[derive(Clone, Debug, Default, PartialOrd, PartialEq, Serialize, Deserialize)]
pub enum StrategyChoice {
Stop,
#[default]
Manual,
ReinforcementLearning,
TestUniform,
TestForward,
}