Write a program that runs a simple computer vs human card game. You should use the basic C/C++ features like:

  • constants
  • Enumerations
  • Structures
  • Arrays
  • cin/cout
  • Loops and conditions
  • The standard random number generator

The game uses one French deck of cards with 4 suits (heart, diamond, spades and clubs) and 13 cards per suit (numbered 1, 2, 3, , 10, Jack, Queen, King). The principle is simple:

The game is played in multiple rounds. When the first round starts, 4 random cards are drawn from the deck and placed on the table. At each round, each player gets a hand of three random cards.

One by one, the players would match one card from their hands with cards from the table such as it is either

  • One-to-one matching: one card with the same number as his card (of course different suit)
  • One-to-two matching: Two cards which sum equals the number of his card. Jack has a value 11. Queen has a value 12 and King has a value 13.

The player who matches cards (either one to one or one to two) wins them.

If no matching is possible, the player has to add one of his cards to the table

At the last round, the last player making a match wins the cards left on the table without matching

The game ends when there are no cards left in the deck to be distributed. With a simple count, we can find that there are 8 rounds (13 x 4 = 52 cards per deck, take 4 for the initial table, 48 are left for playing. In each round, each player gets 3 cards so 6 cards in total. 48/6=8 rounds)

The winner is the player who has won the largest number of cards.

Note:

When playing, the computer does not take into account the cards in the hand of the opponent. Its decision is based only on his cards and the cards on the table.

However, when the human player makes a match, the computer needs to check that the human is not cheating. So, it needs to check that:

  • The human owns the card he is claiming to match
  • The human is making a correct match (one to one or one to two
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.