/*
    Owen Sullivan
 */

package cpsc2150.extendedConnectX.models;

/**
 * Keep track of an individual cell for a board.
 * <p>This class keeps row and column information for a single cell on the game board
 * and provides methods to get the row and column numbers.</p>
 *
 * @author Owen Sullivan
 * @version 1.0
 *
 * @invariant 0 {@code >=} row {@code <} MAX_ROWS AND 0 {@code >=} column {@code <} MAX_COLUMNS
 */
public class BoardPosition {

    public static final int MAX_ROWS = 9;
    public static final int MAX_COLUMNS = 7;

    private int row;
    private int column;

    /**
     * Constructor for BoardPosition that takes integers
     * for row and column.
     *
     * @param Row number corresponding to row
     * @param Column number corresponding to column
     *
     * @pre
     *      0 {@code >=} Row {@code <} MAX_ROWS AND 0 {@code >=} Column {@code <} MAX_COLUMNS
     *
     * @post
     *      row = Row AND column = Column
     */
    public BoardPosition(int Row, int Column) {

        row = Row;
        column = Column;

    }

    /**
     * Overloaded equals method for BoardPosition.
     *
     * @param o Object to check if equal to
     * @return Whether two BoardPosition objects are equal
     *
     * @post
     *      equals = true iff ((BoardPosition) o = this) AND row = #row AND column = #column
     *      equals = false iff ((BoardPosition) o != this) AND row = #row AND column = #column
     */
    @Override
    public boolean equals(Object o) {

        // If object o is being compared with itself, return true
        if (o == this) {

            return true;

            // If object o is not type BoardPosition, return false
        } else if (!(o instanceof BoardPosition)) {

            return false;

        }

        // Typecast object o to type BoardPosition
        BoardPosition pos = (BoardPosition) o;

        // If rows and columns between the two objects are equal, return true
        if (pos.row == this.row && pos.column == this.column) {

            return true;

            // Otherwise, return false
        } else {

            return false;

        }

    }

    /**
     * Overloaded toString method for BoardPosition.
     * <p><b>NOTE:</b> The string will change depending on the values of the BoardPosition
     * object that calls the toString method, and thus the post-condition for this method 
     * is partially informal.</p>
     *
     * @return A string in the format "<row>,<column>"
     *
     * @post
     *      [toString is formatted like "<row>,<column>"] AND row = #row AND column = #column
     */
    @Override
    public String toString() {

        return (row + "," + column);

    }

    /**
     * This function returns the value of the row number.
     *
     * @return The row value
     *
     * @post
     *      getRow = row AND row = #row AND column = #column
     */
    public int getRow() {

        return row;

    }

    /**
     * This function returns the value of the column number.
     *
     * @return The column value
     *
     * @post
     *      getColumn = column AND row = #row AND column = #column
     */
    public int getColumn() {

        return column;

    }

}
