Back to 111 Main Page

Mobius strip

Assignment 18

Task

Write a simple Blackjack game.

Concepts: Review of class-related concepts

Steps

The point of this assignment is to reuse your PlayingCard and Deck classes from A17 in a different context.

Your Blackjack game must follow the standard rules (such as described at Wikipedia or Pagat), but without betting or any of the advanced options that accompany betting. Instead, the game should simply track how many hands the player has won, tied, and lost.

Cards have a value equal to their face value except for face cards (which are worth 10 points each) and Aces (which are worth either 11 or 1). The value of an Ace should be 11, unless this would cause the hand value to exceed 21; in that case, the Ace instead counts as 1. Note that there should be no artificial limit on the number of cards or Aces that can be in a hand (as long as the total hand value is still <= 21.)

For each hand/round, your game should do the following:

  • Deal two cards (one of which is "face down") to the computer dealer and two to the human user. (The player's face down card should be revealed at the end of the game, or at the beginning of the dealer's turn, whichever comes first.)
  • If both dealer and player have hands totaling 21 at this point, the game is a tie ("push"). If only one or the other has 21, then that player wins the game. Otherwise, the game continues with the player's move.
  • The player may continue to choose to hit (draw another card) or stand (stop drawing) as long as their hand totals 21 or less. The game should show the player's hand total during this process. If the player exceeds 21, they lose the game.
  • If the player stands with 21 or fewer points, the dealer then plays. The dealer must always hit as long as its hand value is 16 or less. If 17 or above, the dealer must stand. If the dealer's hand exceeds 21 at this point, the player wins. (You may have the dealer hit a soft 17, if you wish.)
  • At this point, both players have stood. The player with the higher-scoring hand wins, or the game may be a tie.
  • Display how many games have been won/tied/lost so far and ask the player if they'd like to play another hand.

I'm going to grade this assignment manually, so input and output formatting is up to you. Just make sure that you explain to the user what the game controls are.

Design Considerations

You may create additional classes if you want (such as for a Hand), but it's not necessary. (You could just use an ArrayList directly.) I strongly recommend you write some additional methods to help break the problem down. For example, you might want a method that totals a hand and another that runs though a single hand/round. Your deck must not run out of cards--create a new deck either when you run out of cards or at the beginning of each game (depending on whether you want to be able to practice your card-counting skills).

What to Submit

Upload your UsernameA18.java file to Tamarin. Remember that the file must include all the classes needed for your program to run.

Grading [9 points]

1 - Compiles + Coding Standards
Your program compiles successfully (no errors). Your code follows Java coding standards.
0.5 - Helper classes
Your game uses a PlayingCard and Deck.
0.5 - Instructions
Your game explains the controls to the user (that is, how to hit, how to stand, and how to play again).
2 - Cards are displayed.
You display all the cards that make up each hand (1.5). The dealer's face down card should not be shown until after the player cannot hit again, but must be shown by the end of the game (0.5).
2 - Hands are totaled.
The game should display the correct total value of each hand, handling Aces correctly. (It should tell the player the value of her hand each time she is asked to hit or stand. It should reveal the dealer's total at the end of the game.)
1 - Follows the game rules
Dealer hits on 16 or less, and stands on 17 or higher; doesn't let a player hit after exceeding 21 points, etc.
1.5 - Determines win, lose, or tie
Correctly determines who won each game (1.0) and keeps running statistics (0.5) that are displayed each time the player is asked if they want to play again.
0.5 - No crashes
Your program does not crash from invalid input or from running out of cards.

FAQs



~ztomasze Index : TA Details: ICS111: A18
http://www2.hawaii.edu/~ztomasze
Last Edited: 01 Apr 2009
©2009 by Z. Tomaszewski.