aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2022-09-25 17:53:36 +0200
committertslil clingman <tslil@posteo.de>2022-09-25 17:59:04 +0200
commit6c9cee559d6f461ec660d3a1416b70e475b1c3bb (patch)
tree5941c3f55b0d45808e18dbe251e0ce80a9d8f1a2 /src/main.rs
parentac5858eb9f241023224b5415b1f6d516aae514b8 (diff)
Fix tournament
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs27
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()
}