import java.util.Random;
import java.lang.Math;
import java.io.*;

class GuessingGame {

    public static void main(String argv[]) throws IOException {
	
	BufferedReader stdin = new BufferedReader
	    (new InputStreamReader(System.in));
	Random x = new Random();
	int secretnumber = Math.abs(x.nextInt()) % 100;

	int guess = 0; // Keeps track of current guess
	int low = 1; // Computer uses this variable to make next guess
	int high = 100; // Computer uses this variable to make next guess

	System.out.println("Would you like to (p)lay or watch the (c)omputer play?");
	char ans = (stdin.readLine()).charAt(0);
	if (ans != 'p' && ans != 'c')
	    ans = 'c';

	// Loops until correct number is guessed.
	while (secretnumber != guess) {

	    guess = getGuess(ans, low, high); // Gets guess from either
user or computer.

	    // Prints out appropriate message based on number guessed.
	    if (guess > secretnumber) {
		System.out.println("Sorry, your guess is too high, try again.");
		if (ans == 'c')
		    high = guess;
	    }
            else if (guess < secretnumber) {
		System.out.println("Sorry, your guess is too low, try again.");
		if (ans == 'c')
		    low = guess;
	    }
	}

	System.out.println("Congrats, you guessed the correct number, "+secretnumber);

    }

    // Method that gets the next guess. The parameters it takes are player,
    // a character that is either c or p, indicating either a computer player,
    // or a human player, low and high. low is the low bound for the secret
    // number and high is the high bound for the secret number. Both values
    // are used to formulate the computer's guess. The method returns the
    // next guess.
    static int getGuess(char player, int low, int high) throws IOException {

	BufferedReader stdin = new BufferedReader
	    (new InputStreamReader(System.in));
	int guess = 0;

	if (player == 'p') {
	    System.out.println("Enter your guess in between 1 and 100.");
	    guess = Integer.parseInt(stdin.readLine());
	}
	else {
	    guess = (high + low)/2;
	    System.out.println("The computer\'s guess is "+guess);
	}
	return guess;
    }
}
