From a4a3cc90f0ace7102c59560f508123fafe8b34cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Thu, 2 Mar 2023 21:28:37 +0100 Subject: [PATCH] clean up file --- compress.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compress.py b/compress.py index 559954d..4331c04 100644 --- a/compress.py +++ b/compress.py @@ -3,12 +3,12 @@ from enum import Enum from typing import List, Optional import more_itertools -BASE62 = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +BASE62 = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; COLORS = 'rygbp' - +# Some setup for conversion between variant id and name with open("variants.json", 'r') as f: VARIANTS = json.loads(f.read()) @@ -18,11 +18,13 @@ def variant_id(variant_name): def variant_name(variant_id): return next(var['name'] for var in VARIANTS if var['id'] == variant_id) -## Helper method, iterate over chunks of length n in a string + +# Helper method, iterate over chunks of length n in a string def chunks(s: str, n: int): for i in range(0, len(s), n): yield s[i:i+n] + class DeckCard(): def __init__(self, suitIndex: int, rank: int): self.suitIndex: int = suitIndex @@ -46,6 +48,7 @@ class ActionType(Enum): RankClue = 3 EndGame = 4 + class Action(): def __init__(self, type_: ActionType, target: int, value: Optional[int] = None): self.type = type_ @@ -75,6 +78,7 @@ class Action(): return "Player {} ends the game (code {})".format(self.target, self.value) return "Undefined" + def compress_actions(actions: List[Action]) -> str: minType = 0 maxType = 0 @@ -92,6 +96,7 @@ def compress_actions(actions: List[Action]) -> str: out += ''.join(map(compress_action, actions)) return out + def decompress_actions(actions_str: str) -> List[Action]: try: minType = int(actions_str[0]) @@ -173,6 +178,7 @@ def compressJSONGame(game_json: dict) -> str: out += str(variant_id(variant)) return ''.join(more_itertools.intersperse("-", out, 20)) + def decompressJSONGame(game_str: str)->dict: game = {} game_str = game_str.replace("-", "")