struct Player<'a> { dice: [u8; 5], rolls: u8, scores: HashMap<&'a str, Option<u16>>, id: &'a str, } impl<'a> Player<'a> { fn new(id: &'a str) -> Self { let mut rng = rand::thread_rng(); let dice: [u8; 5] = (0..5) .map(|_| rng.gen_range(1..=5)) .collect::<Vec<u8>>() .try_into() .unwrap(); let rolls: u8 = 0; let mut scores = HashMap::new(); ["1", "2", "3", "4", "5", "6", "c", "3ok", "4ok", "fh", "ss", "ls", "gz"] .map(|key| scores.insert(key, None)); ["tts", "bonus", "ts"] .map(|key| scores.insert(key, Some(0))); Player { dice, rolls, scores, id } } }
The Player struct holds a slice of 5 dices, a u8 number of rolls, a hashmap that holds the scores for a player and an id for the player.