def test_check_double_ace(self):
     gameLogic = GameLogic()
     player = Player(
         [Card('Hearts', 'A'), Card('Clubs', 'A')], False, False, 500, 0)
     self.assertEqual(
         gameLogic.checkSum(player), 12,
         f"gameLogic.checkSum(player) = {gameLogic.checkSum(player)} // Player hand should be 12 because one A is valued as 11 and one as 1"
     )
 def test_check_ace_eleven(self):
     gameLogic = GameLogic()
     player = Player(
         [Card('Hearts', 'A'), Card('Clubs', '2')], False, False, 500, 0)
     self.assertEqual(
         gameLogic.checkSum(player), 13,
         f"gameLogic.checkSum(player) = {gameLogic.checkSum(player)} // Player hand should sum to 13 because A is valued as 11"
     )
 def test_sum(self):
     gameLogic = GameLogic()
     player = Player(
         [Card('Hearts', 'A'), Card('Clubs', 'J')], False, True, 500, 0)
     self.assertEqual(
         gameLogic.checkSum(player), 21,
         f"gameLogic.checkSum(player) = {gameLogic.checkSum(player)} // Ace and Jack should sum to 21"
     )
 def test_check_ace_one(self):
     gameLogic = GameLogic()
     player = Player(
         [Card('Hearts', 'A'),
          Card('Clubs', 'J'),
          Card('Clubs', '9')], False, False, 500, 0)
     self.assertEqual(
         gameLogic.checkSum(player), 20,
         f"gameLogic.checkSum(player) = {gameLogic.checkSum(player)} // Player hand should sum to 20 because A is valued as 1"
     )
 def test_check_double_ace_and_normal_card(self):
     gameLogic = GameLogic()
     player = Player(
         [Card('Hearts', 'A'),
          Card('Clubs', 'A'),
          Card('Clubs', '10')], False, False, 500, 0)
     self.assertEqual(
         gameLogic.checkSum(player), 12,
         f"gameLogic.checkSum(player) = {gameLogic.checkSum(player)} // Player hand should be 12 because both aces are valued as 1"
     )
Exemplo n.º 6
0
        deck.cardDeck))  # Dealer is dealt his first card
    dealer.hand.append(gameLogic.dealCard(
        deck.cardDeck))  # Dealer is dealt his 2nd card

    dealer.printCardsAndSum()  # Prints the dealers hand and sum

    player.playerChoice = True  # Set playerChoice to True, since they have to decide on stand / hit now
    if player.isBlackjack():
        player.playerChoice = False  # Calls isBlackJack method that checks if the players starting hand is blackjack
    while player.playerChoice:  # Loops while player needs to make a choice to hit or stand
        player.playerChoice = player.takeTurn(
            dealer, deck.cardDeck)  # Player needs to take his turn

    dealer.dealerTurn = True  # Set dealerTurn to true so we enter while loop
    if gameLogic.checkSum(
            player
    ) <= 21 and not dealer.roundOver:  # If player's sum is 21 or lower
        dealer.takeTurn(
            player, deck.cardDeck
        )  # Player chose to stand - It's now dealers turn to play -
        # Players sum is added as parameter so we can measure later.

    if player.balance == 0:  # If player is out of money - end the game
        print("You are out of money! Game is over!")
        endGame = True
        quit()

    while True:  # Ask if the player / dealer wants to play another round
        choice = input("Do you want to keep playing?(Y / N)")
        if choice == 'N':  # If N then stop the game
            endGame = True