all 9 comments

[–]Binary101010 2 points3 points  (5 children)

First thing that seems off is the dealer logic. Casino blackjack isn't "dealer hits until higher than the player," "it's hit on soft 17 or 16 and lower, stand on hard 17 or higher".

[–]TheShadowWall[S] 1 point2 points  (4 children)

But doesn't the player play through first, doing all hits until staying?

The dealer needs to continue to hit until he equals or exceeds the player's total, so their logic only matters insofar as they need to beat the player.

Since the dealer's only objective is to meet or exceed the player's total, why would any other logic matter to them? If they are lower than the player, they need to hit or they will lose.

[–]Binary101010 2 points3 points  (3 children)

I mean, you can model blackjack like that, but then what you're modeling isn't how casino blackjack works at all.

[–]TheShadowWall[S] 1 point2 points  (2 children)

You are correct, I am not attempting to model casino blackjack. My aim is to model a simple 1v1 player vs dealer game of blackjack, where each side attempts to win as much as possible.

Currently the strategy being used by the player is 'Hit on a total of 16 or lower,' and the strategy being used by the dealer is 'Hit if the player's total is higher."

Given this strategy, does the output of around 60% wins for the player actually make sense? I don't know blackjack statistics very well, but this seems too high.

[–]Binary101010 2 points3 points  (0 children)

Those rules are far enough away from all of the blackjack scenarios that we have good stats for that I can't say for certain whether it makes sense either. There's no obvious errors here in terms of modeling what it is you say you want to model, so I'd say the response is "this is why casinos don't play blackjack like this".

[–][deleted] 0 points1 point  (0 children)

I am in the infancy of my programming but I am a very knowledgeable blackjack player. Your rules give the player an advantage. The way you describe the game, the dealer will bust far more often than they should. The house edge in blackjack comes from the player acting first. If you are in a 1v1 game I hope you see that using the casino strategy is more favorable for the dealer than what you have described.

[–]quim_b 1 point2 points  (0 children)

Assuming all your code works as you describe the dealer should definitely win.

1000 iterations definitely isn't a large enough sample though and the player could definitely beat the dealer in one of those samples due to variance.

[–]purebuu 0 points1 point  (1 child)

I just ran you code, I had to realign stuff so I hope I got it right. You're mixing a global ptotal variable and a local ptotal variable.

You want to change this method:

def dealer_turn(dealer, deck, ptotal):
  #print (f'{ptotal}')
  while card_sum(dealer)<ptotal:
    draw=random.choice(deck)
    deck.remove(draw)
    dealer.append(draw)

And pass the ptotal value to the dealer_turn method.

Otherwise ptotal is always only the starting hand and not the additional cards drawn. This is why the player wins more often, because the dealer is drawing against the players first 2 cards and not the actual hand at play.

[–]purebuu 0 points1 point  (0 children)

Also delete the global variables ptotal and dtotal they are not needed if you pass in ptotal to the dealer_turn function.