CPSC 115L: Introduction to Computing Fall2010

Project 2: Blackjack Card game

CPSC 115-01: due Monday, November 22
CPSC 115-02: due Tuesday, November 23

For this project, you are encouraged to work with a partner, although you may work on your own if you prefer. If submitted as a pair, both you and your partner will receive the same grade.

Objectives

The main objectives of this assignment are
  1. to give you practice designing and writing a Python program of moderate complexity, and
  2. to give you practice using object-oriented programming concepts.

Introduction

For this assignment we will write a program that plays the game of blackjack (or 21) (see here for instructions) with a single deck of cards. The user of the program will play against the program, which will play the role of the dealer.

For each hand, the player and the dealer will each be dealt two cards. The player's objective is to beat the dealer. If the player's cards total more than the dealer's without exceeding 21, the player wins. The player plays first. If the player's cards exceed 21, the player busts and loses. The dealer plays after the player is finished. If the dealer busts and the player does not, the player wins. If neither the player nor the dealer bust, the winner is the one who has the highest total without exceeding 21.

In blackjack, the cards' suit have no bearing, just their rank. Cards 2-10 are counted at their face value (their rank). All face cards (Jack, Queen, King) are valued at 10. Aces can count for either 1 or 11. So an Ace and a face card would total 21--that's a blackjack.

In blackjack, the player can choose to hit or stay for each additional card beyond the first two that were dealt. The dealer, however, must take hit whenever the total is below 17 and must stay whenever the total is 17 or above.

Program Specifications

The following are the minimum requirements for this assignment. You should free to include additional features besides these -- e.g., keeping score -- to make your game more enjoyable.

Implementation

Implement your blackjack game in a Python script named blackjack.py. Save snapshots of several runs that demonstrate the following points:

Sample Output

You are free to design your own user interface. But here are a couple of sample runs of the script:

Dealer hand: ( 12 ):  2 of Clubs, Jack of Hearts
Ralph hand: ( 14 ): 9 of Diamonds, 5 of Diamonds
Ralph, type 1 for a hit and 0 to stay > 1
Ralph hand: ( 18 ): 9 of Diamonds, 5 of Diamonds, 4 of Hearts
Ralph, type 1 for a hit and 0 to stay > 0

Ralph total is 18 and Dealer total is 12 .

Dealer's turn.  Type any key to continue > 
Dealer takes a hit
Dealer hand: ( 22 ):  2 of Clubs, Jack of Hearts, 10 of Diamonds
That is a bust

Game over. Ralph has 18 Dealer has 22 .
Dealer busts and pays.


Dealer hand: ( 21 ):  King of Diamonds, Ace of Spades
That's blackjack!
Ralph hand: ( 15 ): 8 of Spades, 7 of Clubs
Ralph, type 1 for a hit and 0 to stay > 1
Ralph hand: ( 20 ): 8 of Spades, 7 of Clubs, 5 of Hearts
Ralph, type 1 for a hit and 0 to stay > 1
Ralph hand: ( 30 ): 8 of Spades, 7 of Clubs, 5 of Hearts, Jack of Diamonds
That is a bust. 

Ralph total is 30 and Dealer total is 21 .
Ralph went bust and loses the hand.

Dealer's turn.  Type any key to continue > 
Dealer stays with 21

Game over. Ralph has 30 Dealer has 21 .
The dealer wins this hand.

Documentation

Your blackjack.py script should contain a comment block at the beginning with your name, date, file name. It should include a brief description of the program, including the problem statement. Each method in the BlackjackHand class should include a docstring that describes its purpose.

What to hand in

Submit the following in paper:

Plagiarism and academic dishonesty

Please remember our course policy on plagiarism and academic dishonesty: You are encouraged to consult with one another when you work on homework assignments, but in the end everyone must do one's own work to hand in. In particular, discussion of homework assignments should be limited to brainstorming and verbally going through strategies, but it must not involve one student sharing written solutions with another student. In the end everyone must write up solutions independently. If you have discussed with classmates or used any outside source, you must clearly indicate so on your solutions and provide all references. Turning in another person's work under your name is plagiarism and qualifies as academic dishonesty. Academic dishonesty is a serious intellectual violation, and the consequences can be severe. For more details, read the Student Handbook 2010–2011, pp. 21–29.


* CPSC 115L home page
Valid HTML 4.01!