public class SudokuSolver extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
SOLUTION_NON_UNIQUE
Solution exists and is non-unique.
|
static int |
SOLUTION_NOT_EXISTS
Solution does not exist.
|
static int |
SOLUTION_UNIQUE
Solution exists and is unique.
|
static int |
SOLVING_STATE_NOT_STARTED
Sudoku solving not initiated.
|
static int |
SOLVING_STATE_SOLVED
Sudoku solving finished and successful.
|
static int |
SOLVING_STATE_STARTED
Sudoku solving started.
|
| Constructor and Description |
|---|
SudokuSolver()
Default constructor - only board initialization.
|
SudokuSolver(ArrayList<String> boardDefinition)
Constructor - based on file path to the Sudoku definition.
|
SudokuSolver(int exampleNumber)
Constructor - based on the Sudoku predefined example number.
|
SudokuSolver(int[][] sudokuBoard)
Constructor - based on array representing Sudoku board.
|
SudokuSolver(String filePath)
Constructor - based on file path to the Sudoku definition.
|
SudokuSolver(String[] boardDefinition)
Constructor - based on file path to the Sudoku definition.
|
| Modifier and Type | Method and Description |
|---|---|
String |
boardAndEmptyCellsToString()
Returns string board and empty cells representation.
|
String |
boardToString()
Returns string board (only) representation.
|
int |
checkIfUniqueSolution()
Method searching all solutions procedure.
|
void |
clearMessages()
Clears list of recorded messages.
|
void |
clearPuzzels()
To clear the Sudoku board.
|
void |
disableRndSeedOnEmptyCells()
By default random seed on empty cells is enabled.
|
void |
disableRndSeedOnFreeDigits()
By default random seed on free digits is enabled.
|
String |
emptyCellsToString()
Returns string empty cells (only) representation.
|
void |
enableRndSeedOnEmptyCells()
By default random seed on empty cells is enabled.
|
void |
enableRndSeedOnFreeDigits()
By default random seed on free digits is enabled.
|
int |
findAllSolutions()
Method searching all solutions procedure.
|
BoardCell[] |
getAllBoardCells()
Get all current board cells.
|
ArrayList<SudokuBoard> |
getAllSolutionsList()
Gets all solutions list evaluated by the findAllSolutions() method
|
int[][] |
getBoard()
Gets array representing Sudoku board.
|
int[][] |
getBoardCopy()
Method for copy current board content
|
int |
getBoardState()
Return current Sudou board state.
|
int |
getCellDigit(int rowIndex,
int colIndex)
Returns cell digit from current Sudoku board.
|
int |
getClosedRoutesNumber()
Number of routes that were assessed, but lead to nothing
and required step back.
|
double |
getComputingTime()
Return solving time in seconds..
|
int[][] |
getEmptyCells()
Gets array representing evaluated empty cells.
|
String |
getLastErrorMessage()
Gets last recorded error message.
|
String |
getLastMessage()
Gets last recorded message.
|
String |
getMessages()
Returns list of recorded messages.
|
BoardCell[] |
getSolutionBoardCells()
Return solution board cells keeping the solution
path order.
|
int[][] |
getSolvedBoard()
Gets array representing solved Sudoku board.
|
int |
getSolvingState()
Return current solving status.
|
int |
loadBoard(ArrayList<String> boardDefinition)
Loads Sudoku from array of strings.
|
int |
loadBoard(int exampleNumber)
Loads Sudoku example given by the parameter exampleNumber.
|
int |
loadBoard(int[][] sudokuBoard)
Loads Sudoku from array.
|
int |
loadBoard(String filePath)
Loads Sudoku from file.
|
int |
loadBoard(String[] boardDefinition)
Loads Sudoku from array of strings.
|
boolean |
saveBoard(String filePath)
Saves board to the text file.
|
boolean |
saveBoard(String filePath,
String headComment)
Saves board to the text file.
|
boolean |
saveBoard(String filePath,
String headComment,
String tailComment)
Saves board to the text file.
|
boolean |
saveSolvedBoard(String filePath)
Saves solved board to the text file.
|
boolean |
saveSolvedBoard(String filePath,
String headComment)
Saves solved board to the text file.
|
boolean |
saveSolvedBoard(String filePath,
String headComment,
String tailComment)
Saves solved board to the text file.
|
int |
setCell(int rowIndex,
int colIndex,
int digit)
Manually set cell value.
|
String |
solutionPathToString()
Return string representation of cells that lead to
the solution, keeping the sequence.
|
int |
solve()
Method starts solving procedure.
|
public static final int SOLVING_STATE_NOT_STARTED
public static final int SOLVING_STATE_STARTED
public static final int SOLVING_STATE_SOLVED
public static final int SOLUTION_NOT_EXISTS
checkIfUniqueSolution(),
Constant Field Valuespublic static final int SOLUTION_UNIQUE
checkIfUniqueSolution(),
Constant Field Valuespublic static final int SOLUTION_NON_UNIQUE
checkIfUniqueSolution(),
Constant Field Valuespublic SudokuSolver()
public SudokuSolver(int exampleNumber)
exampleNumber - number of Sudoku example to load between 1
and SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLESpublic SudokuSolver(String filePath)
filePath - Path to the sudoku definition.public SudokuSolver(String[] boardDefinition)
boardDefinition - Board definition (as array of strings,
each array entry as separate row).public SudokuSolver(ArrayList<String> boardDefinition)
boardDefinition - Board definition (as list of strings,
each list entry as separate row).public SudokuSolver(int[][] sudokuBoard)
sudokuBoard - 9x9 array representing Sudoku board/public int loadBoard(int exampleNumber)
exampleNumber - Number of predefined Sudoku example.ErrorCodes.SUDOKUSOLVER_LOADBOARD_LOADING_FAILED or
SudokuBoard.BOARD_STATE_LOADED.public int loadBoard(String filePath)
filePath - File path that contains board definition.ErrorCodes.SUDOKUSOLVER_LOADBOARD_LOADING_FAILED or
SudokuBoard.BOARD_STATE_LOADED.public int loadBoard(String[] boardDefinition)
boardDefinition - Board definition as array of strings
(each array entry as separate row).ErrorCodes.SUDOKUSOLVER_LOADBOARD_LOADING_FAILED or
SudokuBoard.BOARD_STATE_LOADED.public int loadBoard(ArrayList<String> boardDefinition)
boardDefinition - Board definition as list of strings
(each list entry as separate row).ErrorCodes.SUDOKUSOLVER_LOADBOARD_LOADING_FAILED or
SudokuBoard.BOARD_STATE_LOADED.public int loadBoard(int[][] sudokuBoard)
sudokuBoard - Array representing Sudoku puzzles.ErrorCodes.SUDOKUSOLVER_LOADBOARD_LOADING_FAILED or
SudokuBoard.BOARD_STATE_LOADED.public boolean saveBoard(String filePath)
filePath - Path to the file.SudokuStore.saveBoard(int[][], String),
SudokuStore.boardToString(int[][])public boolean saveBoard(String filePath, String headComment)
filePath - Path to the file.headComment - Comment to be added at the head.SudokuStore.saveBoard(int[][], String, String),
SudokuStore.boardToString(int[][], String)public boolean saveBoard(String filePath, String headComment, String tailComment)
filePath - Path to the file.headComment - Comment to be added at the head.tailComment - Comment to be added at the tail.SudokuStore.saveBoard(int[][], String, String, String),
SudokuStore.boardToString(int[][], String, String)public boolean saveSolvedBoard(String filePath)
filePath - Path to the file.SudokuStore.saveBoard(int[][], String),
SudokuStore.boardToString(int[][])public boolean saveSolvedBoard(String filePath, String headComment)
filePath - Path to the file.headComment - Comment to be added at the head.SudokuStore.saveBoard(int[][], String, String),
SudokuStore.boardToString(int[][], String)public boolean saveSolvedBoard(String filePath, String headComment, String tailComment)
filePath - Path to the file.headComment - Comment to be added at the head.tailComment - Comment to be added at the tail.SudokuStore.saveBoard(int[][], String, String, String),
SudokuStore.boardToString(int[][], String, String)public int setCell(int rowIndex,
int colIndex,
int digit)
rowIndex - Cell row index between 0 and 8.colIndex - Cell column index between 0 and 8.digit - Cell digit between 1 and 9, or EMPTY_CELL.ErrorCodes.SUDOKUSOLVER_SETCELL_INCORRECT_DEFINITION otherwise.public int getCellDigit(int rowIndex,
int colIndex)
rowIndex - Cell row index between 0 and 8.colIndex - Cell column index between 0 and 8.BoardCell.EMPTY.
If indexes are out of range then error
ErrorCodes.SUDOKUSOLVER_GETCELLDIGIT_INCORRECT_INDEX
is returned.public int solve()
SudokuBoard.BOARD_STATE_EMPTY then ErrorCodes.SUDOKUSOLVER_SOLVE_SOLVING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_ERROR then ErrorCodes.SUDOKUSOLVER_SOLVE_SOLVING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_LOADED then ErrorCodes.SUDOKUSOLVER_SOLVE_SOLVING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_READY then returns solving status:
SOLVING_STATE_SOLVED,
ErrorCodes.SUDOKUSOLVER_SOLVE_SOLVING_FAILED.public int findAllSolutions()
SudokuBoard.BOARD_STATE_EMPTY then ErrorCodes.SUDOKUSOLVER_FINDALLSOLUTIONS_SEARCHING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_ERROR then ErrorCodes.SUDOKUSOLVER_FINDALLSOLUTIONS_SEARCHING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_LOADED then ErrorCodes.SUDOKUSOLVER_FINDALLSOLUTIONS_SEARCHING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_READY then returns number of all solutions found.public int checkIfUniqueSolution()
SudokuBoard.BOARD_STATE_EMPTY then ErrorCodes.SUDOKUSOLVER_CHECKIFUNIQUESOLUTION_CHECKING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_ERROR then ErrorCodes.SUDOKUSOLVER_CHECKIFUNIQUESOLUTION_CHECKING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_LOADED then ErrorCodes.SUDOKUSOLVER_CHECKIFUNIQUESOLUTION_CHECKING_NOT_STARTED,
if board state is SudokuBoard.BOARD_STATE_READY then returns SOLUTION_UNIQUE, SOLUTION_NON_UNIQUE, SOLUTION_NOT_EXISTS.public void clearPuzzels()
public String getMessages()
public void clearMessages()
public String getLastMessage()
public String getLastErrorMessage()
public int getBoardState()
public int[][] getBoardCopy()
public int getSolvingState()
public int[][] getBoard()
public int[][] getSolvedBoard()
public ArrayList<SudokuBoard> getAllSolutionsList()
findAllSolutions()public int[][] getEmptyCells()
public BoardCell[] getAllBoardCells()
public BoardCell[] getSolutionBoardCells()
public double getComputingTime()
public int getClosedRoutesNumber()
public void enableRndSeedOnEmptyCells()
public void disableRndSeedOnEmptyCells()
public void enableRndSeedOnFreeDigits()
public void disableRndSeedOnFreeDigits()
public String boardAndEmptyCellsToString()
public String boardToString()
public String emptyCellsToString()
public String solutionPathToString()
Copyright © 2017. All rights reserved.