-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparse_decklist.py
65 lines (56 loc) · 2.36 KB
/
parse_decklist.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import re
from collections import defaultdict
from cards import EternalCard, Power
import pdb
# We don't care about setnumber & eternalid right now, but they may be
# relevant in the future. In any case, the json DB has this information
card_parse = re.compile(r"^(?P<count>[0-9]+) (?P<cardname>.+) \(Set(?P<setnumber>[0-9]+) #(?P<eternalid>[0-9]+)\)$")
def read_exported_list(file_name):
with open(file_name) as f:
export_list = f.read().split('\n')
export_list = [x for x in export_list if x]
return parse_export(export_list)
def parse_export(exported_list):
power_base, nonpower_cards, decklist, market_list = [], [], [], []
market = False
for line in exported_list:
if 'MARKET' in line:
market = True
continue
cardmatch = card_parse.match(line)
count = int(cardmatch.group('count'))
name = cardmatch.group('cardname')
card = EternalCard(name=name, market=market)
if card.etype == "Power" and not market:
power = Power(name=name, market=market)
power_base.extend([power.copy() for _ in range(count)])
decklist.extend([power.copy() for _ in range(count)])
elif not market:
nonpower_cards.extend([card.copy() for _ in range(count)])
decklist.extend([card.copy() for _ in range(count)])
else:
if card.etype == "Power":
card = Power(name=name, market=market)
market_list.append(card)
return power_base, nonpower_cards, decklist, market_list
def tabulate_influence_requirements(decklist):
"""
Tabulates the most restrictive influence requirement at each turn
(indicated by the cost of the card) in each faction.
"""
card_reqs, turn_reqs = defaultdict(list), []
influence = 'FTJPS'
for card in decklist:
if card.etype == "Power" or card.market:
continue
card_reqs[card.cost].append(card.influence)
for turn in range(max(card_reqs.keys())+1):
cards = card_reqs[turn]
if turn_reqs:
reqs = turn_reqs[-1].copy()
else:
reqs = {faction: 0 for faction in influence}
for faction in influence:
reqs[faction] = max([inf[faction] for inf in cards if faction in inf] + [reqs[faction]])
turn_reqs.append(reqs)
return turn_reqs, card_reqs