예제 #1
0
    def test_compare_push(self):  # Same value should push
        dDeck = ["10", "J"]
        pDeck = ["10", "J"]

        dw, pw = bs.compare(pDeck, dDeck)

        self.assertEqual(dw, 0)
        self.assertEqual(pw, 0)
예제 #2
0
    def test_compare_playerWin(self):  # Player with higher value should win
        dDeck = ["10", "9"]
        pDeck = ["10", "J"]

        dw, pw = bs.compare(pDeck, dDeck)

        self.assertEqual(dw, 0)
        self.assertEqual(pw, 1)
예제 #3
0
def simulate(individual, betAmount):
    # status = -1 = dealer win ; 0 = push (equal valued decks) ; 1 = player win.
    dDeck = bjs.dealerInitial()  # Give dealer two cards.

    botChoice = 1
    bDeck = []
    bjs.hit(bDeck)

    #  While botChoice = 1 (hit)
    while botChoice == 1:
        #  Give a card
        bjs.hit(bDeck)

        #  Check for soft aces.
        bDeck = bjs.checkAce(bDeck)

        #  Check if bust
        if bjs.bust(bDeck):  # If player busts
            status = -1
            return status, betAmount
        #  Check for 21
        if bjs.checkBlackjack(dDeck):
            break

        #  Make a new choice with the new deck.
        botChoice = makeDecision(individual, bDeck, dDeck)

    #  If the player has a blackjack
    if bjs.checkBlackjack(bDeck):
        #  If the dealer also has a blackjack.
        if bjs.checkBlackjack(dDeck):
            status = 0
            return status, betAmount
        #  If the dealer doesn't have blackjack.
        else:
            status = 1
            betAmount *= 3
            return status, betAmount

    #  If the dealer has a blackjack
    elif bjs.checkBlackjack(dDeck):
        status = -1
        return status, betAmount

    #  If stand
    if botChoice == 0:
        bjs.dealerAfter(dDeck)
        dw, pw = bjs.compare(bDeck, dDeck)
        if dw == 1 and pw == 0:
            status = -1
            return status, betAmount
        elif dw == 0 and pw == 1:
            status = 1
            return status, betAmount
        elif dw == 0 and pw == 0:
            status = 0
            return status, betAmount

    #  If double down
    elif botChoice == 2:
        #  Double the betting money.
        betAmount *= 2

        #  Give bot a single random card from the deck.
        bDeck = bjs.hit(bDeck)

        #  Check if bust.
        if bjs.bust(bDeck):
            status = -1
            return status, betAmount

        #  Compare to dealer
        dw, pw = bjs.compare(bDeck, dDeck)
        if dw == 1 and pw == 0:
            status = -1
            return status, betAmount
        elif dw == 0 and pw == 1:
            status = 1
            return status, betAmount
        elif dw == 0 and pw == 0:
            status = 0
            return status, betAmount

    #  If split
    elif botChoice == 3:
        #  Create two separate decks.
        bDeck1 = [bDeck[0]]  # Deck 1
        bDeck2 = [bDeck[1]]  # Deck 2

        bDecks = [bDeck1, bDeck2]

        # For each deck, player win, equal or dealer win.
        deckStatus = [
            0, 0
        ]  # -1 = dealer win ; 0 = push (equal valued decks) ; 1 = player win.

        #  Play with both hands
        deckNumber = -1

        #  Double the bet
        betAmount *= 2

        for deck in bDecks:
            deckNumber += 1
            botChoice = 1

            #  While botChoice = 1 (hit)
            while botChoice == 1:
                #  Give a card
                bjs.hit(deck)

                #  Check for soft aces.
                deck = bjs.checkAce(deck)

                #  Check if bust
                if bjs.bust(deck):
                    deckStatus[deckNumber] = -1
                    break

                #  Check for 21
                if bjs.checkBlackjack(deck):
                    break

                #  Make a new choice with the new deck.
                botChoice = makeDecision(individual, deck, dDeck)

            #  If the player has a blackjack
            if bjs.checkBlackjack(deck):
                #  If the dealer also has a blackjack.
                if bjs.checkBlackjack(dDeck):
                    deckStatus[deckNumber] = 0
                #  If the dealer doesn't have blackjack.
                else:
                    deckStatus[deckNumber] = 1
            #  If the dealer has a blackjack
            elif bjs.checkBlackjack(dDeck):
                deckStatus[deckNumber] = -1

            #  If stand
            if botChoice == 0:
                bjs.dealerAfter(dDeck)
                dw, pw = bjs.compare(deck, dDeck)
                if dw == 1 and pw == 0:
                    deckStatus[deckNumber] = -1
                elif dw == 0 and pw == 1:
                    deckStatus[deckNumber] = 1
                elif dw == 0 and pw == 0:
                    deckStatus[deckNumber] = 0

            #  If double down
            elif botChoice == 2:
                #  Double the betting money.
                betAmount *= 2

                #  Give bot a single random card from the deck.
                deck = bjs.hit(deck)

                #  Check if bust.
                if bjs.bust(deck):
                    deckStatus[deckNumber] = -1

                #  Compare to dealer
                dw, pw = bjs.compare(deck, dDeck)
                if dw == 1 and pw == 0:
                    deckStatus[deckNumber] = -1
                elif dw == 0 and pw == 1:
                    deckStatus[deckNumber] = 1
                elif dw == 0 and pw == 0:
                    deckStatus[deckNumber] = 0
        return deckStatus, betAmount
예제 #4
0
def evalDecks(deckDict, dDeck, betDict, bDeck):
    player = 0

    dealerAfter(dDeck)

    for deck in deckDict.values():
        if type(deck[0]) == str:
            player += 1
            print("====================================================")
            print(f"Player {player}:")

            dw, pw = bjs.compare(deck,
                                 dDeck)  # dw = dealer win ; pw = player win
            if dw == 1 and pw == 0:
                print("The dealer won, better luck next time.\n"
                      f"You lost €{betDict[player]}.")
            elif dw == 0 and pw == 0:
                print("You and the dealer had the same value\n"
                      f"You received your bet of €{betDict[player]} back.")
            elif dw == 0 and pw == 1:
                print(f"Congratulations! You won €{betDict[player]}")

        elif type(deck[0]) == list:
            player += 1
            for splitDeck in deck:
                print(f"Player {player}:")

                dw, pw = bjs.compare(
                    splitDeck, dDeck)  # dw = dealer win ; pw = player win
                if dw == 1 and pw == 0:
                    print("The dealer won, better luck next time.\n"
                          f"You lost €{betDict[player]/2}.")
                elif dw == 0 and pw == 0:
                    print(
                        "You and the dealer had the same value\n"
                        f"You received your bet of €{betDict[player]/2} back.")
                elif dw == 0 and pw == 1:
                    print(f"Congratulations! You won €{betDict[player]/2}")

    if type(bDeck[0]) == str:
        player += 1
        print("====================================================")
        print("Bot:")

        dw, pw = bjs.compare(bDeck, dDeck)  # dw = dealer win ; pw = player win
        if dw == 1 and pw == 0:
            print("The dealer won, better luck next time.")
        elif dw == 0 and pw == 0:
            print("You and the dealer had the same value")
        elif dw == 0 and pw == 1:
            print(f"Congratulations, You won!")

    elif type(bDeck[0]) == list:
        player += 1
        for splitDeck in bDeck:
            print("Bot:")

            dw, pw = bjs.compare(splitDeck,
                                 dDeck)  # dw = dealer win ; pw = player win
            if dw == 1 and pw == 0:
                print("The dealer won, better luck next time.")
            elif dw == 0 and pw == 0:
                print("You and the dealer had the same value.")
            elif dw == 0 and pw == 1:
                print(f"Congratulations, you won!")