This program will simulate the game of hearts

Assignment Help C/C++ Programming
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:

  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!

Reference no: EM13165281

Questions Cloud

F does not logically imply : Given R = (J,K,L ) and the set F of FDs J -> K and L -> K , show that F does NOT logically
Variables should be private and the class functions public : All the class variables should be private and the class functions public. The class functions should be implemented in a file Inventory.cpp which should be linked with the inventory.hpp file.
Encode or decode a color combination : In the early days of computer graphics, colors where represented as two numbers. The first number was the foreground color and the second was the background color. These two values, which ranged from 0 to 15 were stored within a single byte; the fore..
Offer activities to promote diversity : "Many organizations sponsor or offer activities to promote diversity.  What types of activities or trainings do organizations offer to ensure/promote a diverse company.
This program will simulate the game of hearts : 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 p..
Harassment prevention training : What are some of the reasons an organization should have harassment prevention training?  Even though our text focuses on sexual harassment, which groups of people, in addition to women, can be targets of harassment? "
Efforts against terrorism more effective : If the United States is NOT making progress, what would have to happen to make the efforts against terrorism more effective?
Morality-rational self-interest : Moral philosopher Thomas Hobbes argued that morality (that is, willingness to abide by basic ethical rules) arises not from benevolence (the desire to be kind and beneficial) but from rational self-interest.
Lying and cheating-negotiation skills : Isn't this "ethics" business all about not lying and cheating? If other people do it (and they'll do it to me), shouldn't I be doing it to them? Where does effectiveness come into play? Please answer in 150 words or less and cite url or references us..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd