def test_04_best_value_one_ace_2(self): # less than 21, A with value 1 cards = [BlackJackCard('2', 'C'), BlackJackCard( 'A', 'C'), BlackJackCard('K', 'S')] self.assertEqual(BlackJackHand.best_value(cards), 13, best_value_error_message % ( BlackJackHand.best_value(cards), get_printable_cards(cards), 13))
def test_03_best_value_one_ace_1(self): # less than 21, A with value 11 cards = [BlackJackCard('2', 'C'), BlackJackCard( 'A', 'C'), BlackJackCard('7', 'H')] self.assertEqual(BlackJackHand.best_value(cards), 20, best_value_error_message % ( BlackJackHand.best_value(cards), get_printable_cards(cards), 20))
def test_02_best_value_no_aces_2(self): # less than 21 cards = [BlackJackCard('2', 'C'), BlackJackCard( '3', 'C'), BlackJackCard('K', 'H')] self.assertEqual(BlackJackHand.best_value(cards), 15, best_value_error_message % ( BlackJackHand.best_value(cards), get_printable_cards(cards), 15))
def test_01_best_value_no_aces_1(self): # no cards cards = [] self.assertEqual(BlackJackHand.best_value(cards), 0, best_value_error_message % ( BlackJackHand.best_value(cards), get_printable_cards(cards), 0))
def test_16_doubledown_strategy_3(self): # player == 11 player_cards = [BlackJackCard('2', 'C'), BlackJackCard('9', 'H')] dealer_cards = [BlackJackCard('3', 'S'), BlackJackCard('J', 'C')] deck = CardDecks(2, BlackJackCard) hand = BlackJackHand(deck) hand.set_initial_cards(player_cards, dealer_cards) self.assertEqual(hand.doubledown_strategy(), BlackJackHand.doubledown, doubledown_error_message % ( hand.doubledown_strategy(), get_printable_cards(player_cards), get_printable_cards(dealer_cards), BlackJackHand.doubledown)) # make sure the bet doubles when doubling down cards_to_deal = [BlackJackCard('9', 'D'), BlackJackCard('9', 'S'), *dealer_cards, *player_cards] mockdeck = MockCardDecks(4, BlackJackCard, cards_to_deal) hand = BlackJackHand(mockdeck, initial_bet=2.0) hand.set_initial_cards(player_cards, dealer_cards) initial_bet = hand.get_bet() self.assertEqual(initial_bet, 2.0, "Inaccurate initial bet, found %s, expected %s" % (initial_bet, 2.0)) def strategy(hand): if hand.deck.num_cards_left() == 2: return BlackJackHand.doubledown # trigger play_player_turn to double the bet else: return BlackJackHand.stand hand.play_player_turn(strategy) new_bet = hand.get_bet() self.assertEqual(new_bet, 4.0, "Your doubledown strategy did not double the current bet to %s, found %s" % (4.0, new_bet))
def test_06_best_value_multiple_aces_4(self): cards = [BlackJackCard('A', 'C'), BlackJackCard('A', 'C'), BlackJackCard( '3', 'S'), BlackJackCard('A', 'H'), BlackJackCard('5', 'H')] self.assertEqual(BlackJackHand.best_value(cards), 21, best_value_error_message % ( BlackJackHand.best_value(cards), get_printable_cards(cards), 21))