def test_hit_or_stand_case_stand(self, input): captured_output = StringIO() sys.stdout = captured_output # Redirects the output (print) deck = deck_of_cards.Deck() player1 = player.Player('Lasse', player.Hand(), player.Chips()) blackjack.hit_or_stand(deck, player1) sys.stdout = sys.__stdout__ # Resets the redirect self.assertEqual(len(player1.hand.cards), 0)
def test_reset_hands(self): deck = deck_of_cards.Deck() player1 = player.Player('Lasse', player.Hand(), player.Chips()) computer1 = player.Player('Lasse', player.Hand(), player.Chips()) blackjack.deal_initial_cards(deck, player1, computer1) blackjack.reset_hands(player1, computer1) result = len(player1.hand.cards) == 0 and len( computer1.hand.cards) == 0 self.assertEqual(result, True)
import deck_of_cards as deckoc import player as pl import pyfiglet as pg import sys deck = deckoc.Deck() # creates new deck object player1 = pl.Player(deck) # creates player 1 object player2 = pl.Player(deck) # creates player 2 object def playRound(): deck.shuffle() # shuffles order of all cards print("Player 1 starts") player1_new_card = player1.deal() deckoc.createAsciiCard(player1_new_card) player1.cards_drawn += 1 # deals card and prints it as ascii art print("Player two's go") player2_new_card = player2.deal() deckoc.createAsciiCard(player2_new_card) player2.cards_drawn += 1 # deals card and prints it as ascii art winning_card = deckoc.decideWin(player1_new_card, player2_new_card) print("This card won: \n") deckoc.createAsciiCard(winning_card) # decides winning card with function and prints the winning card
def main(): global playing # Prints a welcome message ascii_msg.welcome() # Asks for the player's desired display name player_name = input('\nEnter your display name: ') # Deposit Funds funds = deposit() # Asks if the the player would like to play as the dealer or the player choice = play_as_dealer() # Creates an object for the player and the computer bj_player = player_module.Player(player_name, player_module.Hand(), player_module.Chips(funds)) bj_computer = player_module.Player('Computer', player_module.Hand(), player_module.Chips()) while True: # if choice == False - Want to play as player if not choice: print('+-----------------------------------+') print('| You are now playing as the Player |') print('+-----------------------------------+') reset_hands(bj_player, bj_computer) deck = deck_of_cards.Deck() deck.shuffle() deal_initial_cards(deck, bj_player, bj_computer) take_bet(bj_player.chips) show_some_cards(bj_player, bj_computer) # Global variable set to True - False if the player stands while playing: hit_or_stand(deck, bj_player) show_some_cards(bj_player, bj_computer) # If player's hand exceeds 21, player_busts() is called and we break the while loop if bj_player.hand.value > 21: player_busts(bj_player, bj_computer) break # If the player hasn't busted, the dealer's hand is played until it reaches 17 or above # Dealer will Stand on 17 and above if bj_player.hand.value <= 21: while bj_computer.hand.value < 17: hit(deck, bj_computer.hand) show_all_cards(bj_player, bj_computer) check_winner(bj_player, bj_computer) # Informs the player of their total amount of chips print(f'\nYour total chips are at: {bj_player.chips.total}') new_game = input('\nWould you like to play again? y/n: ') if new_game.lower() == 'y': playing = True print('\n' * 100) continue else: print('\n' * 100) ascii_msg.goodbye() break # else (choice == True) - Want to play as dealer else: print('+-----------------------------------+') print('| You are now playing as the Dealer |') print('+-----------------------------------+') reset_hands(bj_player, bj_computer) deck = deck_of_cards.Deck() deck.shuffle() deal_initial_cards(deck, bj_player, bj_computer) take_bet(bj_player.chips) # Show all cards (possible since the player is playing automatically) show_all_cards(bj_computer, bj_player) while True: # Auto-play logic here # The computer will hit on 4-15 and stand on 16-21 if bj_computer.hand.value > 15 and bj_computer.hand.value <= 21: print('+---------------+') print(f'| {bj_computer.name} Stands |') print('+---------------+') break else: hit(deck, bj_computer.hand) show_all_cards(bj_computer, bj_player) # If player's hand exceeds 21, run player_busts() and break out of loop if bj_computer.hand.value > 21: player_busts(bj_computer, bj_player) break # If computer hasn't busted, the Dealer's hand will be played if bj_computer.hand.value <= 21: while playing: # Dealer auto stands at 17, 18, 19, 20, 21 if bj_player.hand.value >= 17 and bj_player.hand.value <= 21: playing = False break hit_or_stand(deck, bj_player) show_all_cards(bj_computer, bj_player) if bj_player.hand.value > 21: playing = False check_winner(bj_computer, bj_player) # Inform Player of their chips total print(f'\nYour total chips are at: {bj_player.chips.total}') new_game = input('\nWould you like to play again? y/n: ') if new_game.lower() == 'y': playing = True print('\n' * 100) continue else: print('\n' * 100) ascii_msg.goodbye() break
def __init__(self): self.player_list = [] self.pots = [] self.deck = deck_of_cards.Deck()
import deck_of_cards as deck import player import dealer #create playerss dealer = dealer.Dealer("Dealer") player_1 = player.Player("Player 1") #create a deck of cards main_deck = deck.Deck() main_deck.shuffle() #create variables player_turn = True dealer_turn = True #initial draw sequence between platyer_1 and dealer def draw_sequence(): #add input for more players to play player_1.draw(main_deck) dealer.draw(main_deck) player_1.draw(main_deck) dealer.draw(main_deck) #prints the card values at play def cards_on_table(player): print("===============================================") #dealer hand if player_turn == False:
def test_deal_initial_cards(self): deck = deck_of_cards.Deck() player1 = player.Player('Lasse', player.Hand(), player.Chips()) computer1 = player.Player('Lasse', player.Hand(), player.Chips()) blackjack.deal_initial_cards(deck, player1, computer1) self.assertEqual(len(player1.hand.cards), len(computer1.hand.cards))
def test_deck_deal(self): deck = deck_of_cards.Deck() dealt_card = deck.deal() result = dealt_card not in deck.deck self.assertTrue(result)
def test_hit(self): deck = deck_of_cards.Deck() hand = player.Hand() blackjack.hit(deck, hand) self.assertEqual(len(hand.cards), 1)
def test_hit_or_stand_case_hit(self, input): deck = deck_of_cards.Deck() player1 = player.Player('Lasse', player.Hand(), player.Chips()) blackjack.hit_or_stand(deck, player1) self.assertEqual(len(player1.hand.cards), 1)
def test_deck_shuffle(self): deck1 = deck_of_cards.Deck() deck2 = deck_of_cards.Deck() deck2.shuffle() result = deck1 == deck2 self.assertFalse(result)
def test_deck_len(self): deck = deck_of_cards.Deck() result = len(deck) self.assertEqual(result, 52)
def __init__(self): self.dealer_cards = [] self.player_cards = {} self.deck = deck_of_cards.Deck(3)
def create_deck(): bj_deck = deck_of_cards.Deck() return bj_deck
def __init__(self, game_name, num_players): self.game_name = game_name self.num_players = num_players self.table = table.Table() self.deck = deck_of_cards.Deck()