Not logged in. Login

A3 Hints

Suggested Plan

This is a suggested list of steps that you can follow to get your program working. Remember to test your code frequently, at least after each of these steps.

The hints don't say much about breaking your code into functions. Deciding how to do that is part of the assignment.

  1. Import cards. Create a deck of cards using cards.deck(). Use cards.hand_display() to print out the contents of the deck to check it. Add code to shuffle and test again. (Hint: the random.shuffle function.)
  2. Get the number of players in the game.
  3. Create a loop for the turns (you want to loop three times). In it, call a function that plays a full round (or will eventually, at least).
  4. For each round, create an empty list for the hands. For each player, create their hand (a list of card objects) and append it to the list of hands. For “dealing” cards from the deck, note lists' .pop() method that removes an element from the end of the list and returns it.
  5. Use hand_display to print out the contents of each hand to test. Do the same for the dealer. (Don't worry about hiding the dealer's hole card yet.)
  6. Create a function to count to total number of points in a hand (hint below). Use it in the loop to calculate the total for each initial hand.
  7. Add code to let a player hit or stand. Check for the player busting. Re-test your point totaling function to make sure it handles hands with aces that should count as 1 properly. (See hints below.)
  8. Add code to play the dealer's hand: keep hitting until the total is ≥17.
  9. Add code to determine and print the result for each player (win/loss/push). You will add the betting/money code later: for now, just indicate the result of the hand.
  10. Create your own version of hand_display that displays ** instead of the first card. Use that instead of hand_display when initially displaying the dealer's hand. This will take card of hiding the hole card.
  11. Work back through you program and add code for the player's banks (starting at $1000 each). This should probably be a list of integers: one for each player.
  12. Add code that asks for each player's bet before each turn.
  13. In your win/loss/push code, add logic to update each player's bank.
  14. Make sure you have done the error checking on all of the input, as seen in the sample runs.

Pseudocode

The following are outlines of logic for this assignment.

Blackjack Game

Code corresponding to this logic would likely form the main part of your program. It should be broken up into appropriate functions, but at a high level, your program should do this:

  1. Create and shuffle the deck.
  2. Ask how many players there are and put $1000 in each player's “bank”.
  3. For each round you're going to play:
    1. Ask each player for their bet.
    2. Give two cards to each player and the dealer (display all but the dealer's hole card).
    3. Let each player take their turn:
      1. Ask the player whether they want to hit or stand, until they either stand or bust.
      2. Each card the player is given should be added to their hand, and their new total calculated appropriately.
    4. Play the dealer's hand. (Hit on 16, stand on 17.)
    5. Settle the bets: give/take the bet for each player.
  4. Game over.

Counting a Hand's Value

This is the general idea for determining the number of points in a hand:

  1. For each card in the hand:
    1. Add the card's value to the total.
    2. Count aces as 11, but keep track of the number of aces you've seen.
  2. If the total is over 21, but there were aces in the hand, subtract 10. Repeat as necessary.
Updated Thu June 27 2024, 10:32 by ggbaker.