diff --git a/src/main.rs b/src/main.rs index ee52313..791da77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,38 @@ use rand::seq::SliceRandom; use serde_json::Value; +use std::collections::HashSet; use std::fs::File; use std::io::BufReader; fn main() { let file = File::open("team_names.json").expect("Unable to open JSON"); let reader = BufReader::new(file); - let team_names_json: Value = serde_json::from_reader(reader).expect("Unable to parse JSON"); + let teams_json: Value = serde_json::from_reader(reader).expect("Unable to parse JSON"); - let team_names_list = team_names_json["team_names"].as_array().unwrap(); + let team_names_list = teams_json["team_names"].as_array().unwrap(); + let team_colors = teams_json["team_colors"] + .as_array() + .unwrap() + .iter() + .filter_map(|color| color.as_str()) + .collect::>(); + let mut selected_colors = HashSet::new(); let mut rng = rand::thread_rng(); if let Some(chosen_name) = team_names_list.choose(&mut rng) { println!("Randomly chosen team name: {}", chosen_name); } else { println!("No team names available"); } + + while selected_colors.len() < 3 { + if let Some(color) = team_colors.choose(&mut rng) { + selected_colors.insert(*color); + } + } + + println!("Randomly selected team colors: "); + for color in selected_colors { + println!("- {}", color); + } } diff --git a/team_names.json b/team_names.json index f7f886b..43dd902 100644 --- a/team_names.json +++ b/team_names.json @@ -21,5 +21,22 @@ "Station Grass", "The Ballers", "Keyboard Warriors" + ], + "team_colors": [ + "Red", + "Orange", + "Yellow", + "Green", + "Blue", + "Purple", + "Gray", + "White", + "Black", + "Crimson", + "Teal", + "Ivory", + "Beige", + "Brown", + "Magenta" ] }