import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import matchingpennies.Coin;

import agents.base.BaseWrapper;

public class TestProgram extends BaseWrapper {
	public TestProgram() {
		
	}
	
	private static void write_out(String CurLine) {
		System.out.println(CurLine);
	}
	
	public static void main(String args[]) {
		String current_line = ""; // Line read from standard in
		
		write_out("# Play the Matching Pennies game.");
		write_out("# Type H for HEADS, T for TAILS, Q to quit.");
		
		InputStreamReader converter = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(converter);
		
		do {
			Coin current = null;
			do {
				try {
					// write_out("TestProgram:before_read_line");
					current_line = in.readLine();
					// write_out("TestProgram:after_read_line");
				} catch (IOException e) {
					e.printStackTrace();
				}
				
				if (current_line.startsWith("Q")) {
					return;
				}
				
				if (current_line.startsWith("H")) {
					current = Coin.HEADS;
				} else if (current_line.startsWith("T")) {
					current = Coin.TAILS;
				}
			} while (current == null);
			
			Coin me = Coin.random();
			boolean match = match(me, current);
			
			write_out(me + " - Test - You: " + current + ". Me: " + me + ". " + (match ? "Match!" : "Mismatch!"));
		} while (true);
	}

	private static boolean match(Coin one, Coin two) {
	  return one == two;
  }
}
