Assignment 4: Blackjack

This assignment is to be completed individually. It is not a team project.

You must document (using comments in your code) all resources (beyond our official textbook, Sakai, the class discussion forum, or the class website) that you used to help you complete this assignment.  For example, if you referenced a code example from an online website such as Stackoverflow or github you could acknowledge it as follows:

# Next we print 'Hello, World' to the console.
# Based on help from: https://stackoverflow.com/questions/826948/syntax-error-on-print-with-python-3
print("Hello, world!")
		

You must provide an attribution to any resource you consulted to complete this assignment except for our official textbook, Sakai, class discussion forum, or the class website. Resources that require attribution include — but are not limited to — websites, books, notes from other students, tutors, or help from other people (friends, classmates, etc.). Under no circumstances are you to look at or copy any material related to another student's solution for this assignment.

To repeat, you must attribute any resource you consulted to complete this assignment other than our official textbook, Sakai, class discussion forum, or the class website. Failure to provide attribution is a violation of the honor code.

Overview

Blackjack, also know as twenty-one, is a card game that is played at casinos around the world. In casinos, players bet money on each hand (with, as you would expect in a casino, the odds stacked in favor of the dealer). Point-based variants of the game are also popular, including a large number of Blackjack Phone Apps for Andriod and iPhone. You can read more about the game on Wikipedia.

In this assignment we'll be developing a simplified version of Blackjack. Our version will proceed as follows:

At the start of a new hand, the player will be dealt two cards. The player will then choose, with a goal of obtaining a set of cards that sum as close to 21 as possible without going over, to either "HIT" (get an additional card to add to the player's hand) or "STAY" (stick with the player's existing hand of cards). If the sum of the values of all cards in a player's hand ever goes over 21, they player immediately loses the hand. We call this way of losing "going bust." If the player chooses to STAY before going bust (i.e., with a hand value of 21 or less), it becomes the dealer's turn.

For our game, the dealer is the computer. In the Basic Requirements, you should assign the computerized dealer a score at random within in the range 16-21. We'll look at a more sophisticated approach in the Advanced Requirements below. This computerized dealer score will then be compared to the player's total hand value. If the computer's score is greater than or equal to the player's total hand value (and not over 21), then the player loses the hand. Otherwise, the player wins!

The deck of cards: Traditionally, a deck of playing cards contains 52 cards, with 13 different card values (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King), each of which is found in four distinct suits (Hearts, Diamonds, Spades, and Clubs). In this assignment, we'll ignore suits. For the Basic Requirements, we'll further simplify things to use a deck of cards that has the values from 1 through 10. Moreover, we'll ignore the fact that when playing with real cards, each card can only be used once in a given hand. These assumptions let us simplify the process of dealing a card to the generation of a random number in the range of 1 to 10. For this assignment's Advanced Requirements, we'll add some of this complexity back into the program.


Basic Requirements

Satisfying all basic requirements perfectly, with no points deducted for any reason, would earn a maximum score of 8 out of 10 for this assignment.

You are to implement the basic blackjack game as outlined above. It should provide clear prompts and displays to the user along they way. These prompts should be clear enough to tell the user all they need to play the game, and to determine who wins each hand. The basic flow of the game should be as follows:

Developing the solution for this program would be quite challenging without using functions. To make your job easier, think about how functions can be used to simplify the design. Your solution should have, at a minimum, the following functions:

You may find that additional functions are useful to modularize your design. Adding more functions when appropriate is perfectly fine! However, the four functions identified above are REQUIRED.

The output produced by your program should be nearly identical to the sample output provided below. While the numbers will vary because of the use of random numbers, the prompts and messages printed to the console when using your program should match those in the sample output to receive full credit.


Advanced Requirements

Satisfying both the basic and advanced requirements perfectly, with no points deducted for any reason, will result in a full 10 out of 10 score for this assignment.

Expand on the basic requirements by extending your program as follows.


Sample Output

Examples of the output produced by my solution to this assignment can be found here.

Grading Criteria

This assignment will be graded on a 10 point scale. Your grade for this assignment will be based on a combination of factors including:

Seeking Help

For general questions about Python, please use the class forum on Piazza to seek assistance. For questions that are personal in nature or that would reveal a solution to the assignment, you ask for help by email or during office hours. However, please note that emailed questions will not receive an immediate response. It is likely that it will take 24-48 hours for me to respond.


Submitting Your Solution

Please Note: You must name the main python file for your assignment "assignment<number>_<onyen>.py". For example, for assignment 3 I would name my file assignment3_gotz.py because my onyen is gotz.

Using the wrong name for your file will be cost you points on your assignment grade. Please follow this requirement carefully!

Please submit your assignment via Sakai. You should submit a zip file containing your entire project folder. To create the zip file, follow the submission instructions that have been posted at the bottom of the "Other Information" page on our course website.

The due date for this assignment can be found on the course schedule.