-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditions.py
More file actions
52 lines (42 loc) · 1.47 KB
/
Conditions.py
File metadata and controls
52 lines (42 loc) · 1.47 KB
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
AVAILABLE_VALUES = {
'X': 1, 'Y': 2, 'Z': 4, 'n_1': 7, 'n_2': 7, 'n_3': 7, 'n_4': 7, 'n_5': 7, 'n_odd': 7, 'n_even': 7, 'sum': 7, 'repeat': 7,
}
def compute_effect(str):
s = 0
for v in AVAILABLE_VALUES:
if v in str:
s |= AVAILABLE_VALUES[v]
return s
class Condition:
def __init__(self, str, vset):
self.str = str
self.vset = vset
self.effect = compute_effect(str)
def __repr__(self):
return self.str
def __lt__(self, other):
return self.str < other.str
class ConditionCard:
def __init__(self, conditions, vset, overlap=False, already_eval=False):
if already_eval:
self.conditions = conditions
return
self.conditions = []
left = vset.copy()
for condition in conditions:
if condition == 'left':
condition_set = left
else:
condition_set = {v for v in (vset if overlap else left) if v.eval(condition)}
left -= condition_set
self.conditions += [Condition(condition, condition_set)]
def __repr__(self):
return ' | '.join(map(repr, self.conditions))
def __iter__(self):
return iter(self.conditions)
def __add__(self, other):
if isinstance(other, ConditionCard):
return ConditionCard(self.conditions + other.conditions, None, already_eval=True)
if not other:
return self
return NotImplementedError