// Copyright (C) 2022 tslil clingman
//
// This file is part of srchr.
//
// srchr is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// srchr is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
// A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// srchr. If not, see .
// -----------------------------------------------------------------------------
// Tweak
// -----------------------------------------------------------------------------
// Input parameters
pub const CORPUS_FILE_NAME: &str = "corpus.txt";
pub const STATS_FILE_NAME: &str = "shai.json";
pub const LOAD_STATS: bool = true;
pub const STARTING_LAYOUT_STRING: &str = "
Q W F P B J L U Y '
A R S T G M N E I O
Z X C D V K H , . /
";
// Tournament parameters
pub const NUM_CONTESTANTS: usize = 256;
pub const NUM_PERSIST: usize = 8;
pub const MAX_NUM_TRANSPOSITIONS: usize = 6;
// Fitness parameters
pub const STANDARD_DSFB_WEIGHT: f32 = 1.0 / 16.0;
pub const INDEX_DSFB_WEIGHT: f32 = 1.0 / 16.0;
pub const MIN_INDEX_USAGE_PERCENT: f32 = 0.12;
pub fn index_usage_fitness(index_perc: f32) -> f32 {
if index_perc < MIN_INDEX_USAGE_PERCENT {
MIN_INDEX_USAGE_PERCENT - index_perc
} else {
0.0
}
}
pub const MAX_PINKY_USAGE_PERCENT: f32 = 0.095;
pub fn pinky_col_penalty(lesser_perc: f32, greater_perc: f32) -> f32 {
if greater_perc > MAX_PINKY_USAGE_PERCENT {
if lesser_perc > MAX_PINKY_USAGE_PERCENT {
lesser_perc + greater_perc - MAX_PINKY_USAGE_PERCENT * 2.0
} else {
greater_perc - MAX_PINKY_USAGE_PERCENT
}
} else {
0.0
}
}
// Pre-layout to layout
#[allow(dead_code)]
pub enum Algorithm {
MinimiseLSBThenBalance,
GreedyBalance,
}
pub const PRELAYOUT_TO_LAYOUT_ALGORITHM: Algorithm = Algorithm::MinimiseLSBThenBalance;
// -----------------------------------------------------------------------------
// Do not change the following, the code makes assumptions about these
// -----------------------------------------------------------------------------
pub const NUM_KEYS: usize = 30;
pub const ROW_LENGTH: usize = 10;
pub const KEY_CHARS: [char; NUM_KEYS] = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '/', '.', ',', '\'',
];
pub const KEY_TO_FINGER: [usize; NUM_KEYS] = [
0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7,
];
pub fn canonicalise(inp: char) -> Option {
if inp.is_ascii_alphabetic() {
return Some(inp.to_ascii_uppercase() as u8);
} else {
match inp {
'.' => Some('.' as u8),
'>' => Some('.' as u8),
',' => Some(',' as u8),
'<' => Some(',' as u8),
'/' => Some('/' as u8),
'?' => Some('/' as u8),
'\'' => Some('\'' as u8),
'"' => Some('\'' as u8),
_ => None,
}
}
}