pa2.docx

CS 112 Homework #2: Simple 5-Card Poker Game

In this assignment, you will develop a simple poker game, complete with basic AI, using the object oriented programming principles discussed in class.

UML Class Diagram

Your assignment must contain and use the following classes:

Card Class

We use the card class to represent an individual card in a deck. At minimum, the card class should contain the functions and variables listed in the supplied UML diagram. This includes:

int _suit

This variable indicates the card's suit: Club, Diamond, Heart, or Spade.

int value

value represents the value of the given card. Numerical cards (e.g. 2 of clubs) have a value equal to their number. Provide the values for the following face cards: Jack: 11, Queen: 12, King: 13, Ace: 14.

getSuit

Returns the card's suit as a string.

setSuit

Sets the card's suit.

getName

Returns the card's name.

setName

Set's the card's name.

getValue

Returns the card's value as an integer (e.g. 2-14).

setValue

Set's the card's value.

Deck Class

The deck class will be used to represent a standard 52 card poker deck. At minimum, the deck class should contain the functions and variables listed in the supplied UML diagram. This includes:

Card _cards[52]

This is an array of 52 unique cards.

int _played_cards

This variable is used to track previously dealt cards.

Constructor

The Deck's constructor should initialize and shuffle a fresh deck of 52 unique cards.

buildDeck

Calling this function will initialize _cards to contain all normal 52 cards.

shuffleDeck

Calling this function will randomly rearrange the cards in the deck.

getNextCard

This function will select the next card from the deck.

Hand Class

You will need two instances of the Hand Class in your game: one for the player, and one for the computer. Each Hand will contain the respective player's current hand of cards. The hand class must have several helper methods that can be used to determine the strength of the hand. If you are unfamiliar with poker hands, Wikipedia has a related article that may be of interest.

PokerGame Class

The PokerGame class will be used to encapsulate all of the logic associated with playing the game of poker. The play method's operation will be discussed in the next section.

Flow of Play

Your poker game's play() method should operate as follows:

1. Deal the player five cards and display the results on the screen

2. Ask the player which cards he or she would like to exchange

3. Remove the desired cards from the player's hand

4. Deal the player N new cards (N = exchange amount)

5. Display the new hand on the screen

6. Deal the computer five cards and display the results on the screen

7. The computer determines how many cards to exchange based on the following logic:

a. zero cards if the computer has a four of a kind, full house, straight, or flush

b. one card if the computer has two pair

c. two cards if the computer has three of a kind

d. three cards if the computer has a pair

e. five cards if the computer has none of the above

8. Remove the appropriate number of cards in the computer's hand

9. Deal the computer the appropriate number of replacement cards

10. Display the new hand on the screen

11. Determine the winner of the game based on the following rankings:

a. Four of a kind

b. Full house

c. Flush

d. Straight

e. Three of a kind

f. Two Pair

g. Pair

12. Indicate the winner on the screen

Sample Output

*** Simple 5-Card Poker ***

The cards have been shuffled and you are dealt:

1. Five of Hearts

2. Five of Spades

3. Jack of Hearts

4. Two of Clubs

5. Ace of Diamonds

Indicate the cards that you would like to exchange (-1 to end):

4

3

6

Invalid selection.

Indicate the cards that you would like to exchange (-1 to end):

-1

Your new hand is:

1. Five of Hearts

2. Five of Spades

3. Two of Clubs

4. King of Hearts

5. Ace of Diamonds

The computer is dealt the following cards:

1. Ace of Spades

2. Three of Spades

3. Five of Diamonds

4. Ace of Hearts

5. Six of Clubs

The computer exchanges cards 2, 3, and 5. The new hand is:

1. Ace of Spades

2. Seven of Clubs

3. Seven of Diamonds

4. Ace of Hearts

5. Queen of Diamonds

You have one pair.

The computer has two pair.

The computer wins.

Header Comment, and Formatting

1. Be sure to modify the file header comment at the top of your script to indicate your name, student ID, completion time, and the names of any individuals that you collaborated with on the assignment.

2. Remember to follow the basic coding style guide. For a list of basic rules, see my website or examine my example files from previous assignments and labs.

Reflection Essay

In addition to the programming tasks listed above, your submission must include an essay that reflects on your experiences with this homework. This essay must be at least 350 words long. Note that the focus of this paper should be on your reflection, not on structure (e.g. introductory paragraph, conclusion, etc.). The essay is graded on content (i.e. it shows deep though) rather than syntax (e.g. spelling) and structure. Below are some prompts that can be used to get you thinking. Feel free to use these or to make up your own.

· Describe a particular struggle that you overcame when working on this programming assignment.

· Conversely, describe an issue with your assignment that you were unable to resolve.

· Provide advice to a future student on how he or she might succeed on this assignment.

1. Describe the most fun aspect of the assignment.

1. Describe the most challenging aspect of the assignment.

1. Describe the most difficult aspect of the assignment to understand.

1. Provide any suggestions for improving the assignment in the future.

Deliverables

You must upload your assignment through Canvas no later than midnight on Friday, September 30, 2016. Remember that your submission must either contain a CodeBlocks or Visual Studio project file!

Grading Criteria

Your assignment will be judged by the following criteria:

Error Free Compile (weight: 5%)

· [0] Your program contains compiler errors.

· [1] Your program compiles without issue.

Error Free Runtime (weight: 10%)

· [0] Your program throws a runtime exception.

· [1] Your program does not encounter any runtime exceptions.

Style (weight: 5%)

· [0] Your code contains more than 7 distinct stylistic errors

· [1] Your code contains between 2 and 7 distinct stylistic errors

· [2] Your code contains 1 or 0 stylistic errors

User Interface (weight: 15%)

· [0] Your program does not match the user interface guidelines as specified in the sample output

· [1] Your program almost matches the specified user interface guidelines

· [2] Your program completely matches the specified user interface guidelines

Required Classes (weight: 20%)

· [0] Your program does not use nor does it contain the required classes

· [1] Your program contains, but does not fully use the required classes

· [2] Your program contains and uses the required classes

Game Play (weight: 45%; see list below)

· [0] Your program is missing more than 4 of the listed game play components

· [1] Your program is missing more than 3 of the listed game play components

· [2] Your program is missing more than 2 of the listed game play components

· [3] Your program is missing more than 1 of the listed game play components

· [4] Your program contains all of the necessary game play components

Required Game Play Components

· The program randomly deals cards to both the player and the computer

· The program prompts the user for cards to exchange

· The program correctly identifies and handles invalid input during the card exchange phase

· The program deals the requested number of cards to the player after the exchange phase

· The computer selects the number of cards to redraw based on the algorithm outlined in the "flow of play" section

· The program correctly determines the winner of a given game

Card-_suit : string-_value : int-_name : string+getSuit() : string+setSuit(suit : string) : void+getName() : string+setName(name : string) : void+getValue() : int+setValue(value : int) : void+getValueName() : stringDeck-_cards[52] : Card -_played_cards : int<<constructor>> +Deck()-buildDeck() : void+shuffleDeck() : void +getNextCard() : CardHand-_cards[5] : Card<<constructor>> +Hand()+setCard(int position, Card card) : void +getCard(int position) : Card+hasPair() : bool+hasTwoPair() : bool+hasThreeOfAKind() : bool+hasStraight() : bool+hasFlush() : bool+hasFullHouse() : bool+hasFourOfAKind() : boolPokerGame+playGame() : void

Card <<Stereotype>> parameter -_suit : string -_value : int -_name : string +getSuit() : string +setSuit(suit : string) : void +getName() : string +setName(name : string) : void +getValue() : int +setValue(value : int) : void +getValueName() : string Deck <<Stereotype>> parameter -_cards[52] : Card -_played_cards : int <<constructor>> +Deck() -buildDeck() : void +shuffleDeck() : void +getNextCard() : Card Hand <<Stereotype>> parameter -_cards[5] : Card <<constructor>> +Hand() +setCard(int position, Card card) : void +getCard(int position) : Card +hasPair() : bool +hasTwoPair() : bool +hasThreeOfAKind() : bool +hasStraight() : bool +hasFlush() : bool +hasFullHouse() : bool +hasFourOfAKind() : bool M1 M2 M3 M4 M1 M2 M3 M4 PokerGame <<Stereotype>> parameter +playGame() : void M1 M2 M3 M4