Mastering Objectoriented Python
上QQ阅读APP看书,第一时间看更新

Playing the game

The game of Blackjack can vary from casino to casino, but the outline is similar. The mechanics of play work as follows:

  • First, the player and dealer each get two cards. The player, of course, knows the value of both of their cards. They're dealt face up in a casino.
  • One of the dealer's cards is face up and the other is face down. The player therefore knows a little bit about the dealer's hand, but not everything.
  • If the dealer has an ace showing, there's a 4:13 chance that the hidden card is worth 10 and the dealer has 21. The player can elect to make an additional insurance bet.
  • Next, the player can elect to either receive cards or stop receiving cards. These two most common choices are called hit or stand.
  • There are some additional choices too. If the player's cards match, the hand can be split. This is an additional bet, and the two hands are played separately.
  • Finally, the players can double their bet before taking one last card. This is called doubling down. If the player's cards total 10 or 11, this is a common bet to make.

The final evaluation of the hand works as follows:

  • If the player went over 21, the hand is a bust, the player loses, and the dealer's facedown card is irrelevant.
  • If the player's total is 21 or under, then the dealer takes cards according to a simple, fixed rule. The dealer must hit a hand that totals less than 18. The dealer must stand on a hand that totals 18 or more. There are some small variations here that we can ignore for the moment.
  • If the dealer goes bust, the player wins.
  • If both the dealer and player are 21 or under, the hands are compared to see if the player has won or lost.

The amounts of the final payoffs aren't too relevant for now. For a more accurate simulation of various play and betting strategies, the payoffs will matter quite a bit.