public class SudokuNode
extends SearchNode
implements java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
static int |
SIZE
number of square grid rows and columns
|
static int |
UNKNOWN
constant 0 indicating an unknown grid value
|
Constructor and Description |
---|
SudokuNode(int[][] grid)
Constructs a SudokuNode using the given 9-by-9 grid of cell values, either ranging from 1 to 9 or being the
UNKNOWN value. |
SudokuNode(java.util.Scanner scanner)
Constructs a SudokuNode using the given Scanner to read a text Sudoku grid with periods marking unknown values.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Create a deep clone of this SudokuNode using the int[][] grid copy constructor.
|
java.util.ArrayList<SearchNode> |
expand()
Return a list of children of this node.
|
int |
getCell(int row,
int column)
Return the current cell value given the row and column of the cell.
|
boolean |
isGoal()
Return whether or not the grid contains no
UNKNOWN values. |
java.lang.String |
toString()
Return a String representation of the Sudoku grid with periods marking unknown values.
|
public static final int SIZE
public static final int UNKNOWN
public SudokuNode(java.util.Scanner scanner)
scanner
- a Scanner object for reading a text Sudoku grid with periods marking unknown values.public SudokuNode(int[][] grid)
UNKNOWN
value.
This constructor should not merely assign the given grid to a Sudoku node field, but should make its own field copy of the grid, i.e.
there should be a step where you allocate a new grid 2D int array.grid
- initial 9-by-9 grid of cell values, either ranging from 1 to 9 or being the UNKNOWN
value.public int getCell(int row, int column)
row
- row of the cellcolumn
- column of the cellpublic java.lang.String toString()
UNKNOWN
.toString
in class java.lang.Object
public boolean isGoal()
UNKNOWN
values.isGoal
in class SearchNode
UNKNOWN
valuespublic java.util.ArrayList<SearchNode> expand()
expand
in class SearchNode
public java.lang.Object clone()
clone
in class SearchNode
Object
value