csa 131
CS A131 Spring 2017 MW 2:20p/6:30p LAB06 100pts Due: Wed 10/11/2017 11:59PM
lab06: Blackjack
1 Blackjack
This is a Blackjack program. The idea is to simulate Blackjack in order to make programming more fun! Here is the overview of the implementation:
• To simulate the shuffled stack of cards, we use a pseudo random number generator that generates a random number in the range of 1 to 13. This represents the cards numbered 1 through 10, plus the jack, queen and king, respectively. If the card number is 1 to 10, it directly represents the value of the card. If the card number is 11 to 13, the card represents the jack, queen, and king, which all have the face value 10.
• Player’s round: The dealer draws an initial card for the player and shows it. The player then can choose to draw additional cards as many times as he wants. If his cards have a combined value of more than 21, he loses immediately. If the player decides not to draw any more cards, it’s the dealer’s turn.
• Dealer Stands on All 17’s: With this rule, if a dealer’s hand total is less than 17, they must continue to “hit.” For example, if you have a hand totaling 12, and the dealer’s hand is 14, even though it beats your hand they cannot “stand.” This may increase the dealer’s odds of going over 21 or “busting.” The dealer must continue to take cards, or “hit” until his total is 17 or greater.
If cards total 17 or greater, the dealer must stop drawing cards, or “stand.” An Ace in a dealer’s hand is always counted as 11, if possible without the dealer going over 21.
(Taken from: http://www.bigmcasino.com/learn-more/do-dealers-and-players-have- to-abide-by-the-same-black-jack-rules/)
1
CS A131 Spring 2017 MW 2:20p/6:30p LAB06 100pts Due: Wed 10/11/2017 11:59PM
An example of user interaction with the program is shown below:
**********************************
** Welcome to CS A131 BlackJack! **
********************************** Your first card is: 7
Do you want another card?
Type y for Yes, n for No: y
Your next card is: 8
Your combined value is: 15
Do you want another card?
Type y for Yes, n for No: y
Your next card is: 9
Your combined value is: 24
Sorry.You lose!
Dealer’s round: The dealer draws his own cards until he reaches one of the following conditions:
• If his combined value reaches more than 21, the dealer loses.
• If his combined value is the same as the player’s value, the dealer wins.
• If his combined value is higher than the player’s value, the dealer wins.
• If his combined value and the player’s combined value is both 21 or equal it’s a tie.
2
CS A131 Spring 2017 MW 2:20p/6:30p LAB06 100pts Due: Wed 10/11/2017 11:59PM
An example code is shown below:
**********************************
** Welcome to CS A131 BlackJack! **
********************************** Your first card is: 7
Do you want another card?
Type y for Yes, n for No: y
Your next card is: 8
Your combined value is: 15
Do you want another card?
Type y for Yes, n for No: n
Dealer draws another card.
Dealer’s card is: 10
Dealer’s value is 10, you have 15
Dealer draws another card.
Dealer’s card is: 4
Dealer’s value is 14, you have 15
Dealer draws another card.
Dealer’s card is: 10
Dealer’s value is 24, you have 15
Dealer loses. You win!
2 HINT
To generate the initial random number, you have to use a random number generator which is provided by importing the random module to your python code. You should use the function randint() to generate a random number of type int for a specific range.
You must implement this homework using what we have learned so far and dividing up your code into functions.
3
CS A131 Spring 2017 MW 2:20p/6:30p LAB06 100pts Due: Wed 10/11/2017 11:59PM
3 BONUS (5 points)
Extend the blackjack program. To make the game more real, for each ace card (1), the player can choose the value to be either 1 or 11 for best interest. The decision can only be made once the card is issued and cannot be changed afterwards.
4 Submission
You should submit your program code as zipped file lab06.tar.gz which includes your source code lab06.py, and a text file lab06.txt briefly explaining how you designed your program, and a typescript lab06.scr which shows that you compile and run your program. Please run it twice so that the script shows that you and the dealer win one time each.
Submit the lab06.tar.gz to canvas by the due date on top of this page.
4