// Arup Guha
// 1/25/2012
// Allows the user to play Rock, Paper, Scissors against the computer.

import java.util.*;

public class RPS {

	// Constants for the length of the competition and the options to play.
	public final static int NUMWINS = 10;
	public final static String[] OPTIONS = {"rock","paper","scissors"};

	public static void main(String[] args) {

		Random r = new Random();

		int humanScore = 0;
		int compScore = 0;

		// Continue until one team has enough wins to win the series.
		while (humanScore < NUMWINS && compScore < NUMWINS) {

			// Play the game.
			int result = playGame(r);

			// Output and tally the result.
			if (result == 0) {
				System.out.println("You tied this game.");
			}
			else if (result == 1) {
				System.out.println("Congrats, you won this game!");
				humanScore++;
			}
			else {
				System.out.println("Sorry, the computer beat you.");
				compScore++;
			}

		}

		// Print out an appropriate concluding message.
		if (compScore == NUMWINS) {
			System.out.println("Sorry, the computer beat you "+compScore+" to "+humanScore+".");
		}
		else {
			System.out.println("Congrats, you beat the computer "+humanScore+" to "+compScore+".");
		}
	}

	// Plays one game and returns the status of that game.
	// 0 = tie, 1 = human win, 2 = computer win.
	public static int playGame(Random r) {

		Scanner stdin = new Scanner(System.in);

		System.out.println("What will you play (rock, paper, or scissors)?");
		String humanMove = stdin.next();
		String compMove = getCompMove(r);

		System.out.println("The computer plays "+compMove+".");
		return getResult(humanMove, compMove);
	}

	// Returns 0 if the two teams tie, 1 if move1 wins, and 2 otherwise.
	public static int getResult(String move1, String move2) {

		// Tie game when both play the same thing.
		if (move1.compareTo(move2) == 0)
			return 0;

		// Go through the other six cases individually and return
		// the appropriate outcome.
		if (move1.equals("rock")) {
			if (move2.equals("scissors"))
				return 1;
			return 2;
		}
		else if (move1.equals("paper")) {
			if (move2.equals("rock"))
				return 1;
			return 2;
		}
		else {
			if (move2.equals("paper"))
				return 1;
			return 2;
		}

	}

	// The computer move just returns a random move.
	public static String getCompMove(Random r) {
		int choice = r.nextInt(3);
		return OPTIONS[choice];
	}
}