You are coding a simple game called Pig. Players take turns
rolling
a die. The die determines how many points they get. You may
get
points each turn your roll (turn points), you also have points for
the
entire game (grand points). The first player with 100 grand points
is
the winner. The rules are as follows:
Each turn, the active player faces a decision (roll or hold):
Roll the die. If it’s is a:
1: You lose your turn, no turn total points are added to your
grand total.
2-6: The number you rolled is added to your turn total.
Hold: Your turn total is added to your grand total. It’s now
the
next player’s turn.
Requirements.
These are the requirements for the as-
signment. This means they are general
and apply to the entire assignment,
rather than one specific part. Not every
assignment will have a requirements
section.
• Display the game score every time the active player
changes.
• Use whatever techniques you think best for creating reliable
code
which is easy to read and maintain. Do not optimize for
computer
performance. Choose data structures which are easy to expand,
or
preferably, automatically re-size themselves (if needed).
• Make your output as clear and easy to understand as
possible.
item Use structured programming or object oriented
programming
techniques.
• You cannot use any data structures from the standard
template
library. No vectors or anything like that.
• Make a simple AI with a random number. Each decision the
com-
puter rolls, 1-3 hold, 4-6 roll again.
• Style guide elements apply: comments, layout, Program
Greeting,
Source File Header, and variables etc. etc.
Specification Bundles.
These are additional requirements for the assignment. You
code
the specifications from the various groups to control the
maximum
potential grade you can get for this assignment. The more work
you
do, the better grade you can get. Specifications are bundled
into
Folsom Lake College
pig (pig) 2
groups: "A", "B", and "C". You must meet the specifications of
the
lowest group before I will count the specifications for the
highest
group. For example, you must meet the "C" specifications before
I
will count the "B" specifications. If you miss one element of a
spec-
ification bundle, that is the grade you will get for the assignment
-
regardless of how much extra work you do. Note: sometimes
you
will get comments stacking on top of each other - that’s OK
even
though you would never do that in the real world.
You want to comment where these
specifications begin because I will be
looking for them. You want me to find
them. To confirm I can find them, use
the grep trick discussed below.
"C" Specification Bundle.
1. // Specification C1 - Time Seed
Get the current time and use it for a random number seed.
2. // Specification C2 - Student Name
Allow name to accept first plus last name (ie 2 words). Display
it
somewhere in the output.
3. // Specification C3 - Numeric Menu
Use a numeric menu to collect the human players actions. See
figure 1 for an example menu.
4. // Specification C4 - Bulletproof Menu
Detect and re-prompt if incorrect data is entered.
"C" Bundle Menu Options.
1. 1. Roll
2. 2. Hold
3. 3. Quit
Figure 1: Allowable menu options for
this bundle.
"B" Specification Bundle.
1. // Specification B1 - Track each turn
Keep track of the points each player scores each turn.
2. //Specification B2 - Randomize Start
Randomly determine which player starts the game.
3. // Specification B3 - Alpha Menu
Switch to an alphanumeric menu. Only accept the letters
between
the <>’s. See the next page for an example. List
specification C3
like this: // Specification C3 - REPLACED. Put this comment
right
above specification B3. Note: Specification C4 now applies to
this
alphanumeric menu.
4. // Specification B4 – Resign Option
The human can quit the current game and automatically restart
a
new one. See figure 2 for an example menu.
"A/B" Bundle Menu Options.
1. <R>oll
2. <H>old
3. Re<s>ign
4. <Q>uit
Figure 2: Allowable menu options for
this bundle.
"A" Specification Bundle.
1. // Specification A1 - Main Event Loop
Run the program in a main event loop. Prompt the player when
the game ends if they want to play another game. Use a ’y’ or
’n’
prompt to stop playing games.
pig (pig) 3
2. // Specification A2 - Group Stats
Keep track of the number of games played, who won and lost
each
game and the number of turns each game took. Don’t forget to
keep track of games resigned, too. You can use a struc for this
is
you wish.
3. // Specification A3 - Current Date
Include in the program greeting the current date and time
this
program started. Use a library to automatically get this, do not
ask
the client to enter it.
4. Specification A4 - Upper and Lower Case
You can accept upper and lower case letters for your menu in
specification B3.
#include <iostream>
#include <cstdlib>
#include <ctime>
int dieroll();
int yourturn();
int main()
{
int humanscore=0,compscore=0;
srand(time=(NULL))
{
humantotalscore =yourturn(totaal human score)
cout<<total score so far is <<human total score>
if(human totalscore >=100)
{
cout <<"you win";
return 0;
}
comptotalscore=comptotalscore+compturn(comptotalscore)
if (comptotalscore is >=100)
}
}
}
int dieRoll()
return(rand%6)+1;
}
int human turn (int humanscore)
char roll0or hold;
do
{
score=dieroll();
if(score == 1)
{
return 0;
}
cout<<you rolled a <<score<< "score so far this turn is"<<this score<<end1;
}
while(rollorhold == r || rollorHold == R)
{
cout << "cpu holds."<< end1;
return thisTurnscore;
}
Get Answers For Free
Most questions answered within 1 hours.