1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// 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 <https://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------
// 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<u8> {
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,
}
}
}
|