WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a lot.
Pig Dice Game
Pig is a simple two player dice game, played with one die. The first player to reach or surpass 50 is the winner. Each player takes a turn rolling the dice. They add to the pot with each roll, having to decide to roll again and increase the pot, or cash out. The risk being they could lose the amount they’ve accumulated into the pot.
The Rules for each player’s die roll.
Program Requirements:
continue.
should allow r, R, h or H as valid input. If input is anything else, ask the user
again until valid input is obtained.
n, N.
User rolled last in the previous game, then the computer rolls first and vice versa. When the program first begins, the player will make the first roll of the first game.
Development Notes :
● You will need a way to roll dice in your program. The rand() function works well, but returns an integer. If we want numbers 0 – 9 we can get the value modulus 10.
● Call srand() with a value to seed it. It’s common to seed it with the current computer clock, include ctime, and then call srand(time(0)).
solutiomn;
//Answer:Code in C++
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
//return dice value
int rollDice()
{
return (rand()%6 +1);
}
//return player score and handle players turn
int PlayerTurn(int Score)
{
int diceValue;
int pot=0;
char choice;
char input;
cout<<"Players Turn"<<endl;
do
{
diceValue=rollDice();
cout<<"Die Roll : "<<diceValue;
if(diceValue==1)
{
cout<<" Bust"<<endl;
return Score;
}
else
{
pot+=diceValue;//add into pot
cout<<" Pot: "<<pot;
}
while(1)
{
cout<<" (R)oll again or (H)old ? ";
cin>>choice;
if(choice=='r' || choice=='R' || choice=='H' || choice=='h')
break;
else
cout<<"You must enter R or H"<<endl;
}
}while(choice=='r' || choice=='H');
return Score+pot;
}
//return Computer Score and handle computer turn
int ComputerTurn(int Score)
{
int pot=0;
int diceValue;
cout<<"AI Turn"<<endl;
do
{
diceValue=rollDice();
cout<<"Die Roll: "<<diceValue;
if(diceValue==1)//if dice value is 1
{
cout<<" Bust"<<endl;
return Score;
}
else
{
pot+=diceValue;//add into pot
cout<<" pot: "<<pot<<endl;
}
}while(pot<20);
return pot+Score;
}
int main()
{
srand(time(0));
int score_player=0;//player score
int score_computer=0;//computer score
char turn='P';//initial turn player
char choice;
do{
score_player=0;
score_computer=0;
cout<<"You : "<<score_player<<" AI :
"<<score_computer<<endl;
//Game started
while(1)
{
if(turn=='P')
{
score_player= PlayerTurn(score_player);
turn='C';//turn change
}
else
{
score_computer=ComputerTurn(score_computer);
turn='P';//turn change
}
cout<<"You : "<<score_player<<" AI :
"<<score_computer<<endl;
if(score_computer >=50 || score_player>=50)
break;
}
if(score_player>=50)
cout<<"You Won!"<<endl;
else
cout<<"You Lost!"<<endl;
cout<<"Do you want to play again ? ";
cin>>choice;
}while(choice=='Y' || choice=='y');
return 0;
}
//Output



WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a...
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...
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...
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...
Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game. It is played through dice. Rule for scoring The player who rolls higher number gets one point. If both players roll the same number, it is considered a draw and no one gets a point. Dice Specification There are two kinds of dice: normal die, represented by Die class. loaded die, represented by the loadedDie class. Classes Die class Die class has a member...
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...
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...
Can anyone help me with this java program? We are still very early with lessons so no advanced code please. And if you comment throughout the code that would be incredibly helpful. Thank you Create 2 Java files for this assignment: Die.java and TestDie.java Part 1 - The Die Class The program Design a Die class that contains the following attributes: sides: represents how many sides a dice has. A dice usually has 6 sides but sometimes could have...
I need help figuring out how to code this in C++ in Visual Studio. Problem Statement: Open the rule document for the game LCR Rules Dice Game. Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code. Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read...
Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...
Assignment Specifications We are going to use the Monte Carlo Method to determine the probability of scoring outcomes of a single turn in a game called Pig. Your Task For this assignment you will simulate a given number of hold?at?N turns of a game called Pig, and report the estimated probabilities of the possible scoring outcomes. You are NOT implementing the game of Pig, only a single turn of this game. The value of N will be acquired via user...