Created
August 6, 2021 15:33
-
-
Save kyanny/e7967fa8f58601a71daf248e262fb1e5 to your computer and use it in GitHub Desktop.
Blackjack decision-making strategy ref https://www.kaggle.com/kyanny/exercise-booleans-and-conditionals/edit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def should_hit(dealer_total, player_total, player_low_aces, player_high_aces): | |
"""Return True if the player should hit (request another card) given the current game | |
state, or False if the player should stay. | |
When calculating a hand's total value, we count aces as "high" (with value 11) if doing so | |
doesn't bring the total above 21, otherwise we count them as low (with value 1). | |
For example, if the player's hand is {A, A, A, 7}, we will count it as 11 + 1 + 1 + 7, | |
and therefore set player_total=20, player_low_aces=2, player_high_aces=1. | |
""" | |
if dealer_total >= player_total or player_total <= 12: | |
if player_high_aces == 0: | |
if player_low_aces <= 0: | |
if player_total - ((player_low_aces * 1) + (player_high_aces * 11)) > 6: | |
return True | |
return False | |
q7.simulate(n_games=50000) | |
# win rate avg 41.2% ~ 41.3% | |
# win rate highest 41.7% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment