def test_shuffle_deck(self): self.deck = deck.prepare_deck() self.deck2 = deck.prepare_deck() self.assertEqual(self.deck, self.deck2) deck.shuffle_deck(self.deck2) self.assertNotEqual(self.deck, self.deck2) for i in self.deck: self.assertIn(i,self.deck2)
def play(player, dealer, deck): playing = True while playing: print(f"Welcome {player.name} to the Blackjack game") game = Game(player, dealer) print("Distributing cards ") game.give_hand(deck) print(f"Your balance is ${player.balance}") game.set_bet() deck.new_deck() deck.shuffle_deck() # game.give_card(deck) player_play = True dealer_play = True while player_play or dealer_play: try: print("-----------------------------------------") print("Your hand is ") print(player.get_hand()) print(f"Your total points: {player.get_points()}") print("-----------------------------------------") print("The dealer hand is ") print(dealer.get_hand(0)) if player_play: if game.continue_ask() == True and player.get_points() < 21: game.give_card(deck, game.player) print("-----------------------------------------") else: player_play = False if dealer_play == True: if dealer.get_points() < 17: game.give_card(deck, game.dealer) print("-----------------------------------------") else: dealer_play = False except: print("some error happened") else: if game.can_continue(game.player): print("can continue") else: print("You can't continue you reach the limit") player_play = False game.check_winner() print(f"Your balance is ${player.balance}") if player.balance <= 0: print("You need money yo play!!!!") playing = False if game.continue_playing() == False and player.balance > 0: playing = False
h1 = d[0:26] h2 = d[26:] # Take the bottom thirteen cards from h1 and move them to h2. h3 = h1[0:13] h4 = h2 + h3 # TODO: return a value from war() that tells us who won or if we got a tie. # assert result == tie war(h1, h4) if __name__== '__main__': # Shuffle a deck. d = create_deck() shuffle_deck(d) # Deal the deck into 2 hands, one for each player. hands = deal_deck(d, 2) user_hand = hands[0] computer_hand = hands[1] while len(user_hand) > 0 and len(computer_hand) > 0: cmd = input('Enter "p" to play a card or "q" to quit: ') if cmd == 'p': user_card = user_hand.pop() print(user_card) computer_card = computer_hand.pop() print(computer_card) if user_card['value'] > computer_card['value']: print('You: {}'.format(user_card))
''' Create dealer and player\ Create and shuffle the deck Ask for the player's bet Deal the cards ''' dealer = Dealer() player = create_player() deck = create_deck() game_over = False while game_over == False: shuffle_deck(deck) prompt_bet(player) deal(deck, player, dealer) ''' Player's turn: The flag determines when the player's turn is over. If the flag is 0, the turn continues If the flag is 1, the turn is over If flag is -1, the player has busted - skip the dealer's turn ''' flag = 0 while flag == 0: flag = prompt_player_action(deck, player, dealer)
def main(): d.shuffle_deck(deck) deal_hands() print(len(deck), len(player1), len(player2))