This commit is contained in:
Andrzej Preibisz 2023-01-31 21:05:47 +01:00
commit 43346d0c50

View File

@ -1,4 +1,3 @@
# import itertools
import random import random
from FuzzyControlSystem import getStartDecision, getSplitDecision, getHardHandDecision, getSoftHandDecision from FuzzyControlSystem import getStartDecision, getSplitDecision, getHardHandDecision, getSoftHandDecision
@ -18,7 +17,6 @@ def shoe(n_of_decks: int = 1) -> list:
for _ in range(n_of_decks): for _ in range(n_of_decks):
for _ in suits: for _ in suits:
deck.extend(vals) deck.extend(vals)
# deck.extend(itertools.product(vals, suits))
random.shuffle(deck) random.shuffle(deck)
return deck return deck
@ -101,8 +99,22 @@ def has_blackjack_occured(hand: list):
return True return True
return False return False
def show_game_state(player_hand: list, dealer_hand: list, decision: str='') -> None:
"""Print dealer and player card values and player decision
def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[], bet: int =10) -> str: Args:
player_hand (list): List of cards in player hand
dealer_hand (list): List of cards in dealer hand
decision (str, optional): Player decision. Will not be printed if defaults to ''.
"""
if decision and cards_eval(player_hand)[0] > 21:
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} fail")
elif decision:
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} decision: {decision}")
elif not cards_eval(player_hand)[0] > 21:
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)}")
def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list=[], bet: int=10) -> str:
"""Single blackjack round """Single blackjack round
Args: Args:
@ -121,11 +133,7 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[], bet: int
decision = '' decision = ''
while decision != 'stand' or decision != 'surrender': while decision != 'stand' or decision != 'surrender':
decision = AI(player_hand, face_up) decision = AI(player_hand, face_up)
if cards_eval(player_hand)[0] > 21: show_game_state(player_hand, dealer_hand, decision)
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} fail")
else:
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} decision: {decision}")
if decision == 'hit': if decision == 'hit':
player_hand.append(next(shoe)) player_hand.append(next(shoe))
elif decision == 'double down': elif decision == 'double down':
@ -149,11 +157,8 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[], bet: int
#dealer turn #dealer turn
dealer_value = dealer(dealer_hand, shoe) dealer_value = dealer(dealer_hand, shoe)
player_value = max(cards_eval(player_hand)) player_value = max(cards_eval(player_hand))
# print(dealer_value, player_value) #debug
show_game_state(player_hand, dealer_hand)
if not cards_eval(player_hand)[0] > 21:
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)}")
if player_value == 21 and has_blackjack_occured(player_hand): if player_value == 21 and has_blackjack_occured(player_hand):
return 'player blackjack', bet return 'player blackjack', bet