import java.util.ArrayList;
import java.io.*;

/**
 * Yet another use of the clobberboard class. This one takes
 * user input for all moves
 * 
 * In the main class thre are several options
 * <ul>
 * <li> String -- the name of a file holding a clobber board
 * <li> int int -- the size of a checkerboard clober board
 * <li> int int boolean -- the first two are the size of a clobberboard  
 * The thrid, if false, gives a checkerboard.  If true, it gives a random board
 * </ul>
 * @author gtowell
 *
 */
public class Clobber3
{

	/**
	 * @param args
	 */
	public static void main ( String[] args )
	{
		ClobberBoard cb=null;
		int xsiz=3;
		int ysiz=2;
		boolean rnd=false;
		if (args.length==0)
		{
				// do nothing
		}
		if (args.length==1)
			cb=new ClobberBoard(args[1]);
		if (args.length>1)
		{
			try
			{
				xsiz=Integer.parseInt(args[0]);
				ysiz=Integer.parseInt(args[1]);
			}
			catch (Exception ee)
			{
				System.err.println("Could not translate an arg into a board size");
			}
			if (args.length>=3)
			{
				try
				{
					rnd=(args[2].toLowerCase().indexOf("t")==0);
				}
				catch (Exception ee)
				{
					System.err.println("Could not translate an arg into a booolean goin with false");
				}
			}
		}
		cb=new ClobberBoard(xsiz, ysiz, rnd);
		char[] wb = {'w', 'b'};
		boolean keepGoing=true;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (keepGoing)
		{
			for (int i=0; i<wb.length; i++)
			{
				System.out.println(cb);
				System.out.println("Enter a move for " + wb[i]);
				try
				{
					ArrayList<Amove> am = cb.legalMoves(wb[i]);
					if (am.size()==0)
					{
						keepGoing=false;
						System.out.println(wb[i] + " lost");
						System.out.println(cb);
					}
					else
					{
						Amove aa = new Amove(br.readLine());
						cb.makeMove(aa);
					}
				}
				catch (Exception ee)
				{
				}
			}
		}

	}

}
