/*
    A game of tic-tac-toe in Java.

    Let's move quickly over difficult terrain.
*/

import java.io.*;
import java.util.*;
import java.lang.*;


class TicTacToeGame {
    public static void main(String[] args) {
        Player player1 = new Player("Player 1", 'X');
        Player player2 = new Player("Player 2", 'O');

        boolean playerStarts = humanPlayerStarts();
        if (playerStarts) {
            System.out.println("You go first.");
        } else {
            System.out.println("Machine goes first.");
        }

        Board board = new Board(player1, player2);
        board.print();

        while(true) {
            player1.makeMove(board);
            board.print();
            if (board.isWon()) {
                board.winMessage();
                break;
            }

            player2.makeMove(board);
            board.print();
            if (board.isWon()) {
                board.winMessage();
                break;
            }

            break;
        }
    }

    private static boolean humanPlayerStarts() {
        Random rand = new Random(); 
        int value = rand.nextInt(2);

        if (value == 1) {
            return true;
        } else {
            return false;
        }
    }
}

class Player {
    private String name;
    private char token;
    private boolean isHuman;

    Player(String name, char token) {
        this.name = name;
        this.token = token;
        this.isHuman = true;
    }

    public String getName() {
        return name;
    }

    public char getToken() {
        return token;
    }

    public void makeMove(Board board) {
        board.update(token, 0);
    }
}

class Board {
    private Player player1;
    private Player player2;

    BoardSpace[] spaces = new BoardSpace[9];

    Board(Player player1, Player player2) {
        this.player1 = player1;
        this.player2 = player2;

        for (int i=0; i < spaces.length; i++) {
            spaces[i] = new BoardSpace();
        }
    }

    public void update(char token, int move) {

    }

    public boolean isWon() {
        return true;
    }

    public void print() {

        // Example:
        //    |   |
        //  X | X | X
        // -------------
        //  X | X | X
        // -------------
        //  X | X | X 
        //    |   |

        String out = "\n"
        + "        |   |    \n"
        + "      " + spaces[0] + " | " + spaces[1] + " | " + spaces[2] + "  \n"
        + "    -------------\n" 
        + "      " + spaces[3] + " | " + spaces[4] + " | " + spaces[5] + "  \n"
        + "    -------------\n"
        + "      " + spaces[6] + " | " + spaces[7] + " | " + spaces[8] + "  \n"
        + "        |   |    \n"
        + "                 \n";

        System.out.print(out);
    }

    public void winMessage() {
        System.out.println("Nobody wins!");
    }
}

class BoardSpace {
    private char token;

    BoardSpace() {
        token = ' ';
    }

    public String toString() {
        return Character.toString(token);
    }
}

@@ -257,16 +257,37 @@
 ayer 1%22,
+ BoardState.PLAYER_1,
  'X');%0A 
@@ -332,16 +332,37 @@
 ayer 2%22,
+ BoardState.PLAYER_2,
  'O');%0A%0A
@@ -1014,28 +1014,8 @@
    %7D
-%0A%0A            break;
 %0A   
@@ -1261,24 +1261,85 @@
  %7D%0A    %7D%0A%7D%0A%0A
+/**%0A * A player entity. May be the user or the computer.%0A */%0A
 class Player
@@ -1362,24 +1362,54 @@
 tring name;%0A
+    private BoardState state;%0A
     private 
@@ -1473,16 +1473,34 @@
 ng name,
+ BoardState state,
  char to
@@ -1528,24 +1528,52 @@
 ame = name;%0A
+        this.state = state;%0A
         this
@@ -1674,32 +1674,96 @@
 rn name;%0A    %7D%0A%0A
+    public BoardState getState() %7B%0A        return state;%0A    %7D%0A%0A
     public char 
@@ -1848,48 +1848,275 @@
 ) %7B%0A
-        board.update(token, 0);%0A    %7D%0A%7D%0A
+%0A        System.out.print(name + %22's move: %22);%0A%0A        if (isHuman) %7B%0A            Scanner scan = new Scanner(System.in);%0A            int position = scan.nextInt() - 1;%0A            board.update(this, position);%0A        %7D%0A    %7D%0A%7D%0A%0A/**%0A * The tic-tac-toe game board%0A */
 %0Acla
@@ -2472,32 +2472,111 @@
 ate(
-char token, int move) %7B%0A
+Player player, int position) %7B%0A        spaces%5Bposition%5D.setSpace(player.getState(), player.getToken());
 %0A   
@@ -3396,176 +3396,531 @@
 %0A%7D%0A%0A
-class BoardSpace %7B%0A    private char token;%0A%0A    BoardSpace() %7B%0A        token = ' ';%0A    %7D%0A%0A    public String toString() %7B%0A        return Character.toString(token);%0A    %7D%0A%7D%0A
+/**%0A * One of the nine spaces on the tic-tac-toe board%0A */%0Aclass BoardSpace %7B%0A%0A    private BoardState state;%0A    private char token;%0A%0A    BoardSpace() %7B%0A        token = ' ';%0A    %7D%0A%0A    public void setSpace(BoardState state, char token) %7B%0A        this.state = state;%0A        this.token = token;%0A    %7D%0A%0A    public String toString() %7B%0A        return Character.toString(token);%0A    %7D%0A%7D%0A%0A/**%0A * Status of a space on the board. Available, taken by Player 1, or taken by Player 2.%0A */%0Aenum BoardState %7B%0A    EMPTY, PLAYER_1, PLAYER_2%0A%7D

Read in user inputs and update the board state