def do_action(self): player = self.current_player hand_card = None for card in player.hand: if card.selected: hand_card = card if hand_card == None: return False table_cards = [card for card in self.table if card.selected] if len(table_cards) == 0: player.hand.remove(hand_card) self.table.append(hand_card) self.logSignal.emit('{} trailed with {}\n'.format( player, hand_card)) else: if type(player) is Player: if not is_valid_combo(hand_card.get_hand_value(), [c.value for c in table_cards]): self.logSignal.emit('Invalid move\n') return False for c in table_cards: player.deck.append(c) self.table.remove(c) player.hand.remove(hand_card) player.deck.append(hand_card) self.last_pick = player self.logSignal.emit('{} used {} to capture:\n{}\n'.format( player, hand_card, '\n'.join([str(c) for c in table_cards]))) if len(self.table) == 0: player.sweeps += 1 self.logSignal.emit('Sweep!\n') self.sweepSignal.emit() return True
def test_empty_table(self): self.assertFalse( is_valid_combo(6, []), 'Attempting to take from empty table should return False.')
def test_valid_combo_including_duplicate_values(self): self.assertTrue(is_valid_combo(13, [7, 6, 1, 8, 5, 12, 13, 12, 1]), 'Attempting legal move should return True.')
def test_invalid_combo_with_large_amount_of_cards(self): self.assertFalse( is_valid_combo(16, [ 11, 7, 9, 3, 6, 4, 5, 6, 8, 2, 7, 14, 1, 1, 9, 15, 10, 1, 4, 7, 13, 2 ]), 'Invalid move should be detected before generating subcombos.')
def test_valid_combo_with_multiple_values(self): self.assertTrue(is_valid_combo(8, [4, 6, 7, 1, 4, 2]), 'Attempting legal move should return True.')
def test_valid_combo_with_subcombos_of_over_three_cards(self): self.assertTrue( is_valid_combo(10, [6, 3, 1, 1, 2, 4, 3, 2, 2, 2, 2, 2]), 'Should be possible to combine multiple cards.')
def test_same_card_in_two_combos(self): self.assertFalse(is_valid_combo(7, [3, 4, 4]), 'One card can only contribute to one combination!')
def test_larger_than_hand_chosen(self): self.assertFalse( is_valid_combo(5, [1, 2, 3, 4, 6]), 'Attempting to take card larger than hand should return False.')
def test_pick_one_different_from_hand(self): self.assertFalse( is_valid_combo(7, [3]), 'Taking one card different from hand should return False.')
def test_pick_multiple_equal_cards(self): self.assertTrue(is_valid_combo(9, [9, 9, 9]), 'Should be able to take multiple equal cards.')
def test_pick_one_equal_card(self): self.assertTrue(is_valid_combo(11, [11]), 'Should be able to take one equal card.')