RPS Java
RPS Java
This problem will be a fun application of interfaces. It revolves around the game of Rocks, Paper, Scissors (also known in some parts of the
world as RoShamBo). For those of you who are not familiar with the game, it is played between two people who we will refer to as A and B.
Person A makes a selection of either rock, scissor, or paper with person B being unaware of what A will choose. Similarly, person B will
make a selection of either rock, scissor, or paper with person A being unaware of what B will choose. Then, based on the selection of each, a
winner is decided based on the following selection matrix:
B selects ROCK
B selects PAPER
B selects SCISSOR
A selects ROCK
TIE
B WINS
A WINS
A selects PAPER
A WINS
TIE
B WINS
A selects SCISSOR
B WINS
A WINS
TIE
This can be summarized as “rocks beat scissors” (since a rock can break a pair of scissors), “scissors beat paper” (since scissors can cut
paper), and “paper beats rock” (since paper can cover a rock). Typically, the game is repeated many times so that players can exploit
patterns in their opponents’ playing styles in order to accumulate more wins.
In this exercise, you will be implementing your own strategy for playing this game. Then, I will take every student’s strategy and implement a
tournament to evaluate which strategy is best.
1. Consider the following interface:
import java.util.ArrayList;
public interface RPS_Player {
/**
* integer constant representing the selection rock
*/
static final int ROCK = 0;
/**
* integer constant representing the selection scissor
*/
static final int PAPER = 1;
/**
* integer constant representing the selection paper
*/
static final int SCISSOR = 2;
/**
* method that utilizes an arraylist of an opponent’s previous choices to
* make a selection of whether to play rock, scissor, or paper next.
* @param prev an arraylist of previous selections made by the opponent
* the last entry of this list is the most recent move.
* @return the integer RSP_Player.ROCK, RSP_Player.SCISSOR, or
* RSP_Player.PAPER
*/
Rock Paper scissor