Assignment #3

Twenty-One - Procedural design, Simple Lists, and Card Tricks

Due: Monday, September 30th @ 11:55pm

Submission Guidelines:


For this assignment you will create a one-player variation of the game BlackJack.

The Game

The game will be divided into five rounds. The goal of each round is to accumulate a hand of cards that gets as close to 21 without going over. At the beginng of the game you will start with a score of 100 points. After each round, the difference between your hand and 21 will be subtracted from your total score. The object of the entire game is to get the highest score possible at the end of 5 rounds.


Playing a Round

The rules of each round work similarly to playing a hand of BlackJack. You will be dealt a hand of two cards, each worth a given value (see Counting a Hand below). At this point you are given the choice to either "Stand", that is keep your hand where it is, or "Hit", and be dealt another card. You may continue to hit as many times as you like, until you wish to stand or until you go over 21. If your hand goes over 21 then your hand is "Bust", and the round ends.


Scoring a Round

At the beginning of the game you will start with 100 points. After each round the difference between the total value of your hand and the perfect score of 21 will be subtracted from your total. If you bust, however, a value of 21 will be subtracted from your total.


Counting a Hand

The deck of cards will be simulated with integers of values from 1 to 13, where 1 represents the Ace (A), 11 the Jack(J), 12 the Queen(Q), and 13 the King(K). Use the following rules when determining the value of a hand of cards.

Below are some example hands and their sums:


Scoring the Game

At the start of the game your total score will begin at 100. Each round your score will be decreased by 0 or more points. At the end of the game your final score will be a number in the range [-5,100], and it will be ranked according to the following categories:


User Interaction

User interaction in this game will be entirely text-based. According to the following rules.

See below for example interactions.


Program Design Requirements

Your code must be structured in a procedural style. That is, your code should have a main() function that acts as the starting point of your program. The main function should be responsible for starting, repeating, and ending your game. In addition, your program should have (at minimum) the following other functions:

Please note, your implementation should use the signatures (function names and expected parameters and return types) shown here. You are encouraged to define any additional helper functions you may need.

You should not make use of any global variables in your solution.


Bonus

As a bonus challenge, design your game so that it simulates an authentic deck of 52 cards for each round. This means that at the start of each round you will build a list of 52 cards containing exactly 4 of each value (1-13). Each time the player is dealt a new card that card should be removed from the deck (so the player will never get a hand of 5 Aces, for example). Note: if you attempt the bonus you will likely need to modify the signature for the required dealCard() function mentioned above so that it accepts the deck of cards as argument. Please mention in the comments of that function that your solution attemped this bonus.


Examples

> python twentyone.py

Round 1
Score: 100
Your hand: Q K  (20)
Would you like to 'hit' or 'stand': stand


Round 2
Score: 99
Your hand: 7 7  (14)
Would you like to 'hit' or 'stand': hit
Your hand: 7 7 7  (21)
Would you like to 'hit' or 'stand': stand


Round 3
Score: 99
Your hand: 3 A  (14)
Would you like to 'hit' or 'stand': hit
Your hand: 3 A 3  (17)
Would you like to 'hit' or 'stand': stand


Round 4
Score: 95
Your hand: 2 8  (10)
Would you like to 'hit' or 'stand': hit
Your hand: 2 8 J  (20)
Would you like to 'hit' or 'stand': stand


Round 5
Score: 94
Your hand: 2 K  (12)
Would you like to 'hit' or 'stand': hit
Your hand: 2 K K  (22)
Bust!

Final score: 73,  Your rank: Jack
Would you like to play again? (y/n) n
Goodbye!
> python twentyone.py

Round 1
Score: 100
Your hand: K 10  (20)
Would you like to 'hit' or 'stand': hit
Your hand: K 10 K  (30)
Bust!


Round 2
Score: 79
Your hand: 7 9  (16)
Would you like to 'hit' or 'stand': hit
Your hand: 7 9 2  (18)
Would you like to 'hit' or 'stand': hit
Your hand: 7 9 2 10  (28)
Bust!


Round 3
Score: 58
Your hand: 10 A  (21)
Would you like to 'hit' or 'stand': hit
Your hand: 10 A 7  (18)
Would you like to 'hit' or 'stand': hit
Your hand: 10 A 7 5  (23)
Bust!


Round 4
Score: 37
Your hand: 10 9  (19)
Would you like to 'hit' or 'stand': hit
Your hand: 10 9 J  (29)
Bust!


Round 5
Score: 16
Your hand: 4 A  (15)
Would you like to 'hit' or 'stand': hit
Your hand: 4 A Q  (15)
Would you like to 'hit' or 'stand': hit
Your hand: 4 A Q 4  (19)
Would you like to 'hit' or 'stand': hit
Your hand: 4 A Q 4 Q  (29)
Bust!

Final score: -5,  Your rank: Noob
Would you like to play again? (y/n) y

		
Round 1
Score: 100
Your hand: 6 10  (16)
Would you like to 'hit' or 'stand': yes
Would you like to 'hit' or 'stand': 16 is good, thanks.
Would you like to 'hit' or 'stand': true
Would you like to 'hit' or 'stand': STAND
Would you like to 'hit' or 'stand': 
Would you like to 'hit' or 'stand': 16 
Would you like to 'hit' or 'stand': stand


Round 2
Score: 95
Your hand: A 4  (15)
Would you like to 'hit' or 'stand': stand


Round 3
Score: 89
Your hand: 7 Q  (17)
Would you like to 'hit' or 'stand': stand


Round 4
Score: 85
Your hand: 5 A  (16)
Would you like to 'hit' or 'stand': stand


Round 5
Score: 80
Your hand: 3 3  (6)
Would you like to 'hit' or 'stand': hit
Your hand: 3 3 2  (8)
Would you like to 'hit' or 'stand': hit
Your hand: 3 3 2 9  (17)
Would you like to 'hit' or 'stand': stand

Final score: 76,  Your rank: Queen
Would you like to play again? (y/n) maybe
I'm sorry maybe is not a valid option. Please enter 'y' or 'n'.
Would you like to play again? (y/n) qwert
I'm sorry qwert is not a valid option. Please enter 'y' or 'n'.
Would you like to play again? (y/n) no
I'm sorry no is not a valid option. Please enter 'y' or 'n'.
Would you like to play again? (y/n) N
I'm sorry N is not a valid option. Please enter 'y' or 'n'.
Would you like to play again? (y/n) n
Goodbye!

Grading Scheme