public class TicTacToe {

    private char[][] board;

    public TicTacToe() {
	board = new char[3][3];
	int row;
	int col;
	for (row=0; row<3; row++) {
	    for(col=0; col<3; col++) {
		board[row][col] = '.';
	    }
	}
    }

    // Converts the game into string form.
    public String toString() {
	int row; 
	int col;
	String result = "";

	for (row=0; row<3; row++) {
	    for (col=0; col<3; col++) {
		result = result + board[row][col] + "\t";
	    }
	    result = result + "\n";
	}
	return result;
    }

    // Puts player's mark on the grid location (row,col).
    public void play(int row, int col, char player) {
	if (board[row][col] == '.') {
	    board[row][col] = player;
	}
    }

    // Returns 'X' or 'O' if that player has won; 
    // otherwise returns '.'
    public char winner() {
	int row;
	for(row = 0; row < 3; row++) {
	    if (board[row][0] == board[row][1] 
		&& board[row][0] == board[row][2]) {
		return board[row][0];
	    }
	}


	// and the same thing for columns


	if (board[0][0] == board[1][1] && board[0][0] == board[2][2]) {
	    return board[0][0];
	}


	// and the same thing for the other diagonal
	
	
	return 'X';
    }

    public boolean catsGame() {
	return false; //(winner() == '.') && (the board is full)
    }

}
