Esempio n. 1
0
    def test_calculate_soft(self):
        hand = Hand()
        multiple_aces = ['A', 'A', 'A', '1', '2', '3']
        for card in multiple_aces:
            hand.dealt_card(Card(card))

        self.assertEqual(hand.calculate_soft(), 19)

        single_ace = ['J', 'A']
        hand = Hand()
        for card in single_ace:
            hand.dealt_card(Card(card))
        self.assertEqual(hand.calculate_soft(), 21)

        no_aces = ['5', '6', '9']
        hand = Hand()
        for card in no_aces:
            hand.dealt_card(Card(card))
        self.assertEqual(hand.calculate_soft(), 20)
Esempio n. 2
0
                new_card1 = deck.pick()
                new_card2 = deck.pick()
                new_hand1 = Hand()
                new_hand2 = Hand()
                new_hand1.cards = [cards_to_split[0], new_card1]
                new_hand2.cards = [cards_to_split[1], new_card2]
                player.hands.extend([new_hand1, new_hand2])
                hand_to_play = new_hand1
                print('\nSplitted! You now hold:')
                for index, hand in enumerate(player.hands):
                    hand_no = index + 1
                    print('Hand {}: {}'.format(hand_no, hand))

    # apply house strategy
    while (not house_hand.is_finalized()):
        house_soft = house_hand.calculate_soft()
        score = house_hand.get_score()
        if (house_soft == 17):
            house_hand.stand()
            print('House stands')
        elif (score < 17):
            new_card2 = deck.pick()
            print('House picked new card {}'.format(new_card2.card))
            house_hand.dealt_card(new_card2)
        else:
            house_hand.stand()

    print('\nHouse Hand: {}'.format(house_hand))
    print('You hold:')
    player_total = []
    for index, hand in enumerate(player.hands):