Link Search Menu Expand Document
  1. Background
    1. Goals of this assignment
    2. Collaboration Policy
    3. Style & Design Policy
  2. The Assignment
    1. Playing the Game
    2. Scoring the Game
    3. Detailed Requirements
  3. Submission
  4. Summary

Background

It’s time to take all of the skills we’ve learned so far and apply them to a single, unified project. Unlike in previous assignments where you were responsible for completing a handful of separate tasks, this assignment will allow you to practice your skills in class design, iteration, and data structures in order to put together a complete implementation of a detailed game.

Goals of this assignment

  • Interpret instructions and design a system of classes that can implement the required behavior
  • Use data structures (arrays, 2D arrays, array lists) to represent complex program states
  • Create a user interface so that the software is usable for anyone with a computer.
  • Learning how to test a program thoroughly

Collaboration Policy

You may collaborate with one other student on this assignment. The level of collaboration is limited to discussing design, making CRC cards, and talking about implementation strategies. You are not permitted to write code with another student or view another student’s code. Violations of this policy will be detected using highly effective software and treated as a case of plagiarism. These cases will automatically be referred to the Office of Student Conduct for arbitration. If you have questions about collaboration levels that are permitted, you should feel free to ask the course staff.

Additionally, please include a README.txt file in your submission that lists the partner you worked with, if any, as well as the extent of your collaboration together.

Style & Design Policy

This is the first assignment for which you will receive a style grade. Good style includes:

  • Consistent indentation in code, with lines of code indented to the correct level representing the block they belong to.
  • Identifiers for methods and variables that follow the correct camel case convention and are appropriately descriptive.
  • Correct spacing between operators, parentheses, and brackets.

Fortunately, most good style practices can be automatically enforced using Eclipse. From Preferences, choose Java -> Editor -> Save Actions and check the Format source code box under the Perform the selected actions on save option.

Additionally, you’ll need to make good design choices for this assignment. We won’t be too strict, but some things to look out for are:

  • Declaring variables only in the scopes where they’re needed and avoiding the creation of unnecessary fields
  • Fields should be set to private with access moderated by getter and setter methods
  • Classes should have clear responsibilities and no one class should represent multiple entities of a system.

Style and design scoring will consist of 10% of the assignment grade.

The Assignment

You are going to implement a card game called Blackjack Solitaire. You should follow this link to play a couple rounds of the game before proceeding. Your ultimate goal is to build a program that allows the user to play one round of the game, enforcing the rules along the way. Your program will then score their play.

Blackjack Solitaire is a one-player game with scoring rules inspired by the casino game of Blackjack, where players attempt to build a hand with a value as close to 21 as possible without exceeding 21.

Playing the Game

In this game, playing cards are played onto a grid with four rows and five columns. Cards are drawn one at a time from a standard deck of 52, and the player must choose a location for each card before proceeding. Once a card has been placed on the grid, the card cannot be moved. There are four special discard spots that allow cards placed there to be ignored–they will not contribute to the final scoring. This leaves 16 spaces for cards to be placed where they will be counted in the final score.

Once all 16 scored spaces in the grid have been filled with a card, a score is calculated. Each of the four rows and five columns in the grid count as an individual hand and will be scored as such.

Scoring the Game

Each card has a value. Cards with numbers on them (2s through 10s) have value equal to the number on the card. “Face” cards (Kings, Queens, Jacks) are valued at 10 each. Aces can be “high”, counting as value 11, or “low”, counting as value 1, depending on which value would give the player a higher score without exceeding 21. Hands are calculated by summing the values of the cards in them. Each hand, then, has a cumulative value. The points that the player scores per hand are calculated as follows:

Hand Type Description of Hand Point Value
Blackjack A hand of 2 cards that sum to 21 10
21 3, 4, or 5 cards that sum to 21 7
20 Hand of any size that sums to 20 5
19 Hand of any size that sums to 19 4
18 Hand of any size that sums to 18 3
17 Hand of any size that sums to 17 2
<=16 Hand of any size that sums to 16 or less 1
BUST Hand of any size that sums to 22 or more 0

Detailed Requirements

  • Your program must allow the user to play one game and then exit. Specifically, the user will play until the 16 scoring spots on the gride are filled and at most 4 of the discard spots are filled. Then the score is calculated, displayed, and the program exits.
  • The game begins by shuffling a standard deck of 52 cards and then dealing a first card.
  • The player places one card at a time onto the grid into any empty space. The grid looks like the following:
     1	2	3	4	5
     6	7	8	9	10
     	11	12	13	
     	14	15	16
    

    The numbers representing the spaces should be surrounded by whitespace (spaces and/or tabs). The remaining spaces (17, 18, 19, 20) are discard slots and therefore do not count as part of any hand.

  • You will repeatedly draw a card, show the user the state of the game, prompt the user to place the card, place the card on the grid, and then repeat until the game is over.
  • To display the state of the game, you should use the convention that a card can be represented as a String consisting of its rank and its suit.
    • The King of Hearts would be "KH" and the Three of Diamonds would be "3D".
    • When displaying the current grid state to the player, empty spaces should be represented by their number and filled spaces should be represented.
    • A game in progress could look like this, matching the formatting exactly:
1	KH	3	4	5
2D	7	8	9	AS
	11	12	13	
	14	7C	16
  • The user will specify which place they’d like to put the card by entering the number of the corresponding spot.
    • If the user tries to play a card by entering the number of a spot that’s already filled, you should print an error message and repeat the prompt.
    • If the user tries to play a card to a spot that doesn’t exist (a number that’s not in the acceptable range or some other bad input), print an error message and repeat the prompt.
  • When the game is over, display a final message that includes the score of your table as well as a general notification that the game is over.
    • "Game over! You scored 30 points." would be an acceptable template to follow.
  • You must design at least the following three classes:
    • Card.java that represents a single card.
    • Deck.java that represents a deck of cards.
    • BlackjackSolitaire.java that represents the entire game.
    • BlackjackSolitaireRunner.java that actually runs the game. We provide this to you and it should be used exactly as provided.
         public class BlackjackSolitaireRunner {
             public static void main(String[] args) {
                 BlackjackSolitaire bjs = new BlackjackSolitaire();
                 bjs.play();
             }
         }
      
    • You can use the CRC technique to find and design other classes as well.

Submission

Submit at least the following five files: README.txt, Card.java, Deck.java, BlackjackSolitaire.java, and BlackjackSolitaireRunner.java. You are likely to have other files as well–if you design other classes, be sure to submit them as well.

Ensure that your files do not have a package header! Specifically, the first lines of your file should not read package xyz or similar.

Please find these files locally on your file system. By default, they will be found in a folder called eclipse_workspace, often in your user’s directory. You should select each of the files and upload them as files (not as a directory, and preferably not as a .zip either). If you need help, please reach out on Piazza or in Office Hours.

Summary

The entire project can be summarized using the following steps:

  • Display the initial state of the game.
  • Shuffle a deck.
  • Deal a card.
  • Allow the user to make a move by prompting them to enter the number of the position in which they want the card to be placed.
    • Take that information from the user and move the card to the appropriate position
    • If the user’s choice is invalid, give an error message and tell them to try again.
  • Display the current state of the game after each turn.
  • Repeat the above three bullet points until the game is complete.
  • When all 16 scored places are filled, print a message telling the user that you are going to score the hands and then do so, passing the state of the table to a scoring function.
  • The final message to display should include be the score of your table as well as a general notification that the game is over.
    • "Game over! You scored 30 points." would be an acceptable template to follow.