Reference no: EM13165281
This assignment will also make use of arrays and functions to simulate a game. There is no need for any tools introduced since the previous assignment, though some may be helpful.
SPECIAL ASSIGNMENT REQUIREMENT:
In addition to turning in the assignment, an additional submission is to be made during the week beforehand. A special dropbox will be open until Tuesday, 22 April, to describe the functional aspects of your program: See the similar requirement in Homework 5 for details.
ASSIGNMENT DESCRIPTION
This program will simulate the game of Hearts, which is a four-player trick-taking game using any ordinary deck of playing cards. Each player is dealt thirteen cards. Whoever is dealt the Two of Clubs must lead it to the first trick. Each person plays one card to each trick, and the highest card that follows suit to the trick leads to the next, until all the cards are played. Play restrictions are as follows:
- One must follow suit whenever possible: for example, if the first card led to a trick is a Spade, then you must play a Spade from your hand if you have one. If you cannot follow suit, you may play any card you wish.
- One may not lead a Heart to a new trick unless a Heart has been previously discarded on an earlier trick (when not following suit). The sole exception to this rule is if the leader has no card in his hand outside of Hearts.
Several cards in the deck are worth points: every Heart card is worth one point; and the Queen of Spades is worth 13 points. Points are Bad! The winner of the game of Hearts is the one who earns the fewest points.
But of course, even that last paragraph has an exception: if a single player collects all the point cards within a single round of play (i.e. wins all the tricks that include Hearts and the Queen of Spades), he "Shoots the Moon". Instead of that player receiving the 26 points for those cards, everybody else gets those points.
A typical game of Hearts continues for multiple hands until one player reaches or exceeds 100 points. Whoever has the fewest at that moment wins the game.
SAMPLE INTERFACE
The following is a portion from the instructor's current implementation:
Clubs: 6--Five
Spades: 1--King
Hearts: 0--Four 2--Three 3--Eight 4--Ace 5--Ten
Which card would you like to lead? (type the number) 6
The Five of Clubs is led.
Computer player plays Three of Clubs
Computer player plays Nine of Clubs
Computer player plays Five of Spades
Computer #2 wins the trick.
The Eight of Diamonds is led.
Computer player plays Jack of Hearts
Spades: 1--King
Hearts: 0--Four 2--Three 3--Eight 4--Ace 5--Ten
Which card would you like to play? (type the number) 1
Computer player plays Ace of Spades
Computer #2 wins the trick.
The King of Diamonds is led.
Computer player plays Queen of Hearts
Hearts: 0--Four 1--Ten 2--Three 3--Eight 4--Ace
Which card would you like to play? (type the number) 4
Computer player plays Seven of Hearts
Computer #2 wins the trick.
The Three of Diamonds is led.
Computer player plays Four of Spades
Hearts: 0--Four 1--Ten 2--Three 3--Eight
Which card would you like to play? (type the number) 1
Computer player plays Jack of Spades
Computer #2 wins the trick.
The Six of Hearts is led.
Computer player plays King of Hearts
Hearts: 0--Four 1--Eight 2--Three
Which card would you like to play? (type the number) 1
Computer player plays Seven of Spades
Computer #3 wins the trick.
The Ten of Spades is led.
Hearts: 0--Four 1--Three
Which card would you like to play? (type the number) 1
Computer player plays Four of Clubs
Computer player plays Five of Hearts
Computer #3 wins the trick.
The Six of Spades is led.
Hearts: 0--Four
Which card would you like to play? (type the number) 0
Computer player plays Seven of Clubs
Computer player plays Two of Hearts
Computer #3 wins the trick.
Updated scores: You: 1 Computer #1: 0 Computer #2: 18 Computer #3:7
Next hand!
The Two of Clubs is led.
Computer player plays Ten of Clubs
Computer player plays Queen of Clubs
Clubs: 0--Eight 7--Four 11--Five
Diamonds: 2--Five 4--King 6--Nine
Spades: 3--Three 5--Six 8--Queen
Hearts: 1--Two 9--Ten 10--Seven 12--Nine
Which card would you like to play? (type the number)
Of course, there is no need to match this interface exactly. It is mostly here to demonstrate the game in progress.
INPUT VALIDATION
As for every other assignment in a first year course, you may assume 'reasonable' sorts of input to the program. If your program expects an integer input, it will only receive an integer.
However, your program should at least verify that the player at the keyboard follows the rules of the game. This is little more than verifying that the card he chooses to play follows the two restrictions given above -- regarding following suit, and not leading hearts prematurely.
When simulating the computer player, there is no need to be particularly intelligent, but the computer player must still follow the rules of the game. Your program may use whatever means it chooses to have the computer pick cards.
SMALL EXTRA CREDIT OPTION
One significant part of the Hearts game is the ability to trade some cards away before playing to the first trick. Every player chooses three cards from his hand to give away, and then receives three replacement cards from some other player. Each hand of the game, the trading is slightly different:
On the 1st, 5th, 9th, etc. hand, hand three cards to the player who plays after you (and receive three from the player that plays before you).
On the 2nd, 6th, 10th, etc. hand, pass three cards to the player who plays before you, and receive three from the player that plays after you.
On the 3rd, 7th, 11th, etc. hand, trade three cards with the player across from you on the table.
On the 4th, 8th, 12th, etc., no trading occurs. You are stuck with what you have.
All trades are resolved before the first trick is played -- it is legal to pass away the Two of Clubs to stick someone else with the lead.
LARGER EXTRA CREDIT OPTION
It is one thing to simply make the computer play his cards legally -- it is another to have him play somewhat intelligently, to make the game interesting.
Some players adopt a rather conservative strategy to Hearts that can be approximated:
- They try to avoid winning tricks whenever possible (no tricks means no points)
- If winning a trick seems unavoidable, win big (with a high card) -- perhaps the lower cards can still lose tricks later.
- Look for opportunities to rid your hand of particular suits -- so that if those suits are led, you can discard anything you like (such as risky high cards).
- When passing cards away, high cards from short suit holdings are a priority. High cards in long suits are less dangerous, since you don't have to play them when following suit, and can discard them when not following suit.
- Also, tying 3-4 together, passing very short suits away might allow you start play with no cards in a suit, making it easy to discard dangerous cards.
EVEN LARGER EXTRA CREDIT OPTION
If you really want the computer player to be challenging, try to make it make intelligent decisions regarding Shooting the Moon. The most conservative play-style of not winning any points at all will backfire if it results in all the points on a hand being one by a single player!