// Arup Guha
// 7/26/2011
// Connect Four Shell
// Written in BHCSI class
import java.util.*;

public class confour {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		char[][] board = new char[6][7];

		// Starting conditions.
		initBoard(board, '_');
		char piece = 'X';
		int numMoves = 0;

		/* Need to change this part of main to run until someone wins or 
		 * the board is full
		 */
		while (numMoves < 10) {

			// Get the move.
			print(board);
			System.out.println("Where do you want to move(0-6)?");
			int col = stdin.nextInt();

			// Place the move.
			move(board, piece, col);

			// Update for next turn.
			piece = change(piece);
			numMoves++;
		}
	}

	// Return the other player's piece.
	public static char change(char piece) {
			if (piece == 'X')
				return 'O';3
			else
				return 'X';
	}

	public static void initBoard(char[][] board, char piece) {

		// Put piece in each square of the board.
		for (int row=0; row<board.length; row++) {
			for (int col=0; col<board[0].length; col++) {
				board[row][col] = piece;
			}
		}
	}

	// Executes a move with piece in the designated column with no error checking.
	public static void move(char[][] board, char piece, int column) {

		// Start at bottom row.
		int row = 5;

		// Search for first blank spot, from bottom.
		while (board[row][column] != '_')
			row--;

		// Place the piece.
		board[row][column] = piece;

	}

	// Prints out the board.
	public static void print(char[][] table) {

		// Print out the table.
		for (int row=0; row<table.length; row++) {

			// Prints one row.
			for (int col=0; col<table[0].length; col++) {
				System.out.print(table[row][col] + "\t");
			}

			// Go to the next line.
			System.out.println();
		}

	}

	// Checks the rows to see if the team with piece has won
	// on a row.
	public static boolean checkRows(char[][] board, char piece) {

		// Loop through each row.
		for (int row=board.length-1; row>=0; row--) {

			// Loop through each valid starting column.

				// Check the necessary four squares.
		}

		// This team has yet to win.
		return false;
	}

	// Checks the rows to see if the team with piece has won
	// on a row.
	public static boolean checkCols(char[][] board, char piece) {

		// Loop through each column.
		for (int col=0; col<board[0].length; col++) {

			// Loop through each valid starting row.

				// Check the necessary four squares.
		}

		// This team has yet to win.
		return false;
	}

	// Checks diagonals starting at (5,0) through (3,3) that are "forward".
	// The forward diagonal at (5,0) consists of (4,1), (3,2) and (2,3) as well.
	public static boolean checkForwardDiags(char[][] board, char piece) {

		for (int row=board.length-1; row>=3; row--) {
			for (int col=0; col<board.length-4; col++) {

				// Check the diagonal starting at (row, col) and ending at (row-3, col+3).

			}
		}

	}

	// Checks diagonals starting at (5,6) through (3,3) that are "forward".
	// The backward diagonal at (5,6) consists of (4,5), (3,4) and (2,3) as well.
	public static boolean checkBackDiags(char[][] board, char piece) {

		for (int row=board.length-1; row>=3; row--) {
			for (int col=board[0].length; col>=3; col--) {

				// Check the diagonal starting at (row, col) and ending at (row-3, col-3).

			}
		}
	}
	
	// Returns true if piece has won the game in board, and false otherwise.
	public static boolean didWin(char[][] board, char piece) {
		
		// Separately check rows, columns, forward diagonals and backward diagonals
		// and return the appropriate answer.
	}

}