/**
 * Creates a strategy using random guesses at the average value of
 * each category, applies that strategy to the give number of games,
 * and displays the average score.
 *
 * @author Jim Glenn
 * @version 0.1 3/22/2005
 */

public class StrategyMaker
{
    public static void main(String[] args)
    {
	// read number of games from comamnd line

	if (args.length < 1)
	    {
		System.out.println("USAGE: java StrategyMaker num-games");
		System.exit(1);
	    }

	int games = Integer.parseInt(args[0]);

	if (games < 1)
	    {
		System.out.println("USAGE: java StrategyMaker num-games");
		System.out.println("\t where num-games is at least 1");
		System.exit(1);
	    }

	// create the start state of the game

	YahtzeeState start = new BonusYahtzeeState();

	// create an array containing, for each category, a random
	// number from 0...max score for that category

	double[] values = new double[start.countCategories()];
	for (int c = 0; c < values.length; c++)
	    values[c] = Math.random() * start.getMaximumScore(c);

	// display the values

	System.out.println("Playing " + games + " games using a strategy based on the following values");
	for (int c = 0; c < values.length; c++)
	    System.out.println(start.getCategoryName(c) + ": " + values[c]);

	// create the strategy

	YahtzeeStrategy strat = new CategoryValueHeuristicStrategy(values);

	// apply the strategy to some games

	int totalScore = 0;
	for (int g = 0; g < games; g++)
	    totalScore += YahtzeeSimulator.simulateGame(start, strat);

	System.out.println("AVERAGE = " + (double)totalScore / games);
		
    }
}
