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
|
// With the below parameters and the supplied corpus searches seem to converge on a few layouts, with one of the better ones being
// V L O M Z P F U H ,
// S R A T K Y C E N I
// X J / D Q G W ' B .
// Percent per key:
// 0.92 3.96 7.42 2.57 0.06 1.62 2.10 2.77 5.94 1.78
// 6.03 5.56 7.74 8.60 0.77 1.99 2.35 11.90 6.62 6.68
// 0.15 0.15 0.14 4.25 0.10 1.93 2.27 1.00 1.50 1.14
//
// Finger usage: 7.10%, 9.66%, 15.30%, 16.36%, 12.25%, 15.67%, 14.06%, 9.61%
// Hand usage: 48.42% vs 51.58%
// SFB distribution : 0.002%, 0.088%, 0.089%, 0.047%, 0.104%, 0.197%, 0.044%, 0.024%
// DSFB distribution: 0.166%, 0.402%, 0.614%, 1.302%, 0.761%, 0.985%, 1.101%, 0.405%
// Total sfb: 0.595% (50086)
// Total dsfb: 5.736% (482638)
// -----------------------------------------------------------------------------
// 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 = "
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 . , / '
";
// Tournament parameters
pub const NUM_CONTESTANTS: usize = 256;
pub const NUM_PERSIST: usize = 8;
pub const MAX_NUM_TRANSPOSITIONS: usize = 12;
// Fitness parameters
pub const DESIRED_INDEX_USAGE_PERCENT: f32 = 0.12;
pub const MAX_PINKY_USAGE_PERCENT: f32 = 0.09;
pub const STANDARD_DSFB_WEIGHT: f32 = 1.0 / 8.0;
pub const INDEX_DSFB_WEIGHT: f32 = 1.0 / 8.0;
pub fn index_usage_fitness(index_perc: f32) -> f32 {
if index_perc < DESIRED_INDEX_USAGE_PERCENT {
DESIRED_INDEX_USAGE_PERCENT - index_perc
} else {
0.0
}
}
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
}
}
// -----------------------------------------------------------------------------
// 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,
}
}
}
|