Skip to main content

chess_tui/
constants.rs

1use core::fmt;
2use std::path::PathBuf;
3
4use ratatui::style::Color;
5
6pub const UNDEFINED_POSITION: u8 = u8::MAX;
7pub const WHITE: Color = Color::Rgb(160, 160, 160);
8pub const BLACK: Color = Color::Rgb(128, 95, 69);
9
10// Network constants
11pub const NETWORK_PORT: u16 = 2308;
12pub const NETWORK_BUFFER_SIZE: usize = 5;
13pub const SLEEP_DURATION_SHORT_MS: u64 = 50;
14pub const SLEEP_DURATION_LONG_MS: u64 = 100;
15
16// Time control constants
17// Time control indices: 0: UltraBullet, 1: Bullet, 2: Blitz, 3: Rapid, 4: Classical, 5: No clock, 6: Custom
18pub const TIME_CONTROL_CUSTOM_INDEX: u32 = 6;
19
20// Bot difficulty presets (name, UCI_Elo, depth, movetime_ms).
21// Lower depth and movetime make the bot weaker for engines without UCI_Elo.
22pub const BOT_DIFFICULTY_NAMES: [&str; 4] =
23    ["Easy (400)", "Medium (900)", "Hard (1500)", "Magnus (2700)"];
24pub const BOT_DIFFICULTY_ELO: [u16; 4] = [400, 900, 1500, 2700];
25pub const BOT_DIFFICULTY_DEPTH: [u8; 4] = [1, 4, 8, 20];
26pub const BOT_DIFFICULTY_MOVETIME_MS: [u64; 4] = [25, 120, 500, 12_000];
27pub const BOT_DIFFICULTY_COUNT: usize = 4;
28
29/// Time control options displayed in the UI
30pub const TIME_CONTROL_OPTIONS: &[&str] = &[
31    "UltraBullet",
32    "Bullet",
33    "Blitz",
34    "Rapid",
35    "Classical",
36    "No clock",
37    "Custom",
38];
39
40pub const TITLE: &str = r"
41 ██████╗██╗  ██╗███████╗███████╗███████╗   ████████╗██╗   ██╗██╗
42██╔════╝██║  ██║██╔════╝██╔════╝██╔════╝   ╚══██╔══╝██║   ██║██║
43██║     ███████║█████╗  ███████╗███████╗█████╗██║   ██║   ██║██║
44██║     ██╔══██║██╔══╝  ╚════██║╚════██║╚════╝██║   ██║   ██║██║
45╚██████╗██║  ██║███████╗███████║███████║      ██║   ╚██████╔╝██║
46 ╚═════╝╚═╝  ╚═╝╚══════╝╚══════╝╚══════╝      ╚═╝    ╚═════╝ ╚═╝
47";
48
49#[derive(Debug, Clone, Copy, PartialEq)]
50pub enum DisplayMode {
51    DEFAULT,
52    ASCII,
53    CUSTOM,
54}
55
56impl fmt::Display for DisplayMode {
57    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58        match *self {
59            DisplayMode::ASCII => write!(f, "ASCII"),
60            DisplayMode::DEFAULT => write!(f, "DEFAULT"),
61            DisplayMode::CUSTOM => write!(f, "CUSTOM"),
62        }
63    }
64}
65
66/// Returns the user's config directory path.
67///
68/// # Errors
69///
70/// Returns an error if the config directory cannot be determined.
71pub fn config_dir() -> Result<PathBuf, &'static str> {
72    match dirs::config_dir() {
73        Some(dir) => Ok(dir),
74        None => Err("Could not get config directory"),
75    }
76}
77
78#[derive(Debug, PartialEq, Clone)]
79pub enum Pages {
80    Home,
81    Solo,
82    Multiplayer,
83    Lichess,
84    LichessMenu,
85    OngoingGames,
86    Bot,
87    Credit,
88    GameModeMenu,
89}
90impl Pages {
91    #[must_use]
92    pub fn variant_count() -> usize {
93        8
94    }
95}
96
97#[derive(Debug, PartialEq, Clone, Copy)]
98pub enum Popups {
99    MultiplayerSelection,
100    EnterHostIP,
101    WaitingForOpponentToJoin,
102    EnginePathError,
103    Help,
104    EndScreen,
105    PuzzleEndScreen,
106    Error,
107    Success,
108    SeekingLichessGame,
109    EnterGameCode,
110    EnterLichessToken,
111    ResignConfirmation,
112    MoveInputSelection,
113}