public final class SudokuStore extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
AVAILABLE_RND_BOARD_TRANSF
Number of available random board transformations.
|
static int |
DEFAULT_RND_TRANSF_SEQ_LENGTH
Default sequence length of random board transformations.
|
static String |
JANET_SUDOKU_NAME
Sudoku solver name.
|
static String |
JANET_SUDOKU_VERSION
Sudoku solver version.
|
static String |
NEW_LINE_SEPARATOR
System specific new line separator
|
static int |
NUMBER_OF_PUZZLE_EXAMPLES
Number of Sudoku puzzles examples.
|
static int |
THREADS_NUMBER
Threads number.
|
| Constructor and Description |
|---|
SudokuStore() |
| Modifier and Type | Method and Description |
|---|---|
static String |
boardAndEmptyCellsToString(int[][] sudokuBoard,
int[][] emptyCells)
Returns string representation of the board and empty cells.
|
static int[][] |
boardCopy(int[][] sudokuBoard)
Exact (1 to 1) copy of Sudoku board array.
|
static boolean |
boardsAreEqual(int[][] board1,
int[][] board2)
Checks whether boards are equal.
|
static int |
boardSegmentStartIndex(int segId)
9x9 Sudoku board consist either 3 row segments (3x9 each one)
or 3 column segments (9x3 each one).
|
static String |
boardToString(int[][] sudokuBoard)
Returns string representation of the board.
|
static String |
boardToString(int[][] sudokuBoard,
String headComment)
Returns string representation of the board + provided comment.
|
static String |
boardToString(int[][] sudokuBoard,
String headComment,
String tailComment)
Returns string representation of the board + provided comment.
|
static int |
calculatePuzzleRating(int[][] sudokuPuzzle)
Calculates difficulty of Sudoku puzzle.
|
static boolean |
checkPuzzle(int[][] sudokuBoard)
Checks whether Sudoku puzzle contains an obvious error.
|
static boolean |
checkSolvedBoard(int[][] solvedBoard)
Checks whether solved board is correct.
|
static void |
consolePrintBoard(int[][] sudokuBoard)
Prints Sudoku board to the console.
|
static void |
consolePrintln(Object o)
Prints object to the console.
|
static String |
emptyCellsToString(int[][] emptyCells)
Returns string representation of empty cells (only).
|
static int[] |
generatePermutation(int n)
Permutation generator assuming permuting
0, 1, ..., n-1 for n-length permutation.
|
static int[][] |
getPuzzleExample()
Gets Sudoku example for the Sudoku Store.
|
static int[][] |
getPuzzleExample(int exampleNumber)
Gets Sudoku example for the Sudoku Store.
|
static double |
getPuzzleExampleRating(int exampleNumber)
Returns pre-calculated puzzle example difficulty rating based on
the average number of steps-back performed while recursive
solving sudoku board.
|
static boolean |
isValidPermutation(int[] permutation)
Checks whether given array of length n is representing
valid permutation of 0, 1, ..., n-1
|
static boolean |
isValidPermutation(int[] permutation,
int n)
Checks whether given array is representing
valid permutation of length n and form of 0, 1, ..., n-1
|
static int[][] |
loadBoard(ArrayList<String> boardDefinition)
Loads Sudoku board from list of strings (each string as a
one row)
Format:
Any character different than '1-9' and '.' is being removed.
|
static int[][] |
loadBoard(String filePath)
Loads Sudoku board from text file.
|
static int[][] |
loadBoard(String[] boardDefinition)
Loads Sudoku board from array of strings (each string as a
one row)
Format:
Any character different than '1-9' and '.' is being removed.
|
static int[][] |
loadBoardFromStringLine(String boardDefinition)
Loads Sudoku board from one string line ('0' and' '.' treated as empty cell).
|
static int[][] |
loadBoardFromStrings(String... boardDefinition)
Loads Sudoku board from variadic list of strings (each string as a
one row)
Format:
Any character different than '1-9' and '.' is being removed.
|
static int[][] |
permuteBoard(int[][] sudokuBoard)
Random permutation of sudoku board.
|
static int[][] |
permuteBoard(int[][] sudokuBoard,
int[] permutation)
Sudoku board permutation.
|
static int[][] |
permuteColSegments(int[][] sudokuBoard)
Method applies randomly generated permutation of length 3 (permutation of 0, 1, 2)
to the 3 column segments (9x3 each one) of Sudoku array.
|
static int[][] |
permuteColSegments(int[][] sudokuBoard,
int[] permutation)
Method applies given permutation of length 3 (permutation of 0, 1, 2)
to the 3 column segments (9x3 each one) of Sudoku array.
|
static int[][] |
permuteColsInAllSegments(int[][] sudokuBoard)
Method applies randomly generated permutations of length 3 (permutation of 0, 1, 2)
to the 3 columns in a all column segments (9x3 each one) of Sudoku array.
|
static int[][] |
permuteColsInSegment(int[][] sudokuBoard)
Method applies randomly generated permutation of length 3 (permutation of 0, 1, 2)
to the 3 columns in a randomly selected column segment (3x9 each one) of Sudoku array.
|
static int[][] |
permuteColsInSegment(int[][] sudokuBoard,
int colSeg)
Method applies randomly generated permutation of length 3 (permutation of 0, 1, 2)
to the 3 columns in a given column segment (3x9 each one) of Sudoku array.
|
static int[][] |
permuteColsInSegment(int[][] sudokuBoard,
int colSeg,
int[] permutation)
Method applies given permutation of length 3 (permutation of 0, 1, 2)
to the 3 columns in a given column segment (3x9 each one) of Sudoku array.
|
static int[][] |
permuteRowSegments(int[][] sudokuBoard)
Method applies randomly generated permutation of length 3 (permutation of 0, 1, 2)
to the 3 row segments (3x9 each one) of Sudoku array.
|
static int[][] |
permuteRowSegments(int[][] sudokuBoard,
int[] permutation)
Method applies given permutation of length 3 (permutation of 0, 1, 2)
to the 3 row segments (3x9 each one) of Sudoku array.
|
static int[][] |
permuteRowsInAllSegments(int[][] sudokuBoard)
Method applies randomly generated permutations of length 3 (permutation of 0, 1, 2)
to the 3 rows in a all row segments (9x3 each one) of Sudoku array.
|
static int[][] |
permuteRowsInSegment(int[][] sudokuBoard)
Method applies randomly generated permutation of length 3 (permutation of 0, 1, 2)
to the 3 rows in a randomly selected row segment (9x3 each one) of Sudoku array.
|
static int[][] |
permuteRowsInSegment(int[][] sudokuBoard,
int rowSeg)
Method applies randomly generated permutation of length 3 (permutation of 0, 1, 2)
to the 3 rows in a given row segment (9x3 each one) of Sudoku array.
|
static int[][] |
permuteRowsInSegment(int[][] sudokuBoard,
int rowSeg,
int[] permutation)
Method applies given permutation of length 3 (permutation of 0, 1, 2)
to the 3 rows in a given row segment (9x3 each one) of Sudoku array.
|
static int[][] |
randomBoardTransf(int[][] sudokuBoard)
Random board transformation of type selected randomly (typed randomly selected between
0 and
AVAILABLE_RND_BOARD_TRANSF). |
static int[][] |
randomBoardTransf(int[][] sudokuBoard,
int transfId)
Based on the parameter value method applies
one of the following board transformation:
0 -
rotateClockWise(int[][])
1 - rotateCounterclockWise(int[][])
2 - reflectHorizontally(int[][])
3 - reflectVertically(int[][])
4 - transposeTlBr(int[][])
5 - transposeTrBl(int[][])
6 - swapRowSegmentsRandomly(int[][])
7 - swapColSegmentsRandomly(int[][])
8 - swapRowsInSegmentRandomly(int[][])
9 - swapColsInSegmentRandomly(int[][])
10 - permuteBoard(int[][])
11 - permuteRowSegments(int[][])
12 - permuteColSegments(int[][])
13 - permuteRowsInSegment(int[][])
14 - permuteRowsInAllSegments(int[][])
15 - permuteColsInSegment(int[][])
16 - permuteColsInAllSegments(int[][])
|
static int |
randomIndex(int n)
Random number generator for n returning random number between 0, 1, ... n-1.
|
static int |
randomNumber(int n)
Random number generator for n returning random number between 1, 2, ... n.
|
static int[][] |
reflectHorizontally(int[][] sudokuBoard)
Horizontal reflection of the Sudoku board.
|
static int[][] |
reflectVertically(int[][] sudokuBoard)
Vertical reflection of the Sudoku board.
|
static int[][] |
rotateClockWise(int[][] sudokuBoard)
Clockwise rotation of Sudoku board.
|
static int[][] |
rotateCounterclockWise(int[][] sudokuBoard)
Counterclockwise rotation of Sudoku board.
|
static boolean |
saveBoard(int[][] sudokuBoard,
String filePath)
Saves board to the text file.
|
static boolean |
saveBoard(int[][] sudokuBoard,
String filePath,
String headComment)
Saves board to the text file.
|
static boolean |
saveBoard(int[][] sudokuBoard,
String filePath,
String headComment,
String tailComment)
Saves board to the text file.
|
static int[][] |
seqOfRandomBoardTransf(int[][] sudokuBoard)
Applies to the Sudoku board sequence (of default length) of transformations selected randomly
(each transformation selected randomly between 0 and
AVAILABLE_RND_BOARD_TRANSF). |
static int[][] |
seqOfRandomBoardTransf(int[][] sudokuBoard,
int seqLength)
Applies to the Sudoku board sequence (of a given length) of transformations selected randomly
(each transformation selected randomly between 0 and
AVAILABLE_RND_BOARD_TRANSF). |
static String |
solutionPathToString(BoardCell[] solutionBoardCells)
Returns string representation of the 'path' leading to the solution.
|
static int[][] |
swapColSegments(int[][] sudokuBoard,
int colSeg1,
int colSeg2)
Swapping 2 column segments (9x3 each one) of Sudoku board.
|
static int[][] |
swapColSegmentsRandomly(int[][] sudokuBoard)
Swapping randomly selected 2 column segments (9x3 each one) of Sudoku board.
|
static int[][] |
swapColsInSegment(int[][] sudokuBoard,
int colSeg,
int col1,
int col2)
Swapping 2 columns within a given column segment.
|
static int[][] |
swapColsInSegmentRandomly(int[][] sudokuBoard)
Swapping randomly selected 2 columns within randomly select column segment.
|
static int[][] |
swapRowSegments(int[][] sudokuBoard,
int rowSeg1,
int rowSeg2)
Swapping 2 row segments (3x9 each one) of Sudoku board.
|
static int[][] |
swapRowSegmentsRandomly(int[][] sudokuBoard)
Swapping randomly selected 2 row segments (3x9 each one) of Sudoku board.
|
static int[][] |
swapRowsInSegment(int[][] sudokuBoard,
int rowSeg,
int row1,
int row2)
Swapping 2 rows within a given row segment.
|
static int[][] |
swapRowsInSegmentRandomly(int[][] sudokuBoard)
Swapping randomly selected 2 rows within randomly select row segment.
|
static int[][] |
transposeTlBr(int[][] sudokuBoard)
Diagonal (Top-Left -> Bottom-Right) reflection of the Sudoku board.
|
static int[][] |
transposeTrBl(int[][] sudokuBoard)
Diagonal (Top-Right -> Bottom-Left) reflection of the Sudoku board.
|
public static final String JANET_SUDOKU_VERSION
public static final String JANET_SUDOKU_NAME
public static final int NUMBER_OF_PUZZLE_EXAMPLES
public static final int AVAILABLE_RND_BOARD_TRANSF
public static final int DEFAULT_RND_TRANSF_SEQ_LENGTH
public static final String NEW_LINE_SEPARATOR
public static final int THREADS_NUMBER
public static final int[][] getPuzzleExample(int exampleNumber)
exampleNumber - Example number.SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES,
SudokuPuzzles.getPuzzleExample(int)public static final int[][] getPuzzleExample()
SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES,
SudokuPuzzles.getPuzzleExample(int)public static final double getPuzzleExampleRating(int exampleNumber)
exampleNumber - The example number SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLESpublic static final int calculatePuzzleRating(int[][] sudokuPuzzle)
sudokuPuzzle - Sudoku puzzle to be rated.ErrorCodes.SUDOKUSTORE_CALCULATEPUZZLERATING_PUZZLE_ERROR.
If puzzle has no solutions then ErrorCodes.SUDOKUSTORE_CALCULATEPUZZLERATING_NO_SOLUTION.
If solution is non-unique then ErrorCodes.SUDOKUSTORE_CALCULATEPUZZLERATING_NON_UNIQUE_SOLUTION.public static final int[][] loadBoard(String filePath)
filePath - Path to the file with Sudoku board definition.public static final int[][] loadBoard(ArrayList<String> boardDefinition)
boardDefinition - Board definition (list of strings).public static final int[][] loadBoard(String[] boardDefinition)
boardDefinition - Board definition (array of strings).public static final int[][] loadBoardFromStringLine(String boardDefinition)
boardDefinition - Board definition in one string line containing
row after row.public static final int[][] loadBoardFromStrings(String... boardDefinition)
boardDefinition - Board definition (variadic list of strings).public static final boolean saveBoard(int[][] sudokuBoard,
String filePath)
sudokuBoard - Sudoku board to be saved.filePath - Path to the file.boardToString(int[][])public static final boolean saveBoard(int[][] sudokuBoard,
String filePath,
String headComment)
sudokuBoard - Sudoku board to be saved.filePath - Path to the file.headComment - Comment to be added at the head.boardToString(int[][], String)public static final boolean saveBoard(int[][] sudokuBoard,
String filePath,
String headComment,
String tailComment)
sudokuBoard - Sudoku board to be saved.filePath - Path to the file.headComment - Comment to be added at the head.tailComment - Comment to be added at the tail.boardToString(int[][], String, String)public static boolean checkSolvedBoard(int[][] solvedBoard)
solvedBoard - The solved board to be verified.public static boolean checkPuzzle(int[][] sudokuBoard)
sudokuBoard - The board to be verified.public static final int[][] rotateClockWise(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] rotateCounterclockWise(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] reflectHorizontally(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] reflectVertically(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] transposeTlBr(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] transposeTrBl(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] swapRowSegments(int[][] sudokuBoard,
int rowSeg1,
int rowSeg2)
sudokuBoard - Array representing Sudoku board.rowSeg1 - First row segment id: 0, 1, 2.rowSeg2 - Second row segment id: 0, 1, 2.public static final int[][] swapRowSegmentsRandomly(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] swapColSegments(int[][] sudokuBoard,
int colSeg1,
int colSeg2)
sudokuBoard - Array representing Sudoku board.colSeg1 - First column segment id: 0, 1, 2.colSeg2 - Second column segment id: 0, 1, 2.public static final int[][] swapColSegmentsRandomly(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] swapRowsInSegment(int[][] sudokuBoard,
int rowSeg,
int row1,
int row2)
sudokuBoard - Array representing Sudoku board.rowSeg - Row segment id: 0, 1, 2.row1 - First row id within a segment: 0, 1, 2.row2 - Second row id within a segment: 0, 1, 2.public static final int[][] swapRowsInSegmentRandomly(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] swapColsInSegment(int[][] sudokuBoard,
int colSeg,
int col1,
int col2)
sudokuBoard - Array representing Sudoku board.colSeg - Column segment id: 0, 1, 2.col1 - First column id within a segment: 0, 1, 2.col2 - Second column id within a segment: 0, 1, 2.public static final int[][] swapColsInSegmentRandomly(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] permuteBoard(int[][] sudokuBoard,
int[] permutation)
sudokuBoard - Sudoku board to be permuted.permutation - Permutation (ie. 5, 2, 8, 9, 1, 3, 6, 4, 7)public static final int[][] permuteBoard(int[][] sudokuBoard)
sudokuBoard - Sudoku board to be permuted.public static final int[][] permuteRowSegments(int[][] sudokuBoard,
int[] permutation)
sudokuBoard - Array representing Sudoku board.permutation - Array representing permutation of length 3 (permuting: 0, 1, 2).public static final int[][] permuteRowSegments(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] permuteColSegments(int[][] sudokuBoard,
int[] permutation)
sudokuBoard - Array representing Sudoku board.permutation - Array representing permutation of length 3 (permuting: 0, 1, 2).public static final int[][] permuteColSegments(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.public static final int[][] permuteRowsInSegment(int[][] sudokuBoard,
int rowSeg,
int[] permutation)
sudokuBoard - Array representing Sudoku board.rowSeg - Row segment id: 0, 1, 2.permutation - Permutation of length 3 (0, 1, 2)isValidPermutation(int[]),
generatePermutation(int)public static final int[][] permuteRowsInSegment(int[][] sudokuBoard,
int rowSeg)
sudokuBoard - Array representing Sudoku board.rowSeg - Row segment id: 0, 1, 2.generatePermutation(int)public static final int[][] permuteRowsInSegment(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.generatePermutation(int)public static final int[][] permuteRowsInAllSegments(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.generatePermutation(int)public static final int[][] permuteColsInSegment(int[][] sudokuBoard,
int colSeg,
int[] permutation)
sudokuBoard - Array representing Sudoku board.colSeg - Column segment id: 0, 1, 2.permutation - Permutation of length 3 (0, 1, 2)isValidPermutation(int[]),
generatePermutation(int)public static final int[][] permuteColsInSegment(int[][] sudokuBoard,
int colSeg)
sudokuBoard - Array representing Sudoku board.colSeg - Column segment id: 0, 1, 2.generatePermutation(int)public static final int[][] permuteColsInSegment(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.generatePermutation(int)public static final int[][] permuteColsInAllSegments(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku board.generatePermutation(int)public static final int[][] randomBoardTransf(int[][] sudokuBoard,
int transfId)
rotateClockWise(int[][])
rotateCounterclockWise(int[][])
reflectHorizontally(int[][])
reflectVertically(int[][])
transposeTlBr(int[][])
transposeTrBl(int[][])
swapRowSegmentsRandomly(int[][])
swapColSegmentsRandomly(int[][])
swapRowsInSegmentRandomly(int[][])
swapColsInSegmentRandomly(int[][])
permuteBoard(int[][])
permuteRowSegments(int[][])
permuteColSegments(int[][])
permuteRowsInSegment(int[][])
permuteRowsInAllSegments(int[][])
permuteColsInSegment(int[][])
permuteColsInAllSegments(int[][])
sudokuBoard - Sudoku board to be transformedtransfId - Random operation id between 0 and AVAILABLE_RND_BOARD_TRANSF.public static final int[][] randomBoardTransf(int[][] sudokuBoard)
AVAILABLE_RND_BOARD_TRANSF).sudokuBoard - Sudoku board to be transformed.randomBoardTransf(int[][], int)public static final int[][] seqOfRandomBoardTransf(int[][] sudokuBoard,
int seqLength)
AVAILABLE_RND_BOARD_TRANSF).sudokuBoard - Sudoku board to be transformed.seqLength - Length of sequence (positive)randomBoardTransf(int[][], int)public static final int[][] seqOfRandomBoardTransf(int[][] sudokuBoard)
AVAILABLE_RND_BOARD_TRANSF).
Invocation of seqOfRandomBoardTransf(int[][], int) with sequence length
equal to DEFAULT_RND_TRANSF_SEQ_LENGTH.sudokuBoard - Sudoku board to be transformed.randomBoardTransf(int[][], int)public static final int randomIndex(int n)
n - The parameter influencing random number generation process.ErrorCodes.SUDOKUSTORE_RANDOMINDEX_INCORRECT_PARAMETER
is returned.public static final int randomNumber(int n)
n - The parameter influencing random number generation process.ErrorCodes.SUDOKUSTORE_RANDOMINDEX_INCORRECT_PARAMETER
is returned.public static final int boardSegmentStartIndex(int segId)
segId - The segment id: 0, 1, 2ErrorCodes.SUDOKUSTORE_BOARDSEGMENTSTARTINDEX_INCORRECT_SEGMENT.public static final int[] generatePermutation(int n)
n - The permutation length.public static final boolean isValidPermutation(int[] permutation)
permutation - Array representing permutationpublic static final boolean isValidPermutation(int[] permutation,
int n)
permutation - Array representing permutation.n - Assumed permutation length.public static final int[][] boardCopy(int[][] sudokuBoard)
sudokuBoard - The board that will be copied.public static final boolean boardsAreEqual(int[][] board1,
int[][] board2)
board1 - First board.board2 - Second board.public static final String boardToString(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku puzzles.public static final String boardToString(int[][] sudokuBoard, String headComment)
sudokuBoard - Sudoku board.headComment - Comment to be added at the head.public static final String boardToString(int[][] sudokuBoard, String headComment, String tailComment)
sudokuBoard - Sudoku board.headComment - Comment to be added at the head.tailComment - Comment to be added at the tail.public static final String emptyCellsToString(int[][] emptyCells)
emptyCells - Array representing empty cells of Sudoku puzzles.public static final String boardAndEmptyCellsToString(int[][] sudokuBoard, int[][] emptyCells)
sudokuBoard - Array representing Sudoku puzzles.emptyCells - Array representing empty cells of Sudoku puzzles.public static final String solutionPathToString(BoardCell[] solutionBoardCells)
solutionBoardCells - Array representing sequence of board cells.public static final void consolePrintBoard(int[][] sudokuBoard)
sudokuBoard - Sudoku board to be printedpublic static final void consolePrintln(Object o)
o - Object to be printed.Copyright © 2017. All rights reserved.