diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs index 905d3c6..cee008c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,17 @@ use rand_pcg::*; use corpus::*; use layout::*; +const NUM_CONTESTANTS: usize = 24; +const SURVIVE_THRESHOLD: usize = 2; + +// TODO: Layout is really pre-layout, have something that takes a layout and +// re-orders columns to balance hands, and keys per column (block really +// consider index fingers) to balance rows. + +// TODO: command line arguments to start at a given layout string, maybe read +// from file? Might as well make num_contestants and survive_threshold +// configurable, and number of swaps when generating new layout + fn main() { let corpus = Corpus::load("new.txt").unwrap(); println!("{}", corpus); @@ -28,16 +39,11 @@ fn main() { type Fun = Vec<(Layout, u32)>; let mut best = std::u32::MAX; - let mut layouts: Fun = (0..10) + let mut layouts: Fun = (0..NUM_CONTESTANTS) .into_iter() - .map(|i| { + .map(|_| { let layout; - if i >= 0 { - layout = Layout::new_random_from(&starting_layout, &mut rng); - } else { - layout = starting_layout; - } - + layout = Layout::new_random_from(&starting_layout, &mut rng); return (layout, corpus.layout_fitness(&layout)); }) .collect(); @@ -47,8 +53,9 @@ fn main() { .iter() .enumerate() .map(|(i, (kbd, _))| { - if i > 0 { - Layout::new_random_from(kbd, &mut rng) + if i > SURVIVE_THRESHOLD { + let parent = rng.gen_range(0..=SURVIVE_THRESHOLD); + Layout::new_random_from(&layouts[parent].0, &mut rng) } else { kbd.clone() } |
