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

/**
 * A <code>ColumnGroup</code> represents a group of squares within a single
 * column of a Sudoku <code>Board</code>.  Each square within the column must
 * have a unique value.  The primary task of a <code>ColumnGroup</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 ColumnGroup extends ConstrainedGroup {
    /**
     * The number of the board column represented by this group.
     */
    private final int col;

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

    /**
     * Creates a new <code>ColumnGroup</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 col    the number of the board column that is to be represented
     */
    public ColumnGroup(Board board, int col) {
        super(board);
        this.col = col;
    }
    
    /*
     * See comments for ConstrainedGroup#updateToIndex(Update).
     */
    protected int updateToIndex(Update u) {
        // Within a column, we can use row numbers to identify squares.
        return u.row;
    }
    
    /*
     * See comments for ConstrainedGroup#getSquare(int).
     */
    protected Square getSquare(int index) {
        return board.getSquare(index, col);
    }
}

// End of file.

