import java.util.Arrays;
import java.util.Collections;


public class PlaysCards {

	public static void main(String[] args) {

        Deck d1 = new Deck();
        d1.shuffle();
        Hand h1 = new Hand();
        Hand h2 = new Hand();
        WarPile w = new WarPile();
        
        // initial deal
        while (d1.hasCards()){
           Card c1 = d1.dealOne();
           h1.addCard(c1);
        
           Card c2 = d1.dealOne();
           h2.addCard(c2);
        }
        
        /*System.out.println("Player 1: ");
        h1.show();
        System.out.println("Player 2: ");
        h2.show();
        */
        
        Card c1, c2;
		while (h1.hasCards() && h2.hasCards()) {
			do {
				c1 = h1.playOne();
				c2 = h2.playOne();
				w.addTo(c1);
				w.addTo(c2);

				System.out.print(c1 + ":" + c2);
				if (c1.compareTo(c2) < 0) {
					System.out.println(" Player 2 wins");
					h2.addWarPile(w);
				} else if (c1.compareTo(c2) > 0) {
					System.out.println(" Player 1 wins");
					h1.addWarPile(w);
				} else
					System.out.println(" WAR!");
			} while (c1.compareTo(c2) == 0);
		}
		
		if (h1.hasCards())
			System.out.println(" Player 1 wins the WAR!!!");
		else
		    System.out.println(" Player 2 wins the WAR!!!");

        //d1.show();

	}

}
