Project 2, Hi Ho Cherry-O Game Simulation

Short Description:

Write a program which simulates the game of Hi Ho Cherry-O

Goals

When you finish this homework, you should:

Formal Description

Write a program to simulate the game of Hi Ho Cherry-O.

In this game, each of the four players has a tree and a basket. They are trying to pick the 10 cherries from their tree and place these cherries in their basket. To do this, each player in turn spins a spinner. If the spinner lands on a a picture of 1-4 cherries, the player picks that many cherries from their tree and places them in the basket.

The spinner can also land on a hazard. There are three hazards, a bird that takes two cherries from the player's basket and puts these cherries back on the tree, a dog that does the same, and a spilled basket. If the spinner lands on the spilled basket, all of their cherries magically fly from the basket back onto the tree and they must start again.

A player can only pick cherries if they have that many cherries or more on their tree (exact count). A player with 8 cherries in their basket must spin a two to win. They may not win the game on a three or four. This does not apply to the bird or dog. If you only have one cherry in your basket and spin the bird, that cherry is returned to the tree.

Starting with the first player, the players each take turns spinning the the spinner and placing cherries in their basket. The first player to reach 10 cherries in the basket by exact count cries "Hi Ho Cherry-O!" and wins the game.

Before the games begins, gather player information. There are four players in every game, and these players are either human or computer. For each player, your program should ask if that player is a human or a computer. If the player is a human, ask for their name and age. If they are a computer, assign it a name. All players baskets should be initialized to hold 0 cherries and then the game begins.

The computer player names should be assigned as follows:
First Computer Player Alphie
Second Computer Player Bettie
Third Computer Player Deltie
Fourth Computer Player Gammie

For each round, print a report similar to the following:

Timmy, it is your turn.
Press Enter to spin

You picked 2 cherries.   You now have 2 cherries.

Player 2 Alphie, A computer Player
You spilled your basket.   You now have 0 cherries.

Player 3 Bettie, A computer Player
You picked 1 cherry.     You now have 1 cherries.

Player 4 Deltie, A computer Player
You picked 4 cherries.   You now have 4 cherries.

      Player 1, Timmy,  (2)   is a human.    * * O O O O O O O O
      Player 2, Alphie,  (0)   is a computer. O O O O O O O O O O
      Player 3, Bettie,  (1)   is a computer. * O O O O O O O O O
      Player 4, Deltie,  (4)   is a computer. * * * * O O O O O O
Press ENTER to continue:
Note, the game stops for the human player to press enter. You can accomplish this with a getline. Make sure that you clear the stream of any newline characters before you begin the game however. A common error is that the game does not stop for the first human player on the first turn.

As soon as a player wins, the game should end, and report the winner and the number of rounds it took to win. In this case a round consists of the number of times the first player spins, even if the first player is not the winner.

      Player 1, Timmy,  (8)   is a human.    * * * * * * * * O O
      Player 2, Alphie,  (3)   is a computer. * * * O O O O O O O
      Player 3, Bettie,  (8)   is a computer. * * * * * * * * O O
      Player 4, Deltie,  (2)   is a computer. * * 0 0 O O O O O O
Press ENTER to continue:

Timmy, it is your turn.
Press Enter to spin

You picked 2 cherries.   You now have 10 cherries.
Hi Ho Cherry-O!, you win.

You won the game in 35 rounds.
That is very good for a human who is 5 years old.
You should provide similar verbiage if a computer wins.

Discussion

Required Files

You should submit a tar or zip file containing all source code and a makefile.

Submission

Submit your tar or zip file to the D2L folder Program 2 by the due date.