Skip to main content

elevator_core/components/
patience.rs

1//! Patience and boarding preference components.
2
3use serde::{Deserialize, Serialize};
4
5/// Tracks how long a rider will wait before abandoning.
6#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
7pub struct Patience {
8    /// Maximum ticks the rider will wait before abandoning.
9    pub(crate) max_wait_ticks: u64,
10    /// Ticks waited so far (incremented while in `Waiting` phase).
11    pub(crate) waited_ticks: u64,
12}
13
14impl Patience {
15    /// Maximum ticks the rider will wait before abandoning.
16    #[must_use]
17    pub const fn max_wait_ticks(&self) -> u64 {
18        self.max_wait_ticks
19    }
20
21    /// Ticks waited so far (incremented while in `Waiting` phase).
22    #[must_use]
23    pub const fn waited_ticks(&self) -> u64 {
24        self.waited_ticks
25    }
26}
27
28impl Default for Patience {
29    fn default() -> Self {
30        Self {
31            max_wait_ticks: 600,
32            waited_ticks: 0,
33        }
34    }
35}
36
37/// Boarding preferences for a rider.
38#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
39pub struct Preferences {
40    /// If true, the rider will skip a crowded elevator and wait for the next.
41    pub(crate) skip_full_elevator: bool,
42    /// Maximum load factor (0.0-1.0) the rider will tolerate when boarding.
43    pub(crate) max_crowding_factor: f64,
44}
45
46impl Preferences {
47    /// If true, the rider will skip a crowded elevator and wait for the next.
48    #[must_use]
49    pub const fn skip_full_elevator(&self) -> bool {
50        self.skip_full_elevator
51    }
52
53    /// Maximum load factor (0.0-1.0) the rider will tolerate when boarding.
54    #[must_use]
55    pub const fn max_crowding_factor(&self) -> f64 {
56        self.max_crowding_factor
57    }
58}
59
60impl Default for Preferences {
61    fn default() -> Self {
62        Self {
63            skip_full_elevator: false,
64            max_crowding_factor: 0.8,
65        }
66    }
67}