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

The game %u201CPaper, Rock, Scissors%u201D is a two-player game. The players sim

ID: 3537090 • Letter: T

Question

The game %u201CPaper, Rock, Scissors%u201D is a two-player game. The players simultaneously name (or characterize through pantomime) one of three objects until one player%u2019s selection is superior to the other%u2019s selection. If both players name the same object the game continues. Otherwise, superiority is based on the fact that Scissors cuts Paper, that Stone breaks Scissors, and that Paper covers Stone. The decision table is,

Player 2

Paper

Rock

Scissors

Player 1

Paper

0

1

-1

Rock

-1

0

1

Scissors

1

-1

0

If we use numbers to represent the objects then we can use the numbers as array indices and use pairs of object choices to make decisions. We let 0 represent Paper, 1 represent Rock and 2 represent Scissors.

Suppose Player 1 chooses Rock and Player 2 chooses Scissors. The array element at (1, 2) is 1 which means that Player 1 wins. Suppose Player 1 chooses Scissors and Player 2 chooses rock. The array element at (2, 1) is -1 which means that Player 1 loses. A 0 array element signifies a tie game.

repeat

choice 1 := player1.Choose

choice 2 := player2.Choose

describe(choice1, choice2)

while decision-table(choice 1, choice 2) = 0

A similar two-player game is %u201CRock, Water, Scissors, Glass, Paper%u201D. %u201CIt is obvious to any child that Water wets Stone and Paper; Scissors cost more than Water and Stone; Glass is more brittle than Water and Scissors; Paper is more flexible than Scissors and Glass; and Stone is thicker than Glass and Paper.

Write a program that plays %u201CRock, Water, Scissors, Glass, Paper.%u201D The game is interactive. The game asks the human player to enter his choice and a robot player makes its choice by generating a random number. Use a 2D array as a decision table. The array%u2019s elements%u2019 only values are -1, 0, and 1.


If possible send the solution to ktown213@yahoo.com

Player 2

Paper

Rock

Scissors

Player 1

Paper

0

1

-1

Rock

-1

0

1

Scissors

1

-1

0

Explanation / Answer

I have also mailed it


import java.util.Random;

import java.util.Scanner;


public class rockPap {

// Assume rock 0 water 1 scissor 2 glass 3 paper 4

static int[][] outcome = { { 0, -1, -1, 1, 1 }, { 1, 0, -1, -1, 1 },

{ 1, 1, 0, -1, -1, }, { -1, 1, 1, 0, -1 }, { -1, -1, 1, 1, 0 } };

private static Scanner scan;


/**

* @param args

*/

public static void main(String[] args) {

scan = new Scanner(System.in);

Random r = new Random();

boolean tie = true;

while (tie) {


System.out.println("Please enter an option :");

System.out.println("0 for rock");

System.out.println("1 for water");

System.out.println("2 for scissor");

System.out.println("3 for glass");

System.out.println("4 for paper.");


int human = scan.nextInt();

if (0 <= human && human <= 4) {

int comp = r.nextInt(5); // Generates an int between 0,4

System.out.println("Computer played - " + comp);

if (outcome[human][comp] == 1) {

System.out.println("You win!");

tie = false;

} else if (outcome[human][comp] == -1) {

System.out.println("Sorry you lose");

tie = false;

} else

System.out.println("Its a tie. Play again");

}

}


}

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote