improve bench args

This commit is contained in:
Matthieu Jolimaitre 2024-10-25 22:35:42 +02:00
parent 1a647d91ab
commit 40d06b0fa4
3 changed files with 217 additions and 10 deletions

View file

@ -1,10 +1,8 @@
#![allow(dead_code, unused)]
// use core::iter::repeat;
use clap::Parser;
use game::{simulation::Simulation, Game};
use rand::seq::SliceRandom;
use rayon::iter::repeat;
use rayon::prelude::*;
use solve::grouping::Grouping;
use std::env::args;
@ -12,15 +10,30 @@ mod dictionnary;
mod game;
mod solve;
#[derive(Debug, clap::Parser)]
struct Args {
#[arg(short, long, default_value_t = 100)]
count: usize,
#[arg(short, long)]
target: Option<String>,
}
fn main() {
let count = args()
.nth(1)
.map(|s| s.parse().expect("Number expected."))
.unwrap_or(100);
let args = Args::parse();
dbg!(&args);
let mut dict = dictionnary::gutenberg(7);
// let dict = dictionnary::francais(7);
let dict = dictionnary::gutenberg(7);
(0..count).into_par_iter().for_each(|_| {
let target = dict.choose(&mut rand::thread_rng()).unwrap().to_string();
let count = if args.target.is_some() { 1 } else { args.count };
(0..count).for_each(|_| {
let mut target = dict.choose(&mut rand::thread_rng()).unwrap().to_string();
if let Some(specified) = &args.target {
target = specified.clone();
dict = dict
.iter()
.filter(|w| w.starts_with(target.chars().next().unwrap()))
.cloned()
.collect();
}
dbg!(&target);
let solver = Grouping::new(dict.clone());
let mut game = Simulation::new(target.clone());