def test_deal(): g = Game() assert len(g.player.hand) == 0 assert len(g.dealer.hand) == 0 g.deal() assert len(g.player.hand) == 2 assert len(g.dealer.hand) == 2
def test_deal_card(self): dealt_card = Card(1, SUIT_SPADES) card_in_deck = Card(13, SUIT_SPADES) with patch.object(Game, 'shuffle_deck', autospec=True): game = Game([dealt_card, card_in_deck]) player = Player() game.deal(player) self.assertEqual([card_in_deck], game.card_pool) self.assertEqual([dealt_card], player.hand.cards)
def draw_table(game): print('\n'*100) print(f'Current bet: {game.player.bet}') print(f'Balance: {game.player.balance}\n') print(f'----------PLAYER----------{game.player.hand.value}\n') print(game.player.hand) print(f'----------DEALER----------{game.dealer.hand.value}\n') print(game.dealer.hand) if __name__ == '__main__': game = Game() print('Welcome to Blacjack!') while True: # Create & shuffle the deck, deal two cards to each player game.deal() # Prompt the Player for their bet game.player.setup_bet() # Show cards (but keep one dealer card hidden) game.player.hand.flip_cards() game.dealer.hand.flip_one() draw_table(game) while True: # Prompt for Player to Hit or Stand answer = input('HIT or STAND? ').upper() if answer not in ['HIT', 'STAND']: print('\nOnly HIT or STAND is accepted! Please try again\n') continue elif answer == 'HIT': game.hit() draw_table(game)
def test_game_initial_deal(game: Game): game.deal() player_hands_lens = [len(p.hand) for p in game._players] assert [2] * len(player_hands_lens) == player_hands_lens