-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnoble.py
More file actions
26 lines (20 loc) · 702 Bytes
/
noble.py
File metadata and controls
26 lines (20 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from dataclasses import dataclass
import json
from pathlib import Path
from random import sample
from gemdict import GemDict
NOBLES_JSON_PATH = Path(__file__).with_name("nobles.json")
NOBLE_POINTS = 3
@dataclass(frozen=True)
class Noble:
points: int
price: GemDict
shape = "▲"
def __str__(self):
return ''.join(amount * GemDict.map_color(gem, self.shape) for gem, amount in self.price.items())
@classmethod
def get_nobles(cls, max_nobles):
with NOBLES_JSON_PATH.open() as nobleJsonFile:
noble_dicts = json.load(nobleJsonFile)
nobles = [cls(NOBLE_POINTS, GemDict(dct)) for dct in noble_dicts]
return sample(nobles, max_nobles)