use settheory::CardSelection;

const DIM: usize = 4;
const RUNS: usize = 1000000;

fn main() {
    let mut selection: CardSelection<DIM>;
    let mut avg = 0;
    let mut min = usize::MAX;
    let mut min_cards = CardSelection::new();
    let mut max = usize::MIN;
    let mut max_cards = CardSelection::new();
    'runs: for i in 0..RUNS {
        if i % 500 == 0 {
            print!("{i:5} of {RUNS} iterations\r");
        }
        selection = CardSelection::new();
        loop {
            let Some(card) = selection.no_sets_possible_extensions().pick_random()
            else {
                avg += selection.len();
                if selection.len() < min {
                    min = selection.len();
                    min_cards = selection.clone();
                }
                if selection.len() > max {
                    max = selection.len();
                    max_cards = selection.clone();
                }
                continue 'runs; 
            };
            selection.insert(card);
        }
    }

    println!("Average card amount needed: {}", avg as f64 / RUNS as f64);
    println!("Minimum card amount needed: {min}");
    println!("Cards: {}", min_cards.sorted().map(|card| card.to_string()).reduce(|a, b| a + " " + &b).unwrap_or_default());
    println!("Maximum card amount possible: {max}");
    println!("Cards: {}", max_cards.sorted().map(|card| card.to_string()).reduce(|a, b| a + " " + &b).unwrap_or_default());
}