Interface GameMatrix

  • All Known Subinterfaces:
    Riddle

    public interface GameMatrix
    The quadratic matrix of a game field.
    Author:
    Stephan Fuhrmann
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BLOCK_COUNT
      The total number of blocks in one dimension.
      static int BLOCK_SIZE
      The edge dimension of a 3x3 block.
      static byte MAXIMUM_VALUE
      The valid value that is the maximum (9).
      static byte MINIMUM_VALUE
      The valid value that is the minimum (1).
      static int SIZE
      The size in one dimension.
      static int TOTAL_FIELDS
      The total number of fields.
      static byte UNSET
      The value that is assigned to unset fields.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean canSet​(int row, int column, byte value)
      Checks if the effect of one set operation is valid.
      void clear()
      Clear the cells.
      byte get​(int row, int column)
      Get the value of a field.
      byte[][] getArray()
      Gets a copy of the underlying array.
      int getSetCount()
      Get the number of set cells.
      boolean isValid()
      Checks if the whole play field is valid.
      void set​(int row, int column, byte value)
      Set the value of a field.
      void setAll​(byte[][] initializationData)
      Sets all cells to the given values.
      static boolean validCoords​(int row, int column)
      Is the coordinate pair passed valid?
      static boolean validValue​(byte b)
      Is the value passed in valid for a field?
    • Field Detail

      • UNSET

        static final byte UNSET
        The value that is assigned to unset fields.
        See Also:
        Constant Field Values
      • MINIMUM_VALUE

        static final byte MINIMUM_VALUE
        The valid value that is the minimum (1).
        See Also:
        Constant Field Values
      • MAXIMUM_VALUE

        static final byte MAXIMUM_VALUE
        The valid value that is the maximum (9).
        See Also:
        Constant Field Values
      • TOTAL_FIELDS

        static final int TOTAL_FIELDS
        The total number of fields.
        See Also:
        Constant Field Values
      • BLOCK_SIZE

        static final int BLOCK_SIZE
        The edge dimension of a 3x3 block.
        See Also:
        Constant Field Values
      • BLOCK_COUNT

        static final int BLOCK_COUNT
        The total number of blocks in one dimension.
        See Also:
        Constant Field Values
    • Method Detail

      • clear

        void clear()
        Clear the cells.
      • get

        byte get​(int row,
                 int column)
        Get the value of a field.
        Parameters:
        row - the row of the cell to get the value for.
        column - the column of the cell to get the value for.
        Returns:
        the cell value ranging from 0 to 9.
      • set

        void set​(int row,
                 int column,
                 byte value)
        Set the value of a field.
        Parameters:
        column - the column of the field.
        row - the row of the field.
        value - the value of the field.
      • setAll

        void setAll​(byte[][] initializationData)
        Sets all cells to the given values.
        Parameters:
        initializationData - initialization data with the first dimension being the rows and the second dimension being the columns.
      • getSetCount

        int getSetCount()
        Get the number of set cells.
        Returns:
        the number of fields with a number in. Can be in the range between 0 and 81.
      • getArray

        byte[][] getArray()
        Gets a copy of the underlying array.
        Returns:
        the data array containing numbers between 0 and 9. The first index is the row index, the second index is the column index.
      • isValid

        boolean isValid()
        Checks if the whole play field is valid.
        Returns:
        true if the filled rows, columns and blocks contain no duplicate numbers.
      • canSet

        boolean canSet​(int row,
                       int column,
                       byte value)
        Checks if the effect of one set operation is valid. This is much quicker than isValid().
        Parameters:
        row - the row of the cell to test validity for.
        column - the column of the cell to test validity for.
        value - the value to simulate setting for.
        Returns:
        true if the given cell can be set to value without violating the game rules.
      • validValue

        static boolean validValue​(byte b)
        Is the value passed in valid for a field?
        Parameters:
        b - value to check.
        Returns:
        true if valid.
      • validCoords

        static boolean validCoords​(int row,
                                   int column)
        Is the coordinate pair passed valid?
        Parameters:
        row - the row index.
        column - the column index.
        Returns:
        true if valid.