Class Creator


  • public final class Creator
    extends java.lang.Object
    Creates a fully filled sudoku.
    Author:
    Stephan Fuhrmann
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static GameMatrix createFull()
      Creates a valid fully setup sudoku.
      protected static byte[] createNumbersToDistribute​(java.util.Random r, int multiplicity)
      Create a random array with numbers to distribute.
      static Riddle createRiddle​(GameMatrix fullMatrix)
      Creates a riddle setup sudoku.
      static GameMatrix createVariant​(GameMatrix fullyFilled)
      Creates a variant of a fully-filled game matrix.
      protected static int getSetBitOffset​(int mask, int bitIndex)
      Get the index of the nth bit set.
      protected static void swapColumn​(GameMatrix matrix, int columnA, int columnB)
      Swaps two columns in the given matrix.
      protected static void swapRow​(GameMatrix matrix, int rowA, int rowB)
      Swaps two rows in the given matrix.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getSetBitOffset

        protected static int getSetBitOffset​(int mask,
                                             int bitIndex)
        Get the index of the nth bit set.
        Parameters:
        mask - the value to get the bit index from.
        bitIndex - the number of the set bit wanted.
        Returns:
        the index of the relative bitIndex set bit counted from 0, or -1 if there are no more set bits.
      • createFull

        public static GameMatrix createFull()
        Creates a valid fully setup sudoku.
        Returns:
        a fully filled sudoku board. No fields are unset.
      • createVariant

        public static GameMatrix createVariant​(GameMatrix fullyFilled)
        Creates a variant of a fully-filled game matrix. The variant is calculated very efficiently by applying simple transformations.
        Parameters:
        fullyFilled - the input matrix to transform. All fields need to be filled.
        Returns:
        a transformed variant of the input game matrix.
        Throws:
        java.lang.IllegalArgumentException - if there are unset fields in the GameMatrix.
      • swapRow

        protected static void swapRow​(GameMatrix matrix,
                                      int rowA,
                                      int rowB)
        Swaps two rows in the given matrix.
        Parameters:
        matrix - the game matrix to swap rows in.
        rowA - the first row to swap.
        rowB - the second row to swap.
      • swapColumn

        protected static void swapColumn​(GameMatrix matrix,
                                         int columnA,
                                         int columnB)
        Swaps two columns in the given matrix.
        Parameters:
        matrix - the game matrix to swap rows in.
        columnA - the first column to swap.
        columnB - the second column to swap.
      • createNumbersToDistribute

        protected static byte[] createNumbersToDistribute​(java.util.Random r,
                                                          int multiplicity)
        Create a random array with numbers to distribute.
        Parameters:
        r - the random number generator to use.
        multiplicity - the number of times to add the numbers 1 to 9. 1 means adding 1 to 9 only once. 2 means adding 1 to 9 twice.
        Returns:
        an array with randomly ordered numbers from 1 to 9 with each number occuring multiplicity times.