-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.py
More file actions
76 lines (63 loc) · 1.97 KB
/
Copy pathvalidators.py
File metadata and controls
76 lines (63 loc) · 1.97 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from skullconstants import HEADER_SIZE, SkullEnum
def choose_validator(payload, chosen):
"""
Validator function for choose function in Player class
params:
payload: payload containing the information this validator function needs
chosen: chosen value
returns:
True if chosen value is valid
False otherwise
"""
_has_theme = has_theme(payload["cards"], payload["theme"])
special_tuple = (
SkullEnum.WHITE,
SkullEnum.MERMAID,
SkullEnum.PIRATE,
SkullEnum.GREENPIRATE,
SkullEnum.SKULLKING,
)
if not chosen.isdecimal():
print(f"Choose a number between 1 and {len(payload['cards'])}")
return False
if not (1 <= int(chosen) <= len(payload["cards"])):
print(f"Choose a number between 1 and {len(payload['cards'])}")
return False
if (
_has_theme
and payload["cards"][int(chosen) - 1].CARDTYPE not in special_tuple
and payload["cards"][int(chosen) - 1].CARDTYPE != payload["theme"]
):
print(
f"You have a card of the theme {payload['theme']}. You must choose that card"
)
return False
return True
def yohoho_validator(payload, chosen):
"""
Validator function for yohoho function in Player class
params:
payload: payload containing the information this validator function needs
chosen: chosen value
returns:
True if chosen value is valid
False otherwise
"""
if not chosen.isdecimal():
print(f"Choose a number!")
return False
return True
def has_theme(cards, theme):
"""
evaluate if a set of cards has a specific theme
params:
cards: a list of SkullCard object
theme: the desired theme to investigate on
returns:
True if there is a card of the given theme
False otherwise
"""
for card in cards:
if card.CARDTYPE == theme:
return True
return False