add action for voting to terminate the game

This commit is contained in:
Maximilian Keßler 2023-03-02 22:15:47 +01:00
parent a4a3cc90f0
commit bfc72c497d
Signed by: max
GPG Key ID: BCC5A619923C0BA5

View File

@ -47,6 +47,7 @@ class ActionType(Enum):
ColorClue = 2 ColorClue = 2
RankClue = 3 RankClue = 3
EndGame = 4 EndGame = 4
VoteTerminate = 5
class Action(): class Action():
@ -57,7 +58,6 @@ class Action():
@staticmethod @staticmethod
def from_json(action): def from_json(action):
print("Converting {} to an action".format(action))
return Action( return Action(
ActionType(action['type']), ActionType(action['type']),
int(action['target']), int(action['target']),
@ -72,17 +72,18 @@ class Action():
return "Discard card {}".format(self.target) return "Discard card {}".format(self.target)
case ActionType.ColorClue: case ActionType.ColorClue:
return "Clue color {} to player {}".format(self.value, self.target) return "Clue color {} to player {}".format(self.value, self.target)
case ActionType.ColorClue: case ActionType.RankClue:
return "Clue rank {} to player {}".format(self.value, self.target) return "Clue rank {} to player {}".format(self.value, self.target)
case ActionType.EndGame: case ActionType.EndGame:
return "Player {} ends the game (code {})".format(self.target, self.value) return "Player {} ends the game (code {})".format(self.target, self.value)
return "Undefined" case ActionType.VoteTerminate:
return "Players vote to terminate the game"
return "Undefined action"
def compress_actions(actions: List[Action]) -> str: def compress_actions(actions: List[Action]) -> str:
minType = 0 minType = 0
maxType = 0 maxType = 0
print(actions)
if len(actions) != 0: if len(actions) != 0:
minType = min(map(lambda a: a.type.value, actions)) minType = min(map(lambda a: a.type.value, actions))
maxType = max(map(lambda a: a.type.value, actions)) maxType = max(map(lambda a: a.type.value, actions))