From d7bae269a469dca7dd2a94bb6f9835c1e9f6a945 Mon Sep 17 00:00:00 2001 From: Andrzej Preibisz Date: Tue, 31 Jan 2023 00:42:14 +0100 Subject: [PATCH] Betting system fixes --- cards.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/cards.py b/cards.py index 1166696..4cc9bbf 100644 --- a/cards.py +++ b/cards.py @@ -85,6 +85,8 @@ def AI(hand: list, face_up: str) -> str: # return 'surrender' # else: evaluation = cards_eval(hand, "player") + if max(evaluation) == 11: + return 'double down' if max(evaluation) <= 17: return 'hit' else: @@ -100,7 +102,7 @@ def has_blackjack_occured(hand: list): return False -def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str: +def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[], bet: int =10) -> str: """Single blackjack round Args: @@ -123,6 +125,7 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str: 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! @@ -132,7 +135,7 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str: #so both wager have the same dealer_value! ##this will work reccursevly player_hand = player_hand[0] - blackjack(shoe, dealer_hand, player_hand)#new wager start + blackjack(shoe, dealer_hand, player_hand, bet)#new wager start #old wager continue elif decision == 'surrender': break @@ -148,17 +151,17 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str: print(f"Dealer's deck value: {dealer_value}") print(f"Player's deck value: {player_value}") if player_value == 21 and has_blackjack_occured(player_hand): - return 'player blackjack' + return 'player blackjack', bet elif player_value > 21: - return 'dealer win' + return 'dealer win', bet elif dealer_value > 21: - return 'player win' + return 'player win', bet elif player_value > dealer_value: - return 'player win' + return 'player win', bet elif player_value == dealer_value: - return 'push' #keep money, no win no lose 0$ + return 'push', bet #keep money, no win no lose 0$ else: - return 'dealer win' + return 'dealer win', bet #TODO: add adidtional return with wager value like +10$ or -20$ def game_loop(balance, bet) -> None: @@ -171,20 +174,20 @@ def game_loop(balance, bet) -> None: #round start try: balance -= bet - result = blackjack(shoe_iter) + result, game_bet = blackjack(shoe_iter, bet=bet) except StopIteration: break if result == 'player win': wins += 1 - balance += (2*bet) + balance += (2*game_bet) elif result == 'player blackjack': wins += 1 player_blackjack += 1 - balance += (2*bet) + (bet/2) + balance += (2*game_bet) + (game_bet/2) elif result == 'dealer win': losses += 1 elif result == 'push': - balance += bet + balance += game_bet draws += 1 if result in notable_results: print(result) @@ -206,7 +209,7 @@ if __name__ == '__main__': import time #don't use time.time() for counting code execution time! start = time.perf_counter() - for i in range(1000): + for i in range(100): wins, loses, draws, balance, p_blackjack = game_loop(balance, bet) total_wins += wins total_losses += loses