Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UNIX and C Programming (Program I\'m using is PuTTY) Game Specification: Write a

ID: 3697580 • Letter: U

Question

UNIX and C Programming (Program I'm using is PuTTY)

Game Specification:

Write a program in C that allows a single Player (the user) to play a simple four dice game of chance against "The Odds".

There is a single player, with four six sided die.

The sides of each die are labeled with the numbers from 1 to 6, we will call this the value of the die.

A game is made up of rounds, a single round is played as such:

The player rolls their four dice

The dice are displayed, in some reasonable format.

A determination is made as to whether or not the player won the round, this determination is made via the following rules:

A Quad is when all the dice have the same number on their top faces. If the player has any Quad then they win the round.

A Triple is when exactly three of the dice have the same number on their top faces. If the player has any Triple then they win the round.

A Straight is when the numbers on the three dice faces can be arranged to form a consecutive sequence like 1 2 3 4 or 3 4 5 6 If the player has any Straight then they win the round.

A Two-Pair is when exactly two dice have the number n1 on their top faces, exactly two dice have the number n2 on their top faces, and n1 is not equal to n2. If the player has any Two-Pair then they win the round.

A Pair is when (exactly) two dice have the same number on their top faces. If the player has any Pair then they neither win nor lose the round.

A Junker is then anything that is not listed above. If the player has any Junker then they lose the round.

The result of the round (with respect to the Player) is reported.

The player is asked if they wish to play another round.

Once the player indicates that they do not wish to play another round: Before exiting, the program displays a short report stating how many rounds were played, of those - how many were won and how many were lost.

Outline:

Create a Script .c file in PuTTY

Write the necessary commands to meet the game specification given above

Make sure to test your “program” when it is done

You really need to run your program a number of time to do this thoroughly

Notes(s):

You will need to use the

(rand() % 6) + 1 to generate the die values

Your .c file will be many lines long

Sample Run(s):

Welcome to Computer Dice

-------------------------------------

You will first roll your dice

Next the outcome of your roll will

be determined:

any Quad and you Win

any Triple and you Win

any Straight and you Win

any Two-Pair and you Win

any Pair and you just roll again

anything else and you Lose

-------------------------------------

Player

----------

1 4 5 6

Junker - Sorry, you lose!

Do you wish to play again [y, n] : 6

Do you wish to play again [y, n] : sure

Do you wish to play again [y, n] : y

Player

----------

1 2 5 5

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

3 3 4 5

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

1 3 6 6

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

3 3 3 4

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

2 5 6 6

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

2 2 2 3

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

3 3 3 6

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

1 3 3 6

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

1 2 4 5

Junker - Sorry, you lose!

Do you wish to play again [y, n] : y

Player

----------

1 2 4 5

Junker - Sorry, you lose!

Do you wish to play again [y, n] : y

Player

----------

1 4 4 6

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

1 2 3 4

Straight - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

1 3 3 5

Pair - Its a push!

Do you wish to play again [y, n] : y

Player

----------

2 3 4 5

Straight - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

2 2 2 6

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

3 4 4 4

Trip - Congrats, you win!

Do you wish to play again [y, n] : y

Player

----------

1 2 4 5

Junker - Sorry, you lose!

Do you wish to play again [y, n] : y

Player

----------

3 3 5 5

Two-Pair - Congrats, you win!

Do you wish to play again [y, n] : n

Computer Dice Results

---------------------

You played 19 rounds

Rounds won :8

Rounds lost :4

---------------------

Explanation / Answer

import java.util.Scanner;
public class dice
{
public static void main(final String[] args)
{
Scanner scan = new Scanner(System.in);
char c = 0;
int count = 0;
int round = 0;
int roundl = 0;
System.out.println("Welcome to Dice Game");
System.out.println("--------------------...
System.out.println("You will first roll your dice");
System.out.println("You will first roll your dice");
System.out.println("Next the outcome of your roll will");
System.out.println("be determined");
System.out.println("any Pair and you Win");
System.out.println("any Straight and you just roll again");
System.out.println("anything else and you Lose");
System.out.println("--------------------...
do
{
System.out.println("Player");
System.out.println("----------");
int d1 = (int)(Math.random() * 6) + 1;
int d2 = (int)(Math.random() * 6) + 1;
System.out.println(d1 + " " + d2);
if(d1 == d2)
{
System.out.println("Congrats, you win!");
round++;
count++;
do
{
System.out.println("Do you want to play again?");
c = scan.next().charAt(0);
}while(c != 'y' && c != 'n');
}
else if(d2 - d1 == 1 || d1 - d2 == 1)
{
System.out.println("It's a tie!");
round++;
do
{
System.out.println("Do you want to play again?");
c = scan.next().charAt(0);
}while(c != 'y' && c != 'n');
}
else
{
System.out.println("Sorry, you lose!");
round++;
roundl++;
do
{
System.out.println("Do you want to play again?");
c = scan.next().charAt(0);
}
while(c != 'y' && c != 'n');
}
}while(c != 'n');
System.out.println("Computer Dice Results");
System.out.println("----------");
System.out.println("You played " + round + " rounds");
System.out.println("Rounds won: " + count);
System.out.println("Rounds lost: " + roundl);
System.out.println("----------");
}
}