Ask C/C++ Expert


Home >> C/C++

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:

  1. They try to avoid winning tricks whenever possible (no tricks means no points)
  2. If winning a trick seems unavoidable, win big (with a high card) -- perhaps the lower cards can still lose tricks later.
  3. 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).
  4. 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.
  5. 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!

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9455399

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As