diff --git a/cards.py b/cards.py index 7ab0021..2645f7b 100644 --- a/cards.py +++ b/cards.py @@ -62,7 +62,7 @@ def dealer(hand: list, shoe: iter) -> int: int: dealer hand value """ evaluation = cards_eval(hand) - while max(evaluation) < 17: #solve soft 17 + while max(evaluation) <= 17: #solve soft 17 hand.append(next(shoe)) evaluation = cards_eval(hand) return max(evaluation) @@ -84,7 +84,7 @@ def AI(hand: list, face_up: str) -> str: # return 'surrender' # else: evaluation = cards_eval(hand) - if max(evaluation) < 18: + if max(evaluation) <= 17: return 'hit' else: return 'stand' @@ -114,8 +114,12 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str: elif decision == 'double down': player_hand.append(next(shoe)) elif decision == 'split': - #test if works - #this will work reccursevly + #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)#new wager start #old wager continue @@ -130,7 +134,9 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str: # print(dealer_value, player_value) #debug #round end - if dealer_value > 21: + if player_value > 21: + return 'dealer win' + elif dealer_value > 21: return 'player win' elif player_value > dealer_value: return 'player win' @@ -141,7 +147,7 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[]) -> str: #TODO: add adidtional return with wager value like +10$ or -20$ def game_loop() -> None: - stats = 0 + stats = [0, 0] #wins, loses shoe_iter = iter(shoe(10)) while True: #round start @@ -150,23 +156,29 @@ def game_loop() -> None: except StopIteration: break if result == 'player win': - stats += 1 + stats[0] += 1 elif result == 'dealer win': - stats -= 1 - elif result == 'push': - stats += 0 + stats[1] += 1 + # elif result == 'push': + # stats[0] += 0 + # stats[1] += 1 return stats -if __name__ == '__main__': - print(game_loop()) - # if __name__ == '__main__': -# import time -# #don't use time.time() for counting code execution time! -# start = time.perf_counter() -# for i in range(1000): -# game_loop() +# print(game_loop()) + +if __name__ == '__main__': + statistics = [0, 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() + statistics[0] += wins + statistics[1] += loses -# end = time.perf_counter() -# result = end - start -# print(result) \ No newline at end of file + end = time.perf_counter() + result = end - start + print(result) + print(statistics) + print(statistics[0]/sum(statistics)) \ No newline at end of file