import java.io.*;

public class TTTTextDriver {

  private static final char PLAYER_ONE = 'X';
  private static final char PLAYER_TWO = 'O';
  
  /**
   * A java application is a set of one or more classes
   * with (at least) one main method.
   * 
   * To start executing the program, the system 
   * executes the main method.
   */ 
  public static void main(String[] args) throws IOException {  
    TicTacToe t = new TicTacToe();
    
    char currPlayer = PLAYER_ONE;
    
    // System.in is a byte reader. 
    // InputStreamReader converts a byte-reader to a char-reader.
    // BufferReader converts a char-reader to a String-reader, so we can read lines.
    BufferedReader br = 
      new BufferedReader(new InputStreamReader(System.in));
    
    // while it's not a draw and no one has won yet
    while (!t.isDraw() && t.getWinner() == TicTacToe.BLANK_SQUARE) {
      
      // the player makes a move
      System.out.println("Player " + currPlayer + " enter a row:");
      int r = Integer.parseInt(br.readLine());
      
      System.out.println("Player " + currPlayer + " enter a column:");
      int c = Integer.parseInt(br.readLine());
      
      // put the mark on the board
      t.setMark(currPlayer, r, c);
      
      // output the current state of the game
      System.out.println(t.toString());
      
      // switch players
      if (currPlayer == PLAYER_ONE) {
        currPlayer = PLAYER_TWO;
      } else if (currPlayer == PLAYER_TWO) {
        currPlayer = PLAYER_ONE;
      } else {
        System.exit(0);
      }
    }
    
    if (t.getWinner() != TicTacToe.BLANK_SQUARE) { // someone wins
      System.out.println("Player " + t.getWinner() + " won!");
    } else { // it's a draw
      System.out.println("It's a draw!");
    }
    
  }
}