Package algs13.xbacktrack.xsudoku
Class MySudoku
java.lang.Object
algs13.xbacktrack.xsudoku.MySudoku
- All Implemented Interfaces:
XBacktrackProblem<XMutableCell>
A Sudoker solver, implemented as a BacktrackProblem where each
choice is represented by a MutableCell (a cell we can assign a
digit as part of a possible solution to Sudoku).
This project represents a more substantial Java program than
what we have been working with so far in the course. Search in this
file and in algs13.xbacktrack.xframework.MyBacktrackDriver
(MyBacktrackDriver.java)for some TODOs that will direct you to what you
need to do for this assignment.
-
Field Summary
Modifier and TypeFieldDescriptionprivate MyBacktrackDriver
<XMutableCell> (package private) final XMutableCell
private final XSudokuCell[][]
static final int
(package private) final XMutableCell
static final int
private final HashMap
<Integer, Set<XSudokuCell>> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
advance
(XMutableCell previous) Determine if the backtracking driver can advance in searching for a solution from the state represented by previous choice.private XMutableCell
findNextMove
(XMutableCell current) void
initialize
(MyBacktrackDriver<XMutableCell> driver) Initialize the problem.private boolean
isValid
(XSudokuCell cell) static void
toString()
private boolean
verify()
-
Field Details
-
SUBGRID_DIMENSION
- See Also:
-
GRID_SIZE
- See Also:
-
grid
-
subgrids
-
firstCell
-
lastCell
-
driver
-
-
Constructor Details
-
MySudoku
The constructor takes GRID_SIZE array of strings, each of which must be GRID_SIZE in length. Each character must be a digit. The index of the string corresponds to the row in the grid and the index of the digit in the string corresponds to the column in the grid. If a digit is 0, that signifies that the cell in the grid is mutable and the digit in that cell will be assigned by the solver.
-
-
Method Details
-
initialize
Description copied from interface:XBacktrackProblem
Initialize the problem. The initialize method must call the track method on the driver to track the starting state.- Specified by:
initialize
in interfaceXBacktrackProblem<XMutableCell>
- Parameters:
driver
- The driver orchestrating the search for the solution.
-
findNextMove
-
verify
-
isValid
-
advance
Description copied from interface:XBacktrackProblem
Determine if the backtracking driver can advance in searching for a solution from the state represented by previous choice. If it can, this method must either call the track method on the driver to track the next choice, or it must call the driver's setDone() method.- Specified by:
advance
in interfaceXBacktrackProblem<XMutableCell>
- Parameters:
previous
- The previous choice- Returns:
- true if the current state consists of a valid partial solution, or the current state represents a complete solution (i.e. the last choice required to solve the problem has been made).
-
toString
-
main
-