buckshot_roulette_gameplay_engine/
player.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::collections::HashSet;

use crate::{player_number::PlayerNumber, round_number::RoundNumber};

#[derive(Debug, Clone)]
pub struct Player {
    player_number: PlayerNumber,
    wins: HashSet<RoundNumber>,
}

impl Player {
    pub fn new(player_number: PlayerNumber) -> Self {
        Player {
            player_number,
            wins: HashSet::with_capacity(3),
        }
    }

    pub fn number(&self) -> PlayerNumber {
        self.player_number
    }

    pub fn register_win(&mut self, round_number: RoundNumber) {
        assert!(self.wins.insert(round_number));
    }

    pub fn wins(&self) -> &HashSet<RoundNumber> {
        &self.wins
    }
}