Betting system fixes

This commit is contained in:
Andrzej Preibisz 2023-01-31 00:42:14 +01:00
parent 298d239b84
commit d7bae269a4

View File

@ -85,6 +85,8 @@ def AI(hand: list, face_up: str) -> str:
# return 'surrender' # return 'surrender'
# else: # else:
evaluation = cards_eval(hand, "player") evaluation = cards_eval(hand, "player")
if max(evaluation) == 11:
return 'double down'
if max(evaluation) <= 17: if max(evaluation) <= 17:
return 'hit' return 'hit'
else: else:
@ -100,7 +102,7 @@ def has_blackjack_occured(hand: list):
return False 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 """Single blackjack round
Args: Args:
@ -123,6 +125,7 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str:
if decision == 'hit': if decision == 'hit':
player_hand.append(next(shoe)) player_hand.append(next(shoe))
elif decision == 'double down': elif decision == 'double down':
bet *= 2
player_hand.append(next(shoe)) player_hand.append(next(shoe))
elif decision == 'split': elif decision == 'split':
#this wont work! #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! #so both wager have the same dealer_value!
##this will work reccursevly ##this will work reccursevly
player_hand = player_hand[0] 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 #old wager continue
elif decision == 'surrender': elif decision == 'surrender':
break 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"Dealer's deck value: {dealer_value}")
print(f"Player's deck value: {player_value}") print(f"Player's deck value: {player_value}")
if player_value == 21 and has_blackjack_occured(player_hand): if player_value == 21 and has_blackjack_occured(player_hand):
return 'player blackjack' return 'player blackjack', bet
elif player_value > 21: elif player_value > 21:
return 'dealer win' return 'dealer win', bet
elif dealer_value > 21: elif dealer_value > 21:
return 'player win' return 'player win', bet
elif player_value > dealer_value: elif player_value > dealer_value:
return 'player win' return 'player win', bet
elif player_value == dealer_value: 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: else:
return 'dealer win' return 'dealer win', bet
#TODO: add adidtional return with wager value like +10$ or -20$ #TODO: add adidtional return with wager value like +10$ or -20$
def game_loop(balance, bet) -> None: def game_loop(balance, bet) -> None:
@ -171,20 +174,20 @@ def game_loop(balance, bet) -> None:
#round start #round start
try: try:
balance -= bet balance -= bet
result = blackjack(shoe_iter) result, game_bet = blackjack(shoe_iter, bet=bet)
except StopIteration: except StopIteration:
break break
if result == 'player win': if result == 'player win':
wins += 1 wins += 1
balance += (2*bet) balance += (2*game_bet)
elif result == 'player blackjack': elif result == 'player blackjack':
wins += 1 wins += 1
player_blackjack += 1 player_blackjack += 1
balance += (2*bet) + (bet/2) balance += (2*game_bet) + (game_bet/2)
elif result == 'dealer win': elif result == 'dealer win':
losses += 1 losses += 1
elif result == 'push': elif result == 'push':
balance += bet balance += game_bet
draws += 1 draws += 1
if result in notable_results: if result in notable_results:
print(result) print(result)
@ -206,7 +209,7 @@ if __name__ == '__main__':
import time import time
#don't use time.time() for counting code execution time! #don't use time.time() for counting code execution time!
start = time.perf_counter() start = time.perf_counter()
for i in range(1000): for i in range(100):
wins, loses, draws, balance, p_blackjack = game_loop(balance, bet) wins, loses, draws, balance, p_blackjack = game_loop(balance, bet)
total_wins += wins total_wins += wins
total_losses += loses total_losses += loses