CIS501 Assignment 1


10 points; due Friday January 30

You will implement a C# console application that lets a human "guest" play multiple rounds of casino-style Blackjack against a computerized "house" player. (In the usual game, there are multiple "guest" players who all play against the "house" player at the same time. In this assignment, there is only one "guest" --- the human. The rules below are for the game when one or more guest players compete against the one house player.)

Game rules

Here's how one round of Blackjack works:
  1. Deal two cards to all players: The card dealer gives two cards to each player (that is, two cards to each guest player and then two cards to the house player.)

    Important: for all players, guest and house players, the value of the first of the two cards from each player's hand is revealed to all. Of course, the human sees the values of both cards in her own hand.

  2. Check for Blackjack: If the house player has two cards that total to 21 (this is called a "Blackjack"), the round ends here: Skip Step 3 and go to Step 4, ``Determine the winners.''

    If the house player does not have Blackjack, then the dealer looks at the scores of each of the guest players. Every guest player who has Blackjack wins the round. (When there are multiple guest players, there can be multiple winners of a round.) Important: Every guest player who has won the round does not participate in Steps 3 and 4 that follow.

  3. Receive more cards: At the start of this step, the house player does not have 21 and there is at least one guest player who does not have 21. These players can receive more cards, if they wish:
    For each player, starting with the guest players and finishing with the house player, the dealer repeatedly

    (i) asks if an additional card is desired. If "yes", then (ii) the dealer gives one more card. The repetition stops when the player says "no" or if the score of the player's hand equals or exceeds 21.

    Important: the human guest player decides whether to accept more cards. The house player in your implementation is computerized and will accept another card as long as the house player's hand has a score that is less than 17.

  4. Determine the winners: The outcomes of all the remaining guest players are determined by comparing their scores to the score of the house player. There can be multiple winners of a round and even no winners of a round:

The game keeps going for multiple rounds --- indeed, forever --- and it displays at the end of each round (i) the number of rounds played so far, and (ii) for each guest player (in this assignment, the human) the number of the player's wins. (We won't keep track of "losses" or "ties".)

How to calculate the score in a player's hand

Recall that a face card has value 10, a numbered card has its number as its value, and an Ace can have value either 1 or 11. This means a hand of cards can have multiple possible scores. The score of a hand of cards is the largest int that is <= 21 if possible, else the smallest int that is > 21. (Example: if the hand is "Ace of Hearts", "Ace of Clubs", and "8 of Diamonds", the score of the hand is 20. Another example: if the hand is "Ace of Hearts", "6 of Spades", "Jack of Diamonds", and "5 of Clubs", the score is 22, because a score <= 21 is impossible.)

Input and output

All output is posted to the console window, using Console.Write and Console.WriteLine. When the human is asked if she wants one more card or wants to play another round, use Console.ReadLine. A round of play should generate a sequence like this in the console window:
===================================================

Welcome to Blackjack! 
 
New round:
Your top card is: 3 of Clubs
The house player's top card is:  8 of Hearts
The house player does NOT hold a blackjack, so play continues:

Your hand is:
3 of Clubs
Ace of Diamonds
The score is: 14
Do you want another card (y or n)? y
Your hand is:
3 of Clubs
Ace of Diamonds
Ace of Spades
The score is: 15
Do you want another card (y or n)? y
Your hand is:
3 of Clubs
Ace of Diamonds
Ace of Spades
4 of Clubs
The score is: 19
Do you want another card (y or n)? n

The house player's hand is:
8 of Hearts
7 of Spades
The score is 15
The house player's hand is:
8 of Hearts
7 of Spades
Queen of Hearts
The score is 25.  
A bust!

You win!
After 1 rounds, you have 1 wins.
Do you want to play another round (y or n)?   (AND SO ON...)

===================================================
Perhaps the console input/output is not so attractive, but it lets us concentrate on the operation of the game. (Large systems are often prototyped in this way --- with a simplistic user interface that is later replaced by a better-looking one.) In a subsequent assignment, we will add graphics to the user interface.

``Reshuffling'' the deck

Do this part once you have your game operating properly: When subsequent rounds are played, the dealer continues to deal from the same deck. When the deck runs empty (and this will usually happen in the middle of a round of play), then the dealer must continue by dealing from all the previously used cards (the "discards") as the new deck. (Do not construct a new Deck object! Use the cards/deck that you started with.)

The cards that are already in the hands of the players stay where they are. This means you must improve the coding of the deal method in class Deck and you will need to code a new method in class Deck that reclaims previously used cards. class Hand will likely need a new method to surrender its cards and reset to an empty hand.

Testing and Implementation

Use the CardConcepts project to model the cards, the deck, and the players' hands. Modify class Deck and class Hand as needed.

You must write and include unit tests for all classes in CardConcepts and the new classes you write. (You've done much of the work already in lab.) Include the unit tests in the UnitTests project.

Use Visual Studio's debugger with breakpoints if you need to see the values saved in storage during the tests.

CardConcepts is a Class Library and its executable code is saved as a dll file. This VS Solution must be kept separate and will be used in a later assignment. So, you must construct a second Visual Studio Solution --- a Console Application named Blackjack --- that holds the code you write for playing the Blackjack game.

Here is a package diagram that shows the structure of your work:

  MyLastName.MyFirstName.Assn1  (Folder)
  +---------------------------------------------------------
  |
  |  CardConcepts (VS Solution)
  |  +-------------------------------------------------------
  |  |  CardConcepts (VS Project)     UnitTests (VS Project)
  |  |  +-------------------          +------------------
  |  |  | class Card,  class Hand,    |  unit tests go here
  |  |  | class Deck                  |
  |  +--------------------------------------------------------
  |
  |
  |  Blackjack (VS Solution)      (the card game you write)
  |  +-----------------------------------------------------
  |  |  Blackjack (VS Project)    UnitTests (VS Project)
  |  |  +----------------------   +----------------------
  |  |  |  your work goes here    |  if there are classes in
  |  |  |                         |  Project Blackjack to unit-test
  |
  +--------------------------------------------------------------

Once you complete your work, run a sample session where you play the game for at least 3 rounds. Copy the output from your play into a text file, test.txt. (If you don't know how to Mark-Copy-Paste from an MS command window into a text file, ask me!)

What to submit

As shown in the package diagram above, make a folder with the name, MyLastName.MyFirstName.Assn1, and place into it your VS Solution, Blackjack, your VS Solution, CardConcepts, and test.txt. Zip the folder into a .zip file and submit the .zip file to the CIS501 site on K-State Online. To get credit for your work, you must follow the structure indicated in the package diagram.

The teaching assistant will study your work and apply some additional tests. I will also study your work. Later we will meet one-on-one to discuss the work.

This is individual work

You must do this exercise solo --- you won't learn everything I want you to learn if you work with someone else! If you have difficulties doing the assignment, don't hesitate to ask to meet with me or with the TA for assistance. If I determine that you had unauthorized aid, I will award no points for your work and you get into big trouble.