diff --git a/cards.py b/cards.py index 430737b..9f11e7f 100644 --- a/cards.py +++ b/cards.py @@ -85,19 +85,24 @@ def AI(hand: list, face_up: str, losses_in_row: int) -> str: return 'stand' ### temp -def show_game_state(player_hand: list, dealer_hand: list, decision: str='') -> None: +def show_game_state(player_hand: list, dealer_hand: list, splited: bool, decision: str='') -> None: """Print dealer and player card values and player decision Args: player_hand (list): List of cards in player hand dealer_hand (list): List of cards in dealer hand + splited (bool): True if it is subprocess by spliting decision (str, optional): Player decision. Will not be printed if defaults to ''. + """ if decision and cards_eval(player_hand)[0] > 21: + print("split| " if splited else '', end='') print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} fail") elif decision: + print("split| " if splited else '', end='') print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} decision: {decision}") elif not cards_eval(player_hand)[0] > 21: + print("split| " if splited else '', end='') 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, losses_in_row: int=0) -> str: @@ -112,52 +117,58 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list=[], bet: int=1 Returns: str: game result """ + splited = False if dealer_hand == [] and player_hand == []: dealer_hand = [next(shoe), next(shoe)] player_hand = [next(shoe), next(shoe)] + else: + splited = True + + #dealer turn face_up = dealer_hand[0] - + dealer_value = dealer(dealer_hand, shoe) + decision = '' while decision != 'stand' or decision != 'surrender': decision = AI(player_hand, face_up, losses_in_row) - show_game_state(player_hand, dealer_hand, decision) + show_game_state(player_hand, [face_up], splited, decision) if decision == 'hit': player_hand.append(next(shoe)) elif decision == 'double down': bet *= 2 player_hand.append(next(shoe)) elif decision == 'split': - #this wont work! - #it will need to - # dealer_value = dealer(dealer_hand, shoe) - #be calculated before and passed to blackjack() - #so both wager have the same dealer_value! - ##this will work reccursevly - player_hand = player_hand[0] - blackjack(shoe, dealer_hand, player_hand, bet)#new wager start + #this work reccursevly + player_hand = [player_hand[0]] + splited_ai = True #temp + blackjack(shoe, dealer_hand, player_hand.copy(), bet)#new wager start #old wager continue elif decision == 'surrender': break elif decision == 'stand': break - #dealer turn - dealer_value = dealer(dealer_hand, shoe) player_value = max(cards_eval(player_hand)) - show_game_state(player_hand, dealer_hand) - + show_game_state(player_hand, dealer_hand, splited) + print("split| " if splited else '', end='') if player_value == 21 and 1 in player_hand: - return 'player blackjack', bet + print('player blackjack', "="*50, sep='\n') + return 'player blackjack', bet elif player_value > 21: + print('dealer win', "="*50, sep='\n') return 'dealer win', bet elif dealer_value > 21: + print('player win', "="*50, sep='\n') return 'player win', bet elif player_value > dealer_value: + print('player win', "="*50, sep='\n') return 'player win', bet elif player_value == dealer_value: + print('push', "="*50, sep='\n') return 'push', bet #keep money, no win no lose 0$ else: + print('dealer win', "="*50, sep='\n') return 'dealer win', bet def game_loop(balance, bet) -> None: @@ -191,11 +202,6 @@ def game_loop(balance, bet) -> None: elif result == 'push': balance += game_bet draws += 1 - losses_in_row = 0 - - if result in notable_results: - print(result) - print("="*50) return wins, losses, draws, balance #player_blackjack def calculate_bet(wins, losses, hand):