package tictactoe;

import game.CharBoard;
import game.Coordinate;
import game.PieceType;

/**
 * This class creates a 2d array of squares and keeps track of the piece
 * locations, win conditions, and text display.
 */
public class TicTacToeBoard extends CharBoard {

	/**
	 * This constructor initializes the board of a Tic-Tac-Toe game.
	 */
	public TicTacToeBoard() {
		super(3);
	}

	/**
	 * This method verifies that a piece can be placed on this square. For
	 * TicTacToe, this only involves checking if the coordinate is empty.
	 * 
	 * @param piece
	 *            the piece that will be checked
	 * @param c
	 *            the coordinates the piece will be checked on
	 * @return if the piece can be placed on the coordinate
	 */
	@Override
	public boolean canPlace(PieceType piece, Coordinate c) {
		return isEmpty(c);
	}
	
	/**
	 * This method has the AI determine its move and return the corresponding square the move is located on.
	 * 
	 * @return the ai will place a piece on this square
	 */
	private Coordinate getAIMove() {
		// find winning lines
		// count number of pieces in each line
		// end one turn victories
		// randomly place the piece
		// lines 1-3 are columns, lines 4-6 are rows, lines 7 and 8 are diagonals

		return new Coordinate(0, 0);
	}

	/**
	 * This method checks if there are 3 pieces in a row and returns an exit
	 * character if there are 3 pieces in a row. Otherwise, it checks if there
	 * is an empty square. If there is an empty square, continue the game.
	 * Otherwise, end the game as a tie.
	 */
	@Override
	public char gameEnd() {
		char[][] tempBoard = getBoard();

		// check rows
		for (int i = 0; i < tempBoard.length; i++)
			if (tempBoard[i][0] == tempBoard[i][1] && tempBoard[i][1] == tempBoard[i][2])
				return tempBoard[i][0];

		// check columns
		for (int j = 0; j < tempBoard[0].length; j++)
			if (tempBoard[0][j] == tempBoard[1][j] && tempBoard[1][j] == tempBoard[2][j])
				return tempBoard[0][j];

		// check diagonals
		if (tempBoard[0][0] == tempBoard[1][1] && tempBoard[1][1] == tempBoard[2][2])
			return tempBoard[1][1];
		if (tempBoard[2][0] == tempBoard[1][1] && tempBoard[1][1] == tempBoard[0][2])
			return tempBoard[1][1];

		for (int i = 0; i < tempBoard.length; i++)
			for (int j = 0; j < tempBoard[i].length; j++)
				if (tempBoard[i][j] == ' ')
					return ' ';

		return '_';
	}

}
@@ -861,467 +861,8 @@
 %0A%09%7D%0D
-%0A%09%0D%0A%09/**%0D%0A%09 * This method has the AI determine its move and return the corresponding square the move is located on.%0D%0A%09 * %0D%0A%09 * @return the ai will place a piece on this square%0D%0A%09 */%0D%0A%09private Coordinate getAIMove() %7B%0D%0A%09%09// find winning lines%0D%0A%09%09// count number of pieces in each line%0D%0A%09%09// end one turn victories%0D%0A%09%09// randomly place the piece%0D%0A%09%09// lines 1-3 are columns, lines 4-6 are rows, lines 7 and 8 are diagonals%0D%0A%0D%0A%09%09return new Coordinate(0, 0);%0D%0A%09%7D%0D
 %0A%0D%0A%09

remove duplicate method in TicTacToeBoard