// Analysis.java
// [comment block]

import java.io.*;

public class Analysis
{
    static final int MAXHANDS = 500;

    // main method:
    // This method should create a lot of bridge hands and sort them.
    // Essentially, we want to see what happens as the number of
    // hands to be sorted varies.  So we try sorting 10
    // hands, 20 hands, 30 hands, etc. up to MAXHANDS hands.
    // For each test, we need to deal out the required number
    // of BridgeHands; remember that after four hands, the deck
    // has been used up and needs to be shuffle()d.  
    //
    // Code to do an experiments with 10 hands using insertionSort 
    // has already been written here.
    // You should modify this code so that 
    // 1. It tests 10, 20, 30... up to MAXHANDS hands.
    //    (Hint: store the number of comps required for each number
    //     of hands in an int array, then write them all out 
    //     in a loop in the try block)
    // 2. It does similar experiments with selectionSort and bubbleSort, 
    //    writing them out to different files. 
    //
    public static void main(String[] args)
    {
	DeckOfCards d = new DeckOfCards();
	int numComps;

	BridgeHand[] b = new BridgeHand[10];
	Card[] h = new Card[BridgeHand.CARDSINHAND];
	d.shuffle();
	// Deal 10 hands
	for (int j=0; j<10; j++)
	{
	    // Get a hand of cards
	    for (int k=0; k<BridgeHand.CARDSINHAND; k++)  h[k] = d.deal();
	    b[j] = new BridgeHand(h);
	    // each time we've done four, reshuffle
	    if ((j+1)%4 == 0) d.shuffle();
	}
	// Now sort them.
	int c = Sorting.insertionSort(b);
	// You can comment this out if you like.
	System.out.println("10 hands: " + c + " comparisons."); 
	numComps = c;

	// Write the experiment results out to a file.
	try
	{
	    PrintWriter p = new PrintWriter(new FileOutputStream("insertion-comps.txt"));
	    p.println(10 + "\t" + numComps);
	    p.close();
	}
	catch (IOException e)
	{
	    System.out.println("Error writing to file.");
	    
	}
    }
}
