Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created August 6, 2021 15:33
Show Gist options
  • Select an option

  • Save kyanny/e7967fa8f58601a71daf248e262fb1e5 to your computer and use it in GitHub Desktop.

Select an option

Save kyanny/e7967fa8f58601a71daf248e262fb1e5 to your computer and use it in GitHub Desktop.
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%
@necro-manc3r

Copy link
Copy Markdown

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 player_total <10:
    return True    
if player_total < 14:
    return True

return False

q7.simulate(n_games=50000)

win rate avg 41.7% ~ 41.8%

win rate highest 42.0%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment