blackjack-fuzzy/stats.ipynb
2023-01-17 22:33:49 +01:00

8.5 KiB
Raw Blame History

# !git clone https://github.com/hamidshojaee/BlackJackSim.git
from BlackJackSim.BlackJack import * 
table = Table()
table.players.append(Player())
for i in range(0, 5):
    table.playRound()
    print(table.printVerboseResults())
    table.reset()
Dealer FaceCard = 10, Total = 17, BJ = False, Bust = False, Cards = [10, 2, 5], Player 1, Hand 1, Total = 20, BJ = False, Bust = False, Cards = [10, 10], Actions = [<PlayOptions.STAY: 1>], HandResults.WIN
Dealer FaceCard = 10, Total = 15, BJ = False, Bust = False, Cards = [10, 5], Player 1, Hand 1, Total = 25, BJ = False, Bust = True, Cards = [2, 1, 10, 2, 10], Actions = [<PlayOptions.HIT: 2>, <PlayOptions.HIT: 2>, <PlayOptions.HIT: 2>, <PlayOptions.STAY: 1>], HandResults.LOST
Dealer FaceCard = 7, Total = 19, BJ = False, Bust = False, Cards = [7, 7, 5], Player 1, Hand 1, Total = 19, BJ = False, Bust = False, Cards = [3, 2, 10, 4], Actions = [<PlayOptions.HIT: 2>, <PlayOptions.HIT: 2>, <PlayOptions.STAY: 1>], HandResults.PUSH
Dealer FaceCard = 2, Total = 17, BJ = False, Bust = False, Cards = [2, 10, 4, 1], Player 1, Hand 1, Total = 20, BJ = False, Bust = False, Cards = [10, 10], Actions = [<PlayOptions.STAY: 1>], HandResults.WIN
Dealer FaceCard = 1, Total = 18, BJ = False, Bust = False, Cards = [1, 3, 4], Player 1, Hand 1, Total = 16, BJ = False, Bust = False, Cards = [9, 2, 5], Actions = [<PlayOptions.DOUBLE: 3>], HandResults.DOUBLELOSS
table = Table()
table.players.append(Player())
for i in range(0, 1):        # Simulates 1,000 rounds of BlackJack
    table.playRound()
    dealer_face_card, dealer_total, dealer_is_blackjack, dealer_is_bust, dealer_cards, players = table.getVerboseResults()
    player_id, hands = players
    hand_id, player_total, player_is_blackjack, player_is_bust, player_cards, player_actions, hand_result = hands

    print(dealer_face_card, dealer_total, dealer_is_blackjack, dealer_is_bust, dealer_cards, player_id, hand_id, player_total, player_is_blackjack, player_is_bust, player_cards, player_actions, hand_result)

    # Fix incorrect player action if player is busted
    if player_is_bust:
        player_actions = player_actions[:-1]

    if str(player_actions[-1])[12:] == 'STAY':
        print(sum(player_cards))
        print(player_cards)

    if str(player_actions[-1])[12:] == 'HIT' or str(player_actions[-1])[12:] == 'DOUBLE':
        print(sum(player_cards[:-1]))
        print(player_cards[:-1])

    # if len(player_cards) == 2:
    #     print(player_cards)
    
    # if len(player_cards) > 2:
    #     print(player_cards[:-1])

    if len(player_actions) > 0:
        print(str(player_actions[-1])[12:])

    print(str(hand_result)[12:])

    # for player_id, hands in players:
    #     for hand_id, player_total, player_is_blackjack, player_is_bust, player_cards, player_actions, hand_result in hands:
            # print(dealer_face_card, dealer_total, dealer_is_blackjack, dealer_is_bust, dealer_cards, player_id, hand_id, player_total, player_is_blackjack, player_is_bust, player_cards, player_actions, hand_result)

    table.reset()
1 21 True False [1, 10] 1 1 15 False False [1, 4] [] HandResults.LOST
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
d:\studia\blackjack-fuzzy\stats.ipynb Cell 4 in <cell line: 3>()
     <a href='vscode-notebook-cell:/d%3A/studia/blackjack-fuzzy/stats.ipynb#W6sZmlsZQ%3D%3D?line=11'>12</a> if player_is_bust:
     <a href='vscode-notebook-cell:/d%3A/studia/blackjack-fuzzy/stats.ipynb#W6sZmlsZQ%3D%3D?line=12'>13</a>     player_actions = player_actions[:-1]
---> <a href='vscode-notebook-cell:/d%3A/studia/blackjack-fuzzy/stats.ipynb#W6sZmlsZQ%3D%3D?line=14'>15</a> if str(player_actions[-1])[12:] == 'STAY':
     <a href='vscode-notebook-cell:/d%3A/studia/blackjack-fuzzy/stats.ipynb#W6sZmlsZQ%3D%3D?line=15'>16</a>     print(sum(player_cards))
     <a href='vscode-notebook-cell:/d%3A/studia/blackjack-fuzzy/stats.ipynb#W6sZmlsZQ%3D%3D?line=16'>17</a>     print(player_cards)

IndexError: list index out of range
[dealer_face_card, dealer_total, dealer_is_blackjack, dealer_is_bust, [dealer_cards], [player_id, [hand_id, player_total, player_is_blackjack, player_is_bust, [player_cards], [player_actions], hand_result]]]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
d:\studia\blackjack-fuzzy\stats.ipynb Cell 7 in <cell line: 1>()
----> <a href='vscode-notebook-cell:/d%3A/studia/blackjack-fuzzy/stats.ipynb#W6sZmlsZQ%3D%3D?line=0'>1</a> [dealer_face_card, dealer_total, dealer_is_blackjack, dealer_is_bust, [dealer_cards], [player_id, [hand_id, player_total, player_is_blackjack, player_is_bust, [player_cards], [player_actions], hand_result]]]

NameError: name 'dealer_face_card' is not defined
table = Table()
table.players.append(Player())
for i in range(0, 1):        # Simulates 1,000 rounds of BlackJack
    table.playRound()
    # print(str(i) + ", " + table.printShortResults())
    print(table.printShortResults())
    table.reset()
7, 2, 1, 13, True, False, False, PlayOptions.HIT, HandResults.WIN, 1.0
# 4 tabele