Betting system fixes
This commit is contained in:
parent
298d239b84
commit
d7bae269a4
29
cards.py
29
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
|
||||
|
Loading…
Reference in New Issue
Block a user