import SimpleOutput;
import SimpleInput;
import Piece;
import Board;
import OthelloRules;
import ComputerPlayer;
 
/** This "faux" class represents a textual user interface and is designed 
to work with the above classes. 
*
* @author Amber McNett
* @author Hisako Watanabe
* @author Katt Thorne 
* version 1.1 of February 2000
*/
 
public class TUIsample {
 

// +--------+--------------------------------------------------
  // | Fields |
  // +--------+
 // player 1's name
protected String name;
 
// player 2's name
protected String name2;
 
 
// +------------+----------------------------------------------
  // | Methods |
  // +-------------+


/** This method sets the fields, name and name2, so that they may
 * be employed by the main method. To show that it works, we have also
 * included a little bit of code to tell us each player's name.
 * Computer players are named "Computer" or "Computer 2". */

public void namer(String strg, String strg2) {
     SimpleOutput out = new SimpleOutput();
     this.name = new String(strg);
     this.name2 = new String(strg2);
     out.println("Prompt is a success!");// the following 
                                         // three lines are to show 
                                         // the prompts are a success
     out.println("Player 1 is recorded as " + this.name +  ".");  
     out.println("Player 2 is recorded as " + this.name2 + "."); 
      }

/** This is our "workhorse" method, which will handle most of the
 * interfaces and will interact with the player(s).  It checks to see
 * if the game is over, if not, it checks to see if it is a computer
 * player's turn, or a human player's.  A computer will move automatically
 * as specified by the ComputerPlayer interface.  Rules will end the turn.
 * A human player will be prompted, and the Rules and Board interfaces will 
 * be consulted to a) check legality of the move, b) update the board, 
 * c) end the turn.  If the game *is* over, according to Rules, the winner
 * will be announced and the game will end.
 */

public void run() {
    OthelloRules rules = new OthelloRules();
    ComputerPlayer complay = new ComputerPlayer();
    // not sure what illegal board sizes would be, so including
    // possibility for error message if integers are too large
    // or too small.  Board throws exception if non-integers are
    // used
     out.println("How many rows would you like your board to be?");
     int rows = in.readInt();
     out.println("How many columns would you like your board to be?");
     int columns = in.readInt();
     // makes our board according to specs
     Board b = new Board(rows, columns);
     // sets our board (we made up some make-believe game
     // version, but you get the general idea.)
     out.println("Choose a version of the game, number 1-10");
     // startingPieces should include exceptions, such as non-integers
     // and too big, too small
     int version = in.readInt();
     b.startingPieces(version???); //note that we took some liberty 
                                   // with the parameters
     // starting game loop; if game is not over...
      while (!rules.endOfGame()){ 
     // determine whose turn...
     // note: WE WANT A WHOSE TURN METHOD!!!!!!!!!!
          while (rules.whoseTurn == h) { // assuming h = human 
                                        // and c = computer...
              // while the player has legal moves available
              while (rules.anyMove(player)) {  
                  // note that we're not sure who's keeping track of 
                  // the player, but we're assuming it's Rules and 
                  // that the way the player is stored is also
                  // determined by Rules.
           out.println("Enter the column on the board where you would 
                          like to move:");
               int col = in.readint();
               out.println("Enter the row on the board where you would 
                           like to move:"); 
               int row = in.readint();
           // determines if the move is legal, also assuming
           // rules produces results if *NOT* legal...
             while rules.legalMove(player, col, row);
          } // while (rules.anyMove)
          b.putPiece(this.col, this.row);
          b.updatePiece();
          b.updateBoard(); // if this is not a current method, 
                           // it should be!
          rules.nextTurn;  // changes turn: WE NEED THIS METHOD!
           } // rules (whoseturn == h)
    complay();
    b.update(); // if necessary...
    rules.nextTurn;  //changes turn
       } // while (!endgame)
             
// Otherwise, prints out winner of game -- RULES needs WINNER method.   
out.println("The winner is: " + rules.winner + "!  Congratulations," + 
             rules.winner + "!");
out.println("Thanks for playing!");
//possibility in the future for a "Would you like to play again?" prompt.
  } // run
    
 
/** This is the main method which will begin the program and let it know 
 * how many human players will be playing. 
 * It will also employ the run method, which will bear the brunt of
 * the work (see above). 
 */

public static void main(String[] args) {
    SimpleOutput out = new SimpleOutput();
    SimpleInput in = new SimpleInput();
    TUISample othtui = new TUISample();
    // OthelloTUI othtui = new OthelloTUI(); line will be added in real code
    int playnum;
    out.println("Welcome to CS152 Othello, version 1.0!");
    out.println(" How many human players will be playing today?");
    playnum = in.readInt();
      while  (playnum > 2 || playnum < 0) {
           out.println("Invalid number.  Please enter again.");
           playnum = in.readInt();
         }
         if (playnum == 0) {
            tuitp.namer("Computer 1", "Computer 2");
            othtui.run();
          }
      else if (playnum == 1) {
          out.println("Please enter your name: ");
          tuitp.namer(in.readString(), "Computer");
          othtui.run();    
      }
      else {
          out.println("Please enter your name, player one: "); 
          String play1 = in.readString();
          out.println("Please enter your name, player two: "); 
          String play2 = in.readString();
          tuitp.namer(play1, play2);
          othtui.run();
         } 
  } // main
    // OthelloTUI