/*
 * 2006 Utah High School Programming Contest, University of Utah
 * Take-Home Problem
 *
 * RowGroup.java
 *
 * This file contains the implementation of the RowGroup class.
 */

/**
 * A <code>RowGroup</code> represents a group of squares within a single row
 * of a Sudoku <code>Board</code>.  Each square within the row must have a
 * unique value.  The primary task of a <code>RowGroup</code> is to manage that
 * constraint.
 *
 * <p>All of the "interesting" parts of this class are implemented by the
 * <code>ConstrainedGroup</code> class.  The only things that need to be
 * implemented here involve the mapping between squares' [row, column]
 * coordinates and their indices within the group.
 *
 * @see ConstrainedGroup
 */
public class RowGroup extends ConstrainedGroup {
    /**
     * The number of the board row represented by this group.
     */
    private final int row;

    /*************************************************************************/

    /**
     * Creates a new <code>RowGroup</code>.  The group is initialized to
     * indicate that every square value may be contained in any square within
     * the group.  In other words, nothing is known about the assignment of
     * values to squares.
     *
     * @param board  the <code>Board</code> to which this group belongs
     * @param row    the number of the board row that is to be represented
     */
    public RowGroup(Board board, int row) {
        super(board);
        this.row = row;
    }

    /*
     * See comments for ConstrainedGroup#updateToIndex(Update).
     */
    protected int updateToIndex(Update u) {
        // Within a row, we can use column numbers to identify squares.
        return u.col;
    }

    /*
     * See comments for ConstrainedGroup#getSquare(int).
     */
    protected Square getSquare(int index) {
        return board.getSquare(row, index);
    }
}

// End of file.

