-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHearts(card-game).py
265 lines (180 loc) · 8 KB
/
Hearts(card-game).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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import random
all_cards = ["Black_S2","Black_S3","Black_S4","Black_S5","Black_S6","Black_S7","Black_S8","Black_S9","Black_S10","Black_ACE(s)","Black_JACK(s)","Black_KING(s)","Black_QUEEN(s)",
"Black_C2","Black_C3","Black_C4","Black_C5","Black_C6","Black_C7","Black_C8","Black_C9","Black_C10","Black_ACE(c)","Black_JACK(c)","Black_KING(c)","Black_QUEEN(c)",
"Red_H2","Red_H3","Red_H4","Red_H5","Red_H6","Red_H7","Red_H8","Red_H9","Red_H10","Red_ACE(h)","Red_JACK(h)","Red_KING(h)","Red_QUEEN(h)",
"Red_D2","Red_D3","Red_D4","Red_D5","Red_D6","Red_D7","Red_D8","Red_D9","Red_D10","Red_ACE(d)","Red_JACK(d)","Red_KING(d)","Red_QUEEN(d)"]
res_1 = random.sample(all_cards,13)
print(f"Deck of Player_1 is : {res_1}")
all_card = set(all_cards)
result_1 = set(res_1)
result_2 = all_card - result_1
res_2 = random.sample(result_2,13)
print(f"Deck of Player_2 is : {res_2}")
result_3 = set(res_2)
result_4 = all_card - (result_1|result_3)
res_3 = random.sample(result_4,13)
print(f"Deck of Player_3 is : {res_3}")
result_5 = set(res_3)
result_6 = all_card - (result_1|result_3|result_5)
res_4 = random.sample(result_6,13)
print(f"Deck of Player_4 is : {res_4}")
card_count = 0
player_1points = 0
player_2points = 0
player_3points = 0
user_points = 0
while not(len(res_1) == 0) or not(len(res_2) == 0) or not(len(res_3) == 0) or not(len(res_4) == 0) :
player_1 = random.choice(res_1)
print(f"Card picked by player_1 is : {player_1}")
player_2 = random.choice(res_2)
print(f"Card picked by player_2 is : {player_2}")
player_3 = random.choice(res_3)
print(f"Card picked by player_3 is : {player_3}")
print(f"Card deck for USER : {res_4}")
user = input("Pick a card from your deck : ")
print(f"Card picked by player_4 is : {user}")
list_1 = [player_1,player_2,player_2,user]
list_m = max(list_1)
print(f"The highest numbered card in this lot is : {list_m}")
if list_m == player_1:
remove_2 = player_2
remove_3 = player_3
remove_4 = user
tobeadded_list = [player_2,player_3,user]
print(tobeadded_list)
pos = 1
print(f"The original deck of PLayer_1 is : {res_1}")
print(f"The cards to be added in the deck are : {tobeadded_list}")
for i in range(len(tobeadded_list)):
res_1.insert(i + pos, tobeadded_list[i])
print(f"Updated deck of Player_1 is {res_1}")
if remove_2 in res_2:
res_2.pop(res_2.index(remove_2))
print(f"The current deck of Player_2 : {res_2}")
if remove_3 in res_3:
res_3.pop(res_3.index(remove_3))
print(f"The current deck of PLayer_3 : {res_3}")
if remove_4 in res_4:
res_4.pop(res_4.index(remove_4))
print(f"The current deck of User : {res_4}")
else:
print("Didn't update Player_1's deck")
if list_m == player_2:
remove_1 = player_1
remove_3 = player_3
remove_4 = user
tobeadded_list = [player_1,player_3,user]
print(tobeadded_list)
pos = 1
print(f"The original deck of PLayer_2 is : {res_2}")
print(f"The cards to be added in the deck are : {tobeadded_list}")
for i in range(len(tobeadded_list)):
res_2.insert(i + pos, tobeadded_list[i])
print(f"Updated deck of Player_2 is {res_2}")
if remove_1 in res_1:
res_1.pop(res_1.index(remove_1))
print(f"The current deck of Player_1 : {res_1}")
if remove_3 in res_3:
res_3.pop(res_3.index(remove_3))
print(f"The current deck of PLayer_3 : {res_3}")
if remove_4 in res_4:
res_4.pop(res_4.index(remove_4))
print(f"The current deck of User : {res_4}")
else:
print("Didn't update Player_2's deck")
if list_m == player_3:
remove_1 = player_1
remove_2 = player_2
remove_4 = user
tobeadded_list = [player_1,player_2,user]
print(tobeadded_list)
pos = 1
print(f"The original deck of PLayer_3 is : {res_3}")
print(f"The cards to be added in the deck are : {tobeadded_list}")
for i in range(len(tobeadded_list)):
res_3.insert(i + pos, tobeadded_list[i])
print(f"Updated deck of Player_3 is {res_3}")
if remove_1 in res_1:
res_1.pop(res_1.index(remove_1))
print(f"The current deck of Player_1 : {res_1}")
if remove_2 in res_2:
res_2.pop(res_2.index(remove_2))
print(f"The current deck of PLayer_2 : {res_2}")
if remove_4 in res_4:
res_4.pop(res_4.index(remove_4))
print(f"The current deck of User : {res_4}")
else:
print("Didn't update Player_3's deck")
if list_m == user:
remove_1 = player_1
remove_2 = player_2
remove_3 = player_3
tobeadded_list = [player_1,player_2,player_3]
print(tobeadded_list)
pos = 1
print(f"The original deck of User is : {res_4}")
print(f"The cards to be added in the deck are : {tobeadded_list}")
for i in range(len(tobeadded_list)):
res_4.insert(i + pos, tobeadded_list[i])
print(f"Updated deck of User is {res_4}")
if remove_1 in res_1:
res_1.pop(res_1.index(remove_1))
print(f"The current deck of Player_1 : {res_1}")
if remove_2 in res_2:
res_2.pop(res_2.index(remove_2))
print(f"The current deck of PLayer_2 : {res_2}")
if remove_3 in res_3:
res_3.pop(res_3.index(remove_3))
print(f"The current deck of Player_3 : {res_3}")
else:
print("Didn't update User's deck")
if list_m == player_1 :
player_1points += 5
print(player_1points)
print("Player_1 gets all the cards from this round, and thus increases his points tally")
print("Player_2,Player_3,User wins this round")
else :
print("Error PLayer_1")
if list_m == player_2 :
player_2points += 5
print(player_2points)
print("Player_2 gets all the cards from this round, and thus increases his points tally")
print("Player_1,Player_3,User wins this round")
else :
print("Error PLayer_2")
if list_m == player_3 :
player_3points += 5
print(player_3points)
print("Player_3 gets all the cards from this round, and thus increases his points tally")
print("Player_2,Player_1,User wins this round")
else:
print("Error PLayer_3")
if list_m == user :
user_points += 5
print(user_points)
print("User gets all the cards from this round, and thus increases his points tally")
print("Player_2,Player_3,Player_1 wins this round")
else :
print("Error User")
if (len(res_1) == 0) or (len(res_2) == 0) or (len(res_3) == 0) or (len(res_4) == 0):
print(player_1points)
print(player_2points)
print(player_3points)
print(user_points)
else :
print("Points yet to be shown")
#putting this in the IF statement in card count above
list_2 = [player_1points,player_2points,player_3points,user_points]
list_m2 = min(list_2)
print(list_m2)
#some work needed here
if list_m2 == player_1points:
print("Player_1 is the winner")
elif list_m2 == player_2points :
print("Player_2 is the winner")
elif list_m2 == player_3points :
print("Player_3 is the winner")
elif list_m2 == user_points :
print("User is the winner")
else :
print("Error ,can't print winner")