def _init_hand(self, buy_in: int = 1): """This initializes a hand of blackjack with a minimum buy-in of :param buy_in dollars.""" # zeroth check to make sure buy_in denom is in the standard chip denoms buy_in_key = ChipStack.get_chip_string(buy_in) if buy_in_key not in ChipStack.get_empty_stack().keys(): raise KeyError( 'The buy-in value of \'{}\' is not in the standard denominations' .format(buy_in_key)) # also discard any cards in the hand already self.dealer.discard( self.discard_pile, [x.name for x in self.dealer.hand]) # TODO: refactor this... for player in self.players.values(): player.discard(self.discard_pile, [x.name for x in player.hand]) # first check if all players want to buy-in to the hand self.dealt_in_players = list( self.players.keys()) # deal in all players initially self.take_bets(min_bet=buy_in) # second deal hands to all players that are still dealt-in self.deal_cards(list(self.players.values()), n_cards=2, n_visible=2) # two face up self.deal_cards([self.dealer], n_cards=1, n_visible=1) # one face up self.deal_cards([self.dealer], n_cards=1, n_visible=0) # one face down # print out the hands for all players and their bets for player_name in self.dealt_in_players: self.players[player_name].view_hand(all_visible=True) self.dealer.view_hand() # lastly check for any naturals or busts before moving to game loop self.check_for_payouts(end_of_hand=False) return # move to the next state of gameplay
def test_get_chip_string(self): self.assertEqual('$20', ChipStack.get_chip_string(20)) self.assertRaises(ValueError, ChipStack.get_chip_string, 11)