@@ -206,12 +206,10 @@ def select_deck(self, mouse_x, mouse_y):
206
206
# and then go through every card in that deck to find the card. Move that card to the chosen
207
207
# If a chosen card is selected, then it is "unchosen" i.e. removed from the chosen pile
208
208
def choose_card (self , mouse_x , mouse_y , cur_player , dragging ):
209
- if self .select_deck (mouse_x , mouse_y ) == "player" and cur_player == "player" :
209
+ if self .select_deck (mouse_x , mouse_y ) == "player" :
210
210
return self .player_deck .handle_selected (mouse_x , mouse_y , dragging )
211
- elif self .select_deck (mouse_x , mouse_y ) == "opposite" and cur_player == "opposite" :
211
+ if self .select_deck (mouse_x , mouse_y ) == "opposite" :
212
212
return self .opposite_deck .handle_selected (mouse_x , mouse_y , dragging )
213
- else :
214
- return "Not Selected " + cur_player
215
213
216
214
def rotate_deck (self , order ):
217
215
if order == [2 , 1 ]:
@@ -224,6 +222,34 @@ def move_to_discard(self):
224
222
self .discard_deck .transfer_all_cards_to_deck (current_deck )
225
223
self .current_deck .remove_card (current_deck )
226
224
225
+ def check_winner (self ):
226
+ player = self .player_deck .get_deck ()
227
+ opposite = self .opposite_deck .get_deck ()
228
+
229
+ if len (player ) == 0 :
230
+ return "player"
231
+
232
+ if len (opposite ) == 0 :
233
+ return "opposite"
234
+
235
+ player_2_count = 0
236
+ for card in player :
237
+ if card .get_value () == "2" :
238
+ player_2_count += 1
239
+
240
+ if player_2_count == 4 :
241
+ return "player"
242
+
243
+ opposite_2_count = 0
244
+ for card in opposite :
245
+ if card .get_value () == "2" :
246
+ opposite_2_count += 1
247
+
248
+ if opposite_2_count == 4 :
249
+ return "opposite"
250
+
251
+ return "none"
252
+
227
253
def play (self , player , turn ):
228
254
operating_deck = None
229
255
if player == "player" :
@@ -232,11 +258,10 @@ def play(self, player, turn):
232
258
operating_deck = self .opposite_deck .get_chosen ()
233
259
234
260
if self .valid_move (operating_deck , player , turn ):
235
- pass
236
261
# If valid move, then move old cards in current to discard
237
262
self .move_to_discard ()
238
263
# move chosen to current
239
- self .move_chosen_to_current (" player" )
264
+ self .move_chosen_to_current (player )
240
265
241
266
return True
242
267
# return "success" / true
@@ -319,30 +344,30 @@ def valid_move(self, operating_deck, player, turn):
319
344
if self .current_deck .get_length () == 1 :
320
345
if current_deck [0 ].get_value () == "2" :
321
346
if len (operating_deck ) == 1 :
322
- if operating_deck [0 ] != "2" :
347
+ if operating_deck [0 ]. get_value () != "2" :
323
348
if self .quad_beat_two (operating_deck ) or self .triple_beat_two (operating_deck ) or \
324
349
self .special_beat_two (operating_deck ):
325
350
return True
326
351
327
352
return False
328
353
else :
329
- if compare_suits (operating_deck [0 ], current_deck [0 ]) == "player" :
354
+ if compare (operating_deck [0 ], current_deck [0 ]) == "player" :
330
355
return True
331
356
else :
332
357
return False
333
- elif len (operating_deck ) == 2 or len ( operating_deck ) == 4 :
334
- if operating_deck [ 0 ] != "2" or not is_same (operating_deck ):
358
+ elif len (operating_deck ) == 4 :
359
+ if not is_same (operating_deck ):
335
360
return False
336
361
else :
337
362
return True
338
363
elif len (operating_deck ) == 3 :
339
364
return False
340
365
elif len (operating_deck ) % 2 == 0 and len (operating_deck ) > 5 :
341
- return operating_deck [ 0 ] == "2" and self .is_double_consecutive (operating_deck )
366
+ return self .is_double_consecutive (operating_deck )
342
367
else :
343
368
return False
344
369
else :
345
- if compare_suits (operating_deck [0 ], current_deck [0 ]) == "player" :
370
+ if compare (operating_deck [0 ], current_deck [0 ]) == "player" :
346
371
return True
347
372
else :
348
373
return False
@@ -352,7 +377,7 @@ def valid_move(self, operating_deck, player, turn):
352
377
if len (operating_deck ) == 1 :
353
378
return False
354
379
elif len (operating_deck ) == 2 :
355
- if operating_deck [0 ] != "2" :
380
+ if operating_deck [0 ]. get_value () != "2" :
356
381
if self .quad_beat_two (operating_deck ) or self .special_beat_two (operating_deck ):
357
382
return True
358
383
else :
@@ -366,12 +391,12 @@ def valid_move(self, operating_deck, player, turn):
366
391
else :
367
392
return False
368
393
elif len (operating_deck ) == 4 :
369
- if operating_deck [0 ] != "2" or not is_same (operating_deck ):
394
+ if operating_deck [0 ]. get_value () != "2" or not is_same (operating_deck ):
370
395
return False
371
396
else :
372
397
return True
373
398
elif len (operating_deck ) % 2 == 0 and len (operating_deck ) > 5 :
374
- return operating_deck [0 ] == "2" and self .is_double_consecutive (operating_deck )
399
+ return operating_deck [0 ]. get_value () == "2" and self .is_double_consecutive (operating_deck )
375
400
else :
376
401
return False
377
402
else :
@@ -479,12 +504,12 @@ def special_beat_two(self, current_deck):
479
504
return False
480
505
481
506
def is_consecutive (self , operating_deck ):
482
- if operating_deck [0 ] == "2" :
507
+ if operating_deck [- 1 ]. get_value () == "2" :
483
508
return False
484
509
485
510
i = 1
486
511
while i < len (operating_deck ):
487
- if int (operating_deck [i - 1 ].get_value ()) >= int (operating_deck [i ].get_value ()) + 1 :
512
+ if to_int_value (operating_deck [i - 1 ].get_value ()) >= to_int_value (operating_deck [i ].get_value ()):
488
513
return False
489
514
490
515
i += 1
0 commit comments