-
Notifications
You must be signed in to change notification settings - Fork 0
/
sueca_suits_ranks.py
142 lines (115 loc) · 3.15 KB
/
sueca_suits_ranks.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
suits = {
"S": "Spades",
"D": "Diamonds",
"H": "Hearts",
"C": "Clubs",
}
ranks = {
"A": ["Ace", 11, 1],
"7": ["Seven", 10, 2],
"K": ["King", 4, 3],
"J": ["Jack", 3, 4],
"Q": ["Queen", 2, 5],
"6": ["Six", 0, 6],
"5": ["Five", 0, 7],
"4": ["Four", 0, 8],
"3": ["Three", 0, 9],
"2": ["Two", 0, 10],
}
def valid_suit(s: str):
"""
Checks if the suit is valid or not
Parameters:
s (str): The identifier used to find the suit name
Returns:
answer (bool): Whether the rank is valid or not
"""
if s not in suits:
return False # Convert to make this into a boolean
else:
return True # Convert to make this into a boolean
def valid_rank(r: str):
"""
Checks if the rank is valid or not
Parameters:
r (str): The identifier used to find the rank name
Returns:
answer (bool): Whether the rank is valid or not
"""
if len(r) == 1:
rank = r[0]
elif len(r) == 2:
rank = r[0]
else:
rank = r
if rank not in ranks:
return False # Convert to make this into a boolean
else:
return True # Convert to make this into a boolean
def suit_full_name(s: str):
"""
Returns the full name of the suit
Parameters:
s (str): The identifier used to find the full suit name
Returns:
answer (str): What the suits full name is
"""
suit = s[-1]
if suit in suits:
return suits[f'{suit}']
else:
raise ValueError(f"invalid suit symbol: {suit}")
def rank_points(r: str):
"""
Returns the points associated with the given rank
Parameters:
r (str): A string which contains the rank to get points
Returns:
points (int): The amount of points the rank is worth
"""
if len(r) == 1:
rank = r[0]
elif len(r) == 2:
rank = r[0]
else:
rank = r
if rank in ranks:
return ranks[f'{rank}'][1]
else:
raise ValueError(f"invalid rank symbol: {rank}")
def rank_higher_than(r1: str, r2: str):
"""
Checks if one rank is higher than another
Parameters:
r1 (str): The first rank which is compared
r2 (str): The second rank which r1 is compared too
Returns:
answer (bool): Whether r1 is higher than r2
"""
issue = None
if len(r1) == 1:
r1_rank = r1[0]
elif len(r1) == 2:
r1_rank = r1[0]
else:
r1_rank = r1
if len(r2) == 1:
r2_rank = r2[0]
elif len(r2) == 2:
r2_rank = r2[0]
else:
r2_rank = r2
if r1_rank in ranks:
r1_position = ranks[f'{r1_rank}'][2]
else:
issue = r1_rank
raise ValueError(f"invalid rank symbol: {issue}")
if r2_rank in ranks:
r2_position = ranks[f'{r2_rank}'][2]
else:
issue = r2_rank
raise ValueError(f"invalid rank symbol: {issue}")
if r1_position < r2_position:
return True
else:
return False