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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use super::moves::Move;
use super::characters::Character;

/// Keeps track of how many times you chose a move in a row.
///
/// Used for enforcing three-times-in-a-row rule.
#[derive(Clone, Copy)]
pub struct MoveStreak {
    pub repeated_move: Option<Move>,
    pub times: u8
}

/// Keeps track of how many times you chose a character in a row.
///
/// Used for enforcing three-times-in-a-row rule.
#[derive(Clone, Copy)]
pub struct CharacterStreak {
    pub repeated_character: Option<Character>,
    pub times: u8
}

impl MoveStreak {
    pub fn new() -> Self {
        Self {
            repeated_move: None,
            times: 0
        }
    }

    pub fn add(&mut self, new_move: Move) {
        let is_streak_continued = if let Some(repeated_move) = self.repeated_move {
            repeated_move == new_move
        } else {
            false
        };

        self.repeated_move = Some(new_move);
        self.times = if is_streak_continued {
            self.times + 1
        } else {
            1
        }
    }
}

impl CharacterStreak {
    pub fn new() -> Self {
        Self {
            repeated_character: None,
            times: 0
        }
    }

    pub fn add(&mut self, new_character: Character) {
        let is_streak_continued = if let Some(repeated_character) = self.repeated_character {
            repeated_character == new_character
        } else {
            false
        };

        self.repeated_character = Some(new_character);
        self.times = if is_streak_continued {
            self.times + 1
        } else {
            1
        }
    }
}