#![allow(dead_code, unused)]

use clap::Parser;
use game::{simulation::Simulation, Game};
use rand::seq::SliceRandom;
use solve::grouping::Grouping;
use std::env::args;

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 args = Args::parse();
	dbg!(&args);
	let mut dict = dictionnary::scrable(7);
	// let dict = dictionnary::francais(7);
	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());
		let result = game.play_all(solver, Some(20));
		match result {
			Ok((_, tries)) => println!("succ,{target},{tries}"),
			Err(reason) => println!("fail,{target},{reason}"),
		};
	});
}

// fail,suedois,Reached limit.
