コード例 #1
0
 def test_13_simple_strategy_2(self):
     # player == 17
     player_cards = [BlackJackCard('7', 'C'), BlackJackCard('A', 'C')]
     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.simple_strategy(), BlackJackHand.stand, simple_error_message % (
         hand.simple_strategy(), get_printable_cards(player_cards), get_printable_cards(dealer_cards), BlackJackHand.stand))
コード例 #2
0
 def test_07_mimic_dealer_strategy_1(self):
     # less than 17, hit
     player_cards = [BlackJackCard('5', 'C'), BlackJackCard('K', 'C')]
     dealer_cards = [BlackJackCard('6', 'C'), BlackJackCard('3', 'C')]
     deck = CardDecks(2, BlackJackCard)
     hand = BlackJackHand(deck)
     hand.set_initial_cards(player_cards, dealer_cards)
     self.assertEqual(hand.mimic_dealer_strategy(), BlackJackHand.hit, dealer_error_message % (
         hand.mimic_dealer_strategy(), get_printable_cards(player_cards), get_printable_cards(dealer_cards), BlackJackHand.hit))
コード例 #3
0
 def test_15_doubledown_strategy_2(self):
     # player > 11 (has 17)
     player_cards = [BlackJackCard('9', 'C'), BlackJackCard('8', 'D')]
     dealer_cards = [BlackJackCard('3', 'S'), BlackJackCard('J', 'C')]
     deck = CardDecks(2, BlackJackCard)
     hand = BlackJackHand(deck, initial_bet=2.0)
     hand.set_initial_cards(player_cards, dealer_cards)
     self.assertEqual(hand.doubledown_strategy(), BlackJackHand.stand, doubledown_error_message % (
         hand.doubledown_strategy(), get_printable_cards(player_cards), get_printable_cards(dealer_cards), BlackJackHand.stand))
コード例 #4
0
 def test_11_peek_strategy_3(self):
     # player > dealer, stand
     player_cards = [BlackJackCard('9', 'C'), BlackJackCard('A', 'C')]
     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.peek_strategy(), BlackJackHand.stand, peek_error_message % (
         hand.peek_strategy(), get_printable_cards(player_cards), get_printable_cards(dealer_cards), BlackJackHand.stand))
コード例 #5
0
 def test_09_peek_strategy_1(self):
     # player < dealer, hit
     player_cards = [BlackJackCard('9', 'C'), BlackJackCard('K', 'C')]
     dealer_cards = [BlackJackCard('K', 'S'), BlackJackCard('J', 'C')]
     deck = CardDecks(2, BlackJackCard)
     hand = BlackJackHand(deck)
     hand.set_initial_cards(player_cards, dealer_cards)
     self.assertEqual(hand.peek_strategy(), BlackJackHand.hit, peek_error_message % (
         hand.peek_strategy(), get_printable_cards(player_cards), get_printable_cards(dealer_cards), BlackJackHand.hit))
コード例 #6
0
 def test_08_mimic_dealer_strategy_2(self):
     # 17, stand
     player_cards = [BlackJackCard('7', 'C'), BlackJackCard('K', 'C')]
     dealer_cards = [BlackJackCard('6', 'C'), BlackJackCard('3', 'C')]
     deck = CardDecks(2, BlackJackCard)
     hand = BlackJackHand(deck)
     hand.set_initial_cards(player_cards, dealer_cards)
     self.assertEqual(hand.mimic_dealer_strategy(), BlackJackHand.stand, dealer_error_message % (
         hand.mimic_dealer_strategy(), get_printable_cards(player_cards), get_printable_cards(dealer_cards), BlackJackHand.stand))
コード例 #7
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))
コード例 #8
0
    def test_19_play_dealer_turn_1(self):
        # dealer busts
        player_hand = [BlackJackCard('2', 'S'), BlackJackCard('2', 'S')]
        dealer_hand = [BlackJackCard('2', 'S'), BlackJackCard('2', 'S')]
        cards_to_deal = [BlackJackCard('K', 'S'), BlackJackCard(
            'K', 'S'), *dealer_hand, *player_hand]

        deck = MockCardDecks(4, BlackJackCard, cards_to_deal)
        hand = BlackJackHand(deck)
        self.assertRaises(Busted, hand.play_dealer_turn)
コード例 #9
0
    def test_20_play_dealer_turn_2(self):
        # dealer does not bust
        player_hand = [BlackJackCard('2', 'S'), BlackJackCard('2', 'S')]
        dealer_hand = [BlackJackCard('2', 'S'), BlackJackCard('2', 'S')]
        cards_to_deal = [BlackJackCard('3', 'S'), BlackJackCard(
            'K', 'S'), *dealer_hand, *player_hand]

        deck = MockCardDecks(4, BlackJackCard, cards_to_deal)
        hand = BlackJackHand(deck)
        try:
            hand.play_dealer_turn()
        except:
            self.fail('Your play_dealer_turn busted when it should not have.')
コード例 #10
0
    def test_17_play_player_turn_1(self):
        # player busts
        player_hand = [BlackJackCard('2', 'S'), BlackJackCard('2', 'S')]
        dealer_hand = [BlackJackCard('2', 'S'), BlackJackCard('2', 'S')]
        cards_to_deal = [BlackJackCard('K', 'S'), BlackJackCard(
            'K', 'S'), *dealer_hand, *player_hand]

        def strategy(hand):
            if hand.deck.num_cards_left() > 0:
                return BlackJackHand.hit
            return BlackJackHand.stand

        deck = MockCardDecks(4, BlackJackCard, cards_to_deal)
        hand = BlackJackHand(deck)
        self.assertRaises(Busted, hand.play_player_turn, strategy)
コード例 #11
0
    def test_18_play_player_turn_2(self):
        # player does not bust
        player_hand = [BlackJackCard('2', 'S'), BlackJackCard('2', 'S')]
        dealer_hand = [BlackJackCard('2', 'S'), BlackJackCard('2', 'S')]
        cards_to_deal = [BlackJackCard('3', 'S'), BlackJackCard(
            '3', 'S'), *dealer_hand, *player_hand]

        def strategy(hand):
            if hand.deck.num_cards_left() > 0:
                return BlackJackHand.hit
            return BlackJackHand.stand

        deck = MockCardDecks(4, BlackJackCard, cards_to_deal)
        hand = BlackJackHand(deck)
        try:
            hand.play_player_turn(strategy)
        except:
            self.fail('Your play_player_turn busted when it should not have.')
コード例 #12
0
 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))
コード例 #13
0
 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))
コード例 #14
0
 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))
コード例 #15
0
 def test_05_best_value_multiple_aces_1(self):
     # one A with value 1, one A with value 11
     cards = [BlackJackCard('2', 'C'), BlackJackCard(
         'A', 'C'), BlackJackCard('A', 'H')]
     self.assertEqual(BlackJackHand.best_value(cards), 14, best_value_error_message % (
         BlackJackHand.best_value(cards), get_printable_cards(cards), 14))
コード例 #16
0
 def test_06_best_value_multiple_aces_2(self):
     # two A with value 1
     cards = [BlackJackCard('2', 'C'), BlackJackCard('A', 'C'), BlackJackCard(
         'A', 'S'), BlackJackCard('8', 'H'), BlackJackCard('K', 'H')]
     self.assertEqual(BlackJackHand.best_value(cards), 22, best_value_error_message % (
         BlackJackHand.best_value(cards), get_printable_cards(cards), 22))
コード例 #17
0
 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))