// Arup Guha
// 6/6/2016
// Solution for Part B SI@UCF Program: High Card

import java.util.*;

public class HighCardB {
	
	public static void main(String[] args) {
		
		Random r = new Random();
		Scanner stdin = new Scanner(System.in);
		
		// Get number of rounds.
		System.out.println("How many rounds will you play?");
		int numRounds = stdin.nextInt();
		
		// Initialize these for the first round.
		int p1Cards = 2, p2Cards = 2;
		int p1Score = 0, p2Score = 0;
		
		// Get rounds
		for (int loop=0; loop<numRounds; loop++) {
		
			// Create all card objects - I just always generate 2, but I'll only use one if you only have one.
			Card p1Card1 = new Card(r);
			Card p1Card2 = new Card(r);
			Card p2Card1 = new Card(r);
			Card p2Card2 = new Card(r);
		
			// Print out cards.
			System.out.print("Player 1, your card(s): "+p1Card1);
			if (p1Cards == 2) System.out.print(" "+p1Card2);
			System.out.println();
			System.out.print("Player 2, your card(s): "+p2Card1);
			if (p2Cards == 2) System.out.print(" "+p2Card2);
			System.out.println();			
		
			// Assign best card for player 1.
			Card p1Best = p1Card1;
			if (p1Card2.beats(p1Best) && p1Cards == 2)
				p1Best = p1Card2;
			
			// Assign best card for player 2.
			Card p2Best = p2Card1;
			if (p2Card2.beats(p2Best) && p2Cards == 2)
				p2Best = p2Card2;
			
			// Check tie case first!
			if (p1Best.equals(p2Best)) {
				System.out.println("Player 1 and Player 2 tie!");
				p1Cards = 2;
				p2Cards = 2;
			}
			
			// Here Player 1 wins.
			else if (p1Best.beats(p2Best)) {
				System.out.println("Player 1, you win!");
				p1Cards = 2;
				p2Cards = 1;
				p1Score++;
			}
			
			// Must be Player 2 if we get here.
			else {
				System.out.println("Player 2, you win!");
				p1Cards = 1;
				p2Cards = 2;
				p2Score++;
			}
			
			// For readability.
			System.out.println();
			
		} // end for(rounds).
		
		// Output final result.
		if (p1Score > p2Score)
			System.out.println("Player 1 wins by a score of "+p1Score+"-"+p2Score);
		else if (p2Score > p1Score)
			System.out.println("Player 2 wins by a score of "+p2Score+"-"+p1Score);
		else
			System.out.println("Player 1 and Player 2 tie, each with "+p1Score+" points.");
	}
}