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
| 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.
| 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.
| 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.
| 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
|