add card value prints
This commit is contained in:
parent
8a4c81f988
commit
dad56d9e7a
32
cards.py
32
cards.py
@ -90,7 +90,7 @@ def AI(hand: list, face_up: str) -> str:
|
||||
return 'stand'
|
||||
### temp
|
||||
|
||||
def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str:
|
||||
def blackjack(shoe: iter, money:int, dealer_hand: list=[], player_hand: list =[]) -> str:
|
||||
"""Single blackjack round
|
||||
|
||||
Args:
|
||||
@ -109,6 +109,10 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str:
|
||||
decision = ''
|
||||
while decision != 'stand' or decision != 'surrender':
|
||||
decision = AI(player_hand, face_up)
|
||||
if cards_eval(player_hand)[0] > 21:\
|
||||
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':
|
||||
player_hand.append(next(shoe))
|
||||
elif decision == 'double down':
|
||||
@ -135,24 +139,25 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str:
|
||||
|
||||
#round end
|
||||
if player_value > 21:
|
||||
return 'dealer win'
|
||||
return 'dealer win', money
|
||||
elif dealer_value > 21:
|
||||
return 'player win'
|
||||
return 'player win', money
|
||||
elif player_value > dealer_value:
|
||||
return 'player win'
|
||||
return 'player win', money
|
||||
elif player_value == dealer_value:
|
||||
return 'push' #keep money, no win no lose 0$
|
||||
return 'push', money #keep money, no win no lose 0$
|
||||
else:
|
||||
return 'dealer win'
|
||||
return 'dealer win', money
|
||||
#TODO: add adidtional return with wager value like +10$ or -20$
|
||||
|
||||
def game_loop() -> None:
|
||||
stats = [0, 0] #wins, loses
|
||||
money = 500 #100$ start money
|
||||
shoe_iter = iter(shoe(10))
|
||||
while True:
|
||||
#round start
|
||||
try:
|
||||
result = blackjack(shoe_iter)
|
||||
result, money = blackjack(shoe_iter, money)
|
||||
except StopIteration:
|
||||
break
|
||||
if result == 'player win':
|
||||
@ -162,6 +167,8 @@ def game_loop() -> None:
|
||||
# elif result == 'push':
|
||||
# stats[0] += 0
|
||||
# stats[1] += 1
|
||||
print("---------------------")
|
||||
stats.append(money)
|
||||
return stats
|
||||
|
||||
# if __name__ == '__main__':
|
||||
@ -169,16 +176,19 @@ def game_loop() -> None:
|
||||
|
||||
if __name__ == '__main__':
|
||||
statistics = [0, 0]
|
||||
money_sum = 0
|
||||
import time
|
||||
#don't use time.time() for counting code execution time!
|
||||
start = time.perf_counter()
|
||||
for i in range(1000):
|
||||
wins, loses = game_loop()
|
||||
wins, loses, money = game_loop()
|
||||
statistics[0] += wins
|
||||
statistics[1] += loses
|
||||
money_sum += money
|
||||
|
||||
end = time.perf_counter()
|
||||
result = end - start
|
||||
print(result)
|
||||
print(statistics)
|
||||
print(statistics[0]/sum(statistics))
|
||||
print(f'time: {round(result, 3)} seconds')
|
||||
print(f'wins: {statistics[0]} | losses: {statistics[1]}')
|
||||
print(f'win {round((statistics[0]/sum(statistics)*100), 2)}%')
|
||||
print(f'moeny return {round((money_sum/500)*100, 2)}%')
|
Loading…
Reference in New Issue
Block a user