Question

Two player Dice game In C++ The game of ancient game of horse, not the basketball...

Two player Dice game In C++

The game of ancient game of horse, not the basketball version, is a two player game in which the first player to reach a score of 100 wins. Players take alternating turns. On each player’s turn he/she rolls a six-sided dice. After each roll:

a. If the player rolls a 3-6 then he/she can either Roll again or Hold. If the player holds then the player gets all of the points summed up during his/her turn added to their previous total. Each player starts with 0 points. It then alternates to the other player’s turn.

b. If the player rolls a 1 or a 2 then the player loses a turn and the player gets no new points on this roll and it becomes the other player’s turn.

If a player reaches 100 or more points after holding the then the player wins unless the other player scores more points on their final turn. After one player has reached 100+ points and holds the other player will be allowed one more series of rolls and either falls short of the previous player’s points or exceeds the other player’s total and hence they win.

Write a C++ program that plays the game of horse where one player is a human and the other player is the computer. Allow the person to enter an “h” for hold and an “r” for roll. The computer (player) program should follow the following protocol:

It should keep rolling on the computer’s turn until it has accumulated at least 10 points before it is allowed to hold and it must hold after it reaches at least 10 or more. Just as the rules state above, it will lose its turn if it rolls a 1 or a 2 and no points are accumulated for the computer. If the computer goes over 100 points the human is allowed, just as above, to roll until it gets more points than the computer or loses his/her turn. The person/human should roll first.

Your program should announce the name of the person winning or the name computer wins.

Your program must use C++ built in intrinsic functions to do random generation to simulate the rolling of a six sided die. As well as any other built in functions you wish to use.

Your program should also contain at least two user defined functions for the user’s turn and also one for the computer’s turn. You will probably want more than this, possibly nesting functions, to do the rolling and totaling and to determine winners.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ code:

#include<iostream>
#include<cstdlib>
using namespace std;
//function to roll a dice once
int roll()
{
   return(rand()%6+1);
}

//function for player roll
int user_tern()
{
   int n,sum=0;
   int flag=1;
   char ch;
   while(flag)
   {
       n=roll();
       cout<<"You roll a:"<<n;
       if(n>2)
       {
           sum+=n;
           cout<<endl<<"Do you want to hold/roll hit h/r: ";
           cin>>ch;
           if(ch=='h')
           {
               return(sum);
           }          
       }
       else
       {
           cout<<endl;
           return(0);
       }
   }
}

//function for computer roll
int comp_tern()
{
   int n,sum=0;
   while(sum<=10)
   {
       n=roll();
       cout<<" Computer rolls a:"<<n;
       if(n>=3)
       {
           sum+=n;
       }
       else
       {
           return(0);
       }
   }
   return(sum);
}

//main function to use above functions
int main()
{
   int comp,player,comp_total=0,player_total=0,tern=0,flag=1,winner=1;
      
   while(flag)
   {
       comp=comp_tern();//computer tern
       comp_total+=comp;  
       cout<<endl<<"Computer total:"<<comp_total<<endl<<endl;
      
       player=user_tern(); //player tern
       player_total+=player;
       cout<<"Player total:"<<player_total<<endl;
      
      
       if(comp_total>=100 &&player_total<100) //check whether computer total reaches 100
       {
           if(comp_total>player_total)
           {
               cout<<endl<<"Computer wins....";
               flag=0;
           }
           else if(comp_total==player_total)
           {
               cout<<"It's a tie......"<<endl;
               flag=0;
           }  
       }
      
       if(player_total>=100 && comp_total<100)   //checks whether player reaches 100
       {
           comp=comp_tern();
           comp_total+=comp;  
           cout<<endl<<"Computer total:"<<comp_total<<endl;
           if(comp_total<player_total)
           {
               cout<<endl<<"Player wins.......";
               flag=0;  
           }
           else if(comp_total==player_total)
           {
               cout<<"It's a tie......"<<endl;
               flag=0;
           }
          
       }
      
   }
}

output:

Add a comment
Know the answer?
Add Answer to:
Two player Dice game In C++ The game of ancient game of horse, not the basketball...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The game of Pig is a simple two-player dice game in which the first player to...

    The game of Pig is a simple two-player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn, a player rolls a six-sided die: If the player rolls a 1, then the player gets no new points and it becomes the other player’s turn. If the player rolls 2 through 6, then he or she can either ROLL AGAIN or HOLD:      At this point, the sum of all rolls...

  • can someone help me fix my jeopardy dice game I am having a hard time figuring...

    can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong #include #include using namespace std; //this function makes a number between 1 and 6 come out just like a dice int rollDie() { return (rand() % 6+1); } //this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n) void askYoNs(){ cout<<"Do you want to...

  • can someone help me with this C++ problem write your game() function and 3+ functions that...

    can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...

  • The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players...

    The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 (”pig”) is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player’s turn, the player is faced with two decisions: roll If the player rolls a 1: the player scores nothing and it becomes the...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • 2. "Craps" is a game played by rolling two fair dice. To play one round of...

    2. "Craps" is a game played by rolling two fair dice. To play one round of this game, the player rolls the dice and the outcome is determined by the following rules: If the total number of dots is 7 or 11 (a "natural"), then the player wins. If the total number of dots is 2, 3, or 12 C'craps"), then the player loses. If the total number of dots is 4, 5, 6,8,9, or 10, then this number is...

  • please write the following program in Java PIG is one of a family of games called...

    please write the following program in Java PIG is one of a family of games called jeopardy dice games, since a player's main decision after each roll is whether to jeopardize previous gains by trying for potentially even greater gains. In PIG, all players start with ZERO points, and each turn involves rolling a die to earn points. The first player to earn 100 points or more total shouts "PIG!" and wins the game. On their turn, a player does...

  • 9. In the casino dice game Craps, players make wagers on a sequence of rolls of...

    9. In the casino dice game Craps, players make wagers on a sequence of rolls of a pair of dice. A sequence of rolls starts with the "shooter" making an initial roll of two dice called the "come-out” roll. If the sum of the dice on the initial roll is 7 or 11 then a player with a bet on the Pass Line wins. If the initial roll results in a sum of 2, 3, or 12 ("craps") then a...

  • using python [6] Craps is a dice-based game played in many casinos. Like blackjack, a player...

    using python [6] Craps is a dice-based game played in many casinos. Like blackjack, a player plays against the house. The game starts with the player throwing a pair of standard, six-sided dice. If the player rolls a total of 7 or 11, the player wins. If the player rolls a total of 2,3, or 12, the player loses. For all other roll values, the player will repeatedly roll the pair of dice until either she rolls the initial value...

  • python code( using functions please)! Rules of the game: - This game requires a dice. The...

    python code( using functions please)! Rules of the game: - This game requires a dice. The goal of the game is to collect the correct number of coins to create a dollar. Players take coins based on a roll of the dice. The numbers on the dice correlate to the coin values as follows:  1—penny  2—nickel  3—dime  4—quarter  5— ( pick a random card from 1 to 4): o 1 = penny o 2 =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT