End Criteria

EndCondition

Bases: Protocol

Interface representing a condition under which a game may end.

Source code in /home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
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
class EndCondition(Protocol):
    """Interface representing a condition under which a game may end."""

    def game_over(game_data: GameData) -> bool:
        """Check if the game is over based on the provided game data.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            bool: True if the game is over, False otherwise.
        """
        ...

    def winner(game_data: GameData) -> Optional[TeamName]:
        """Determine the winner of the game based on the provided game data.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            Optional[TeamName]: The team name of the winner or None if there is no winner (tie or the game is not over).
        """
        ...

    def loser(game_data: GameData) -> Optional[TeamName]:
        """Determine the loser of the game based on the provided game data.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            Optional[TeamName]: The team name of the loser or None if there is no loser (no game over or multiple players lose).
        """
        ...

game_over(game_data)

Check if the game is over based on the provided game data.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • bool( bool ) –

    True if the game is over, False otherwise.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
13
14
15
16
17
18
19
20
21
22
def game_over(game_data: GameData) -> bool:
    """Check if the game is over based on the provided game data.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        bool: True if the game is over, False otherwise.
    """
    ...

loser(game_data)

Determine the loser of the game based on the provided game data.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • Optional[TeamName]

    Optional[TeamName]: The team name of the loser or None if there is no loser (no game over or multiple players lose).

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
35
36
37
38
39
40
41
42
43
44
def loser(game_data: GameData) -> Optional[TeamName]:
    """Determine the loser of the game based on the provided game data.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        Optional[TeamName]: The team name of the loser or None if there is no loser (no game over or multiple players lose).
    """
    ...

winner(game_data)

Determine the winner of the game based on the provided game data.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • Optional[TeamName]

    Optional[TeamName]: The team name of the winner or None if there is no winner (tie or the game is not over).

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
24
25
26
27
28
29
30
31
32
33
def winner(game_data: GameData) -> Optional[TeamName]:
    """Determine the winner of the game based on the provided game data.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        Optional[TeamName]: The team name of the winner or None if there is no winner (tie or the game is not over).
    """
    ...

InterceptionEndCondition

Bases: EndCondition

End condition representing that a game ends if a team has k interception tokens, in which case it wins.

Source code in /home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class InterceptionEndCondition(EndCondition):
    """End condition representing that a game ends if a team has k interception tokens, in which case it wins."""

    def __init__(self, k: int = MAX_OFFICIAL_INTERCEPTIONS):
        """Initialize the InterceptionEndCondition.

        Args:
            k (int, optional): The number of interception tokens required for the game to end. Defaults to MAX_OFFICIAL_INTERCEPTIONS.
        """
        self.k = k

    def game_over(self, game_data: GameData) -> bool:
        """Check if the game is over due to reaching k interceptions based on the provided game data.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            bool: True if the game is over, False otherwise.
        """
        return any(interceptions == self.k for interceptions in game_data.interceptions)

    def winner(self, game_data: GameData) -> Optional[TeamName]:
        """Determine the winner of the game due to reaching k interceptions based on the provided game data.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            Optional[TeamName]: The team name of the winner according to this condition, or None if there is no winner yet.
        """
        # if the game has not finished or multiple players win, the winner is undecided 
        if not self.game_over(game_data) or Counter(game_data.interceptions)[self.k] > 1:
            return None
        winner = game_data.interceptions.index(self.k)
        return TeamName(winner)

    def loser(self, game_data: GameData) -> Optional[TeamName]:
        """Determine the loser of the game based on the provided game data. Since interceptions determine a winner, None is returned.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            Optional[TeamName]: Always returns None for this condition as there is no loser.
        """
        return None

__init__(k=MAX_OFFICIAL_INTERCEPTIONS)

Initialize the InterceptionEndCondition.

Parameters:
  • k (int) –

    The number of interception tokens required for the game to end. Defaults to MAX_OFFICIAL_INTERCEPTIONS.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
 99
100
101
102
103
104
105
def __init__(self, k: int = MAX_OFFICIAL_INTERCEPTIONS):
    """Initialize the InterceptionEndCondition.

    Args:
        k (int, optional): The number of interception tokens required for the game to end. Defaults to MAX_OFFICIAL_INTERCEPTIONS.
    """
    self.k = k

game_over(game_data)

Check if the game is over due to reaching k interceptions based on the provided game data.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • bool( bool ) –

    True if the game is over, False otherwise.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
107
108
109
110
111
112
113
114
115
116
def game_over(self, game_data: GameData) -> bool:
    """Check if the game is over due to reaching k interceptions based on the provided game data.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        bool: True if the game is over, False otherwise.
    """
    return any(interceptions == self.k for interceptions in game_data.interceptions)

loser(game_data)

Determine the loser of the game based on the provided game data. Since interceptions determine a winner, None is returned.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • Optional[TeamName]

    Optional[TeamName]: Always returns None for this condition as there is no loser.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
133
134
135
136
137
138
139
140
141
142
def loser(self, game_data: GameData) -> Optional[TeamName]:
    """Determine the loser of the game based on the provided game data. Since interceptions determine a winner, None is returned.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        Optional[TeamName]: Always returns None for this condition as there is no loser.
    """
    return None

winner(game_data)

Determine the winner of the game due to reaching k interceptions based on the provided game data.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • Optional[TeamName]

    Optional[TeamName]: The team name of the winner according to this condition, or None if there is no winner yet.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def winner(self, game_data: GameData) -> Optional[TeamName]:
    """Determine the winner of the game due to reaching k interceptions based on the provided game data.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        Optional[TeamName]: The team name of the winner according to this condition, or None if there is no winner yet.
    """
    # if the game has not finished or multiple players win, the winner is undecided 
    if not self.game_over(game_data) or Counter(game_data.interceptions)[self.k] > 1:
        return None
    winner = game_data.interceptions.index(self.k)
    return TeamName(winner)

MiscommunicationEndCondition

Bases: EndCondition

End condition representing that a game ends if a team has k miscommunication tokens, in which case it loses.

Source code in /home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class MiscommunicationEndCondition(EndCondition):
    """End condition representing that a game ends if a team has k miscommunication tokens, in which case it loses."""

    def __init__(self, k: int = MAX_OFFICIAL_MISCOMMUNICATIONS):
        """Initialize the MiscommunicationEndCondition.

        Args:
            k (int, optional): The number of miscommunication tokens required for the game to end. Defaults to MAX_OFFICIAL_MISCOMMUNICATIONS.
        """
        self.k = k

    def game_over(self, game_data: GameData) -> bool:
        """Check if the game is over due to reaching k miscommunications based on the provided game data.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            bool: True if the game is over, False otherwise.
        """
        return any(miscommunications == self.k for miscommunications in game_data.miscommunications)

    def winner(self, game_data: GameData) -> Optional[TeamName]:
        """Determine the winner of the game based on the provided game data. Since miscommunications determine a loser, None is returned.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            Optional[TeamName]: Always returns None for this condition as there is no win condition.
        """
        return None

    def loser(self, game_data: GameData) -> Optional[TeamName]:
        """Determine the loser of the game due to reaching k miscommunications based on the provided game data.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            Optional[TeamName]: The team name of the loser according to this condition, or None if there is no loser yet.
        """
        # if the game has not finished or multiple players lose, the loser is undecided 
        if not self.game_over(game_data) or Counter(game_data.miscommunications)[self.k] > 1:
            return None
        loser = game_data.miscommunications.index(self.k)
        return TeamName(loser)

__init__(k=MAX_OFFICIAL_MISCOMMUNICATIONS)

Initialize the MiscommunicationEndCondition.

Parameters:
  • k (int) –

    The number of miscommunication tokens required for the game to end. Defaults to MAX_OFFICIAL_MISCOMMUNICATIONS.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
50
51
52
53
54
55
56
def __init__(self, k: int = MAX_OFFICIAL_MISCOMMUNICATIONS):
    """Initialize the MiscommunicationEndCondition.

    Args:
        k (int, optional): The number of miscommunication tokens required for the game to end. Defaults to MAX_OFFICIAL_MISCOMMUNICATIONS.
    """
    self.k = k

game_over(game_data)

Check if the game is over due to reaching k miscommunications based on the provided game data.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • bool( bool ) –

    True if the game is over, False otherwise.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
58
59
60
61
62
63
64
65
66
67
def game_over(self, game_data: GameData) -> bool:
    """Check if the game is over due to reaching k miscommunications based on the provided game data.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        bool: True if the game is over, False otherwise.
    """
    return any(miscommunications == self.k for miscommunications in game_data.miscommunications)

loser(game_data)

Determine the loser of the game due to reaching k miscommunications based on the provided game data.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • Optional[TeamName]

    Optional[TeamName]: The team name of the loser according to this condition, or None if there is no loser yet.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def loser(self, game_data: GameData) -> Optional[TeamName]:
    """Determine the loser of the game due to reaching k miscommunications based on the provided game data.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        Optional[TeamName]: The team name of the loser according to this condition, or None if there is no loser yet.
    """
    # if the game has not finished or multiple players lose, the loser is undecided 
    if not self.game_over(game_data) or Counter(game_data.miscommunications)[self.k] > 1:
        return None
    loser = game_data.miscommunications.index(self.k)
    return TeamName(loser)

winner(game_data)

Determine the winner of the game based on the provided game data. Since miscommunications determine a loser, None is returned.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • Optional[TeamName]

    Optional[TeamName]: Always returns None for this condition as there is no win condition.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
69
70
71
72
73
74
75
76
77
78
def winner(self, game_data: GameData) -> Optional[TeamName]:
    """Determine the winner of the game based on the provided game data. Since miscommunications determine a loser, None is returned.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        Optional[TeamName]: Always returns None for this condition as there is no win condition.
    """
    return None

RoundEndCondition

Bases: EndCondition

End condition representing that a game ends if it reaches k rounds, in which case no winner or loser is decided.

Source code in /home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
class RoundEndCondition(EndCondition):
    """End condition representing that a game ends if it reaches k rounds, in which case no winner or loser is decided."""

    def __init__(self, k: int = MAX_OFFICIAL_ROUNDS):
        """Initialize the RoundEndCondition.

        Args:
            k (int, optional): The number of rounds required for the game to end. Defaults to MAX_OFFICIAL_ROUNDS.
        """
        self.k = k

    def game_over(self, game_data: GameData) -> bool:
        """Check if the game is over due to reaching k rounds played based on the provided game data.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            bool: True if the game is over, False otherwise.
        """
        return game_data.rounds_played == self.k

    def winner(self, game_data: GameData) -> Optional[TeamName]:
        """Determine the winner of the game based on the provided game data. Since rounds played determines no winner, None is returned.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            Optional[TeamName]: Always returns None for this condition as there is no winner.
        """
        return None

    def loser(self, game_data: GameData) -> Optional[TeamName]:
        """Determine the loser of the game based on the provided game data. Since rounds played determines no loser, None is returned.

        Args:
            game_data (GameData): The game data to check.

        Returns:
            Optional[TeamName]: Always returns None for this condition as there is no loser.
        """
        return None

__init__(k=MAX_OFFICIAL_ROUNDS)

Initialize the RoundEndCondition.

Parameters:
  • k (int) –

    The number of rounds required for the game to end. Defaults to MAX_OFFICIAL_ROUNDS.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
148
149
150
151
152
153
154
def __init__(self, k: int = MAX_OFFICIAL_ROUNDS):
    """Initialize the RoundEndCondition.

    Args:
        k (int, optional): The number of rounds required for the game to end. Defaults to MAX_OFFICIAL_ROUNDS.
    """
    self.k = k

game_over(game_data)

Check if the game is over due to reaching k rounds played based on the provided game data.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • bool( bool ) –

    True if the game is over, False otherwise.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
156
157
158
159
160
161
162
163
164
165
def game_over(self, game_data: GameData) -> bool:
    """Check if the game is over due to reaching k rounds played based on the provided game data.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        bool: True if the game is over, False otherwise.
    """
    return game_data.rounds_played == self.k

loser(game_data)

Determine the loser of the game based on the provided game data. Since rounds played determines no loser, None is returned.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • Optional[TeamName]

    Optional[TeamName]: Always returns None for this condition as there is no loser.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
178
179
180
181
182
183
184
185
186
187
def loser(self, game_data: GameData) -> Optional[TeamName]:
    """Determine the loser of the game based on the provided game data. Since rounds played determines no loser, None is returned.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        Optional[TeamName]: Always returns None for this condition as there is no loser.
    """
    return None

winner(game_data)

Determine the winner of the game based on the provided game data. Since rounds played determines no winner, None is returned.

Parameters:
  • game_data (GameData) –

    The game data to check.

Returns:
  • Optional[TeamName]

    Optional[TeamName]: Always returns None for this condition as there is no winner.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/end_criteria.py
167
168
169
170
171
172
173
174
175
176
def winner(self, game_data: GameData) -> Optional[TeamName]:
    """Determine the winner of the game based on the provided game data. Since rounds played determines no winner, None is returned.

    Args:
        game_data (GameData): The game data to check.

    Returns:
        Optional[TeamName]: Always returns None for this condition as there is no winner.
    """
    return None