/* 
 * Racquetball/Volleyball Simulation:  
 *    Test framework for a method, playUntilWin, that plays one game
 *       In this file, the body of playUntilWin is just a stub
 *    Serve-by-Serve Recursive Approach
 * Copyright(c) 2011 by Henry M. Walker
 *
 * This code is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * @author Henry M. Walker
 */

// The Math library is needed for its random() function
import java.lang.Math;

// The java.io library is needed for reading from the keyboard
import java.io.*;

public class Game1TestStub {
    public boolean winByTwo; // true for volleyball; false for racquetball

    /**
     * Constructor specifies whether players of the game 
     * must win by 2 or 1, depending whether String simGame is
     * volleyball or racquetball, respectively.
     */
    public Game1TestStub (String simGame)
    {
	winByTwo = simGame.equals("volleyball");
        System.out.println ("  Win by two:  " + winByTwo);
    }

    /**
     * Play one game of racquetball or volleyball to conclusion
     * @parms  server and receiver indicate the team "A" or "B"
     *         probWinVolley specifies the likelihood the server wins a volley
     *         serverScore, recScore contain current score of
     *             server and receiver
     * @returns winner of game: either "A" or "B"
     */
    public String playUntilWin (String server, String receiver,
				       double probWinVolley, 
				       int serverScore, int recScore) 
    {
        // in stub, A always wins
        return "A";
    }

    public static void main (String [] args)
    {
        System.out.println ("Program to simulate five game of racquetball or volleyball");

        // The approach shown here reads test cases from the terminal
        // Alternatively, these parameters could be hard-coded in the program
        System.out.print ("Enter 'racquetball' or 'volleyball':  ");

        // read type of game
        String string = "";
        InputStreamReader input = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader (input);
        try 
            {
                string = reader.readLine();
            }
        catch (Exception e) {}

        // Create game object
        Game1TestStub game = new Game1TestStub (string);

        // read probability of A winning a volley
        System.out.print ("Enter probability of team A winning volley [0..1]:  ");
        try 
            {
                string = reader.readLine();
            }
        catch (Exception e) {}

        double prob = new Double(string).doubleValue();
        System.out.println ("Probability used in simulation:  " + prob);

        System.out.println ("Winners of 5 games");
        System.out.println ("  1:  " + game.playUntilWin("A", "B", prob, 0, 0));
        System.out.println ("  2:  " + game.playUntilWin("A", "B", prob, 0, 0));
        System.out.println ("  3:  " + game.playUntilWin("A", "B", prob, 0, 0));
        System.out.println ("  4:  " + game.playUntilWin("A", "B", prob, 0, 0));
        System.out.println ("  5:  " + game.playUntilWin("A", "B", prob, 0, 0));
    }	
}
