Package de.sfuhrm.sudoku
Class Creator
- java.lang.Object
-
- de.sfuhrm.sudoku.Creator
-
public final class Creator extends java.lang.ObjectCreates a fully filled sudoku.- Author:
- Stephan Fuhrmann
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GameMatrixcreateFull()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 RiddlecreateRiddle(GameMatrix fullMatrix)Creates a riddle setup sudoku.static GameMatrixcreateVariant(GameMatrix fullyFilled)Creates a variant of a fully-filled game matrix.protected static intgetSetBitOffset(int mask, int bitIndex)Get the index of the nth bit set.protected static voidswapColumn(GameMatrix matrix, int columnA, int columnB)Swaps two columns in the given matrix.protected static voidswapRow(GameMatrix matrix, int rowA, int rowB)Swaps two rows in the given matrix.
-
-
-
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
multiplicitytimes.
-
createRiddle
public static Riddle createRiddle(GameMatrix fullMatrix)
Creates a riddle setup sudoku.- Parameters:
fullMatrix- a fully set up (solved) and valid sudoku. Can be created usingcreateFull()orcreateVariant(de.sfuhrm.sudoku.GameMatrix)of a full matrix.- Returns:
- a maximally cleared sudoku. Contains
unsetvalue fields for places where the user/player needs to guess values. - See Also:
createFull(),createVariant(de.sfuhrm.sudoku.GameMatrix)
-
-