Project 2, Hi Ho! Cherry-O Game Simulation

Short Description:

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

This assignment is worth 50 points.

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 number, 1-4, the player takes 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. If a player spins a bird or dog and only has one cherry in their basked, 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 one to reach 10 cherries in the basket cries "Hi Ho! Cherry-O" and wins the game.

The game must end on an exact count. For example, if a player has two cherries on their tree, but spins a three, they may not remove those two cherries. They must remove the amount of cherries indicated by the spin or nothing.

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. If they are a computer, assign it a name. All players baskets should be initialized to contain 0 cherries, the trees to contain 10 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

An example of this interaction would be

Welcome to Hi Ho! Cherry-O
Is player 1 a human or computer (H/C): H
Please enter your name: Timmy
Welcome Timmy.

Is player 2 a human or computer (H/C): C
Player 2 will be Alphie.

Is player 3 a human or computer (H/C): C
Player 3 will be Bettie.

Is player 4 a human or computer (H/C): C
Player 4 will be Deltie.

For each round, print a report using the following format:

Round 1

Player 1 Timmy, it is your turn.
Press ENTER to spin: enter key is pressed

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 cherries. You now have 1 cherries.

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

      Player 1: Timmy   2      a human    * * O O O O O O O O
      Player 2: Alphie  0   a computer    O O O O O O O O O O
      Player 3: Bettie  1   a computer    * O O O O O O O O O
      Player 4: Deltie  4   a computer    * * * * O O O O O O
Press ENTER to continue:  enter key is pressed

Round 2
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. The game is at least three rounds long ( spins of 4, 4, 2 for example).

      Player 1: Timmy   8       a human    * * * * * * * * O O
      Player 2: Alphie  3    a computer    * * * O O O O O O O
      Player 3: Bettie  8    a computer    * * * * * * * * O O
      Player 4: Deltie  2    a computer    * * O O O O O O O O
Press ENTER to continue:

Player 1 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 16 rounds.

Discussion

Required Files

You should submit a tar file containing a source code file and a makefile for this program.

Please use this Makefile

Submission

Submit your tar file to the D2L assignment folder Project2 by the due date.