package project;

import java.util.Random;

public class TicTacToe
{

    private Board board = new Board();
    Player players[]= new Player[2];
    Player currentPlayer = null;
    Player winner = null;

    public void start() {

        initializePlayer1();
        initializePlayer2();

        getFirstPlayer();

        while((winner == null) && !board.isFull()) {
            announcePlayerTurn();
            Turn turn = currentPlayer.getTurn();
            if(board.isValidTurn(turn)){
                board.set(currentPlayer.getSign(), turn);
                board.display();
                if(board.hasWinner()){
                    winner = currentPlayer;
                } else {
                    currentPlayer = getNextPlayer();
                }
            } else {
                logInvalidTurn(turn);
            }
        }
        if(hasWinner()) {
            announceWinner();
        } else {
            announceDraw();
        }

    }

    private void getFirstPlayer() {
        Random random = new Random();
        currentPlayer = random.nextBoolean() ? players[0] : players[1];
        System.out.format("%s is the first player.\n", currentPlayer.getName());
    }

    private void initializePlayer2() {
        Player p2 = new Player();
        p2.setStrategy(new HumanInputStrategy());
        p2.setSign('X');
        p2.setName("Player 2");
        players[1] = p2;
    }

    private void initializePlayer1() {
        Player p1 = new Player();
        p1.setStrategy(new HumanInputStrategy());
        p1.setSign('O');
        p1.setName("Player 1");
        players[0] = p1;
    }

    private void announcePlayerTurn() {
        System.out.format("It is %s's turn.\n", currentPlayer.getName());
    }

    private void logInvalidTurn(Turn turn) {
        System.out.format("Invalid input: %d %d\n", turn.row, turn.column);
    }

    private void announceWinner() {
        System.out.format("Winner is %s.\n", winner.getName());
    }

    private void announceDraw() {
        System.out.println("It's a draw.");
    }

    private boolean hasWinner() {
        return winner != null;
    }

    public Player getNextPlayer() {
        return currentPlayer == players[0] ? players[1] : players[0];
    }
}

@@ -1228,17 +1228,17 @@
 zePlayer
-2
+1
 () %7B%0A   
@@ -1250,17 +1250,17 @@
 Player p
-2
+1
  = new P
@@ -1273,25 +1273,25 @@
 );%0A        p
-2
+1
 .setStrategy
@@ -1323,25 +1323,25 @@
 );%0A        p
-2
+1
 .setSign('X'
@@ -1342,9 +1342,9 @@
 gn('
-X
+O
 ');%0A
@@ -1352,17 +1352,17 @@
        p
-2
+1
 .setName
@@ -1370,17 +1370,17 @@
 %22Player 
-2
+1
 %22);%0A    
@@ -1395,15 +1395,15 @@
 ers%5B
-1
+0
 %5D = p
-2
+1
 ;%0A  
@@ -1432,33 +1432,33 @@
 initializePlayer
-1
+2
 () %7B%0A        Pla
@@ -1454,33 +1454,33 @@
         Player p
-1
+2
  = new Player();
@@ -1481,33 +1481,33 @@
 yer();%0A        p
-1
+2
 .setStrategy(new
@@ -1499,37 +1499,40 @@
 setStrategy(new 
-Human
+Computer
 InputStrategy())
@@ -1521,32 +1521,37 @@
 erInputStrategy(
+board
 ));%0A        p1.s
@@ -1539,33 +1539,33 @@
 ard));%0A        p
-1
+2
 .setSign('O');%0A 
@@ -1550,33 +1550,33 @@
     p2.setSign('
-O
+X
 ');%0A        p1.s
@@ -1564,33 +1564,33 @@
 ('X');%0A        p
-1
+2
 .setName(%22Player
@@ -1579,32 +1579,32 @@
 p2.setName(%22
-Player 1
+Computer
 %22);%0A        
@@ -1603,39 +1603,39 @@
         players%5B
-0
+1
 %5D = p
-1
+2
 ;%0A    %7D%0A%0A    pri
@@ -1619,32 +1619,33 @@
 1%5D = p2;%0A    %7D%0A%0A
+%0A
     private void

remove some functions