clean up file
This commit is contained in:
parent
7c82aff384
commit
a4a3cc90f0
12
compress.py
12
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("-", "")
|
||||
|
Loading…
Reference in New Issue
Block a user