From d71dba523ce0c3ba68cec137645695cc2415d9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 14 Mar 2023 21:15:20 +0100 Subject: [PATCH] add deck index to be stored with card, add hash method --- compress.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compress.py b/compress.py index 31b4b86..9becfb6 100644 --- a/compress.py +++ b/compress.py @@ -16,9 +16,10 @@ def chunks(s: str, n: int): class DeckCard(): - def __init__(self, suitIndex: int, rank: int): + def __init__(self, suitIndex: int, rank: int, deck_index=None): self.suitIndex: int = suitIndex self.rank: int = rank + self.deck_index = deck_index @staticmethod def from_json(deck_card): @@ -30,6 +31,10 @@ class DeckCard(): def __repr__(self): return COLORS[self.suitIndex] + str(self.rank) + def __hash__(self): + # should be injective enough, we never use cards with ranks differing by 1000 + return 1000 * self.suitIndex + self.rank + class ActionType(Enum): Play = 0 @@ -197,3 +202,4 @@ def decompressJSONGame(game_str: str)->dict: def link(game_json: dict) -> str: compressed = compressJSONGame(game_json) return "https://hanab.live/replay-json/{}".format(compressed) +