Пример #1
0
 def test_deal(self):
     self.hand.hand_sum = 0
     self.hand.deal()
     hand = self.hand.hand
     self.assertEqual(10, value(hand[0]))
     self.assertEqual(9, value(hand[1]))
     self.assertEqual(19, self.hand.hand_sum)
Пример #2
0
 def test_hit(self):
     self.hand.hand_sum = 0
     self.hand.deal()
     self.hand.hit()
     hand = self.hand.hand
     self.assertEqual(8, value(hand[2]))
     self.assertEqual(27, self.hand.hand_sum)
Пример #3
0
 def test_handle_bust_ace_first_card(self):
     deck = np.arange(41).tolist()
     hand, h = self.game._initial_deal(deck)
     h.hit()
     self.assertEqual(cn.ACE_ELEVEN, value(hand[0]))
     self.assertEqual(31, h.hand_sum)
     hand_sum = self.game._handle_bust_ace_first_card(h.hand, h.hand_sum)
     self.assertEqual(21, hand_sum)
Пример #4
0
 def _handle_bust_ace_first_card(self, hand, hand_sum):
     """
     Internal method that handles case that first card is a hidden ace,
     which is what caused a bust. By default, the system values ace as 11,
     but if changing this to 1 prevents a bust, it does so.
     Input: hand, hand sum
     Output: hand sum
     """
     if value(hand[0]) == cn.ACE_ELEVEN:
         hand_sum -= cn.TEN_NUM
     return hand_sum
Пример #5
0
 def deal(self):
     """
     Public-facing deal method. Pops initial two cards from deck and adds
     them to hand. Calculates initial sum of cards in hand.
     Output: hand
     """
     self.hand = []
     [self.hand.append(self.deck.pop()) for card in
      range(cn.INITIAL_DEAL_SIZE)]
     for val in self.hand:
         self.hand_sum += value(val)
     return self.hand
Пример #6
0
 def handle_ace(self):
     """
     Internal method for handling case an ace is drawn. Prompt user to
     select a value for ace, either 1 or 11. By default, the system values
     an ace as 11, so if the user specifies 1, then 10 is subtracted from
     the hand sum.
     """
     if value(self.hand[-1]) == cn.ACE_ELEVEN:
         ace_val = input(cn.VALUE_OF_ACE)
         ace_val = self._check_choice(ace_val)
         if ace_val == cn.ACE_ONE:
             self.hand_sum -= cn.TEN_NUM
Пример #7
0
 def test_initial_deal(self):
     deck = np.arange(cn.DECK_SIZE).tolist()
     hand, h = self.game._initial_deal(deck)
     self.assertEqual(2, len(hand))
     self.assertEqual(10, value(hand[0]))
     self.assertEqual(10, value(hand[1]))
Пример #8
0
 def _calculate_sum_of_cards(self):
     """
     Internal method for calculating the sum of cards in a deck.
     Assigns new sum of hand to instance variable hand_sum.
     """
     self.hand_sum += value(self.hand[-1])