Beispiel #1
0
 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
Beispiel #2
0
 def test_get_empty_stack(self):
     empty = {
         '$1': 0,
         '$5': 0,
         '$10': 0,
         '$20': 0,
         '$25': 0,
         '$50': 0,
         '$100': 0
     }
     self.assertEqual(ChipStack.get_empty_stack(), empty)
Beispiel #3
0
 def test_exchange_chips_with_remainders(self):
     cs = ChipStack()
     cs._add_chips({'$25': 3})
     cs.exchange_chips('$25', '$10')
     self.assertEqual(cs.stack['$10'], 7)
     self.assertEqual(cs.stack['$5'], 1)
     cs.stack = ChipStack.get_empty_stack()
     cs._add_chips({'$20': 6})
     cs.exchange_chips('$20', '$50')
     self.assertEqual(cs.stack['$50'], 2)
     self.assertEqual(cs.stack['$20'], 1)