|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.co.keang.sudoku.Puzzle
public class Puzzle
A Sudoku puzzle
Nested Class Summary | |
---|---|
static class |
Puzzle.Cell
|
static class |
Puzzle.PuzzleDifficulty
|
Field Summary | |
---|---|
static Puzzle.Cell |
allPossibleNumbers
|
Constructor Summary | |
---|---|
Puzzle()
Constructs an empty puzzle |
|
Puzzle(java.io.BufferedReader r)
Constructs a puzzle from this input stream |
|
Puzzle(Puzzle.Cell[][] grid,
Puzzle.PuzzleDifficulty dif)
Constructs a puzzle from this grid |
Method Summary | |
---|---|
void |
clear()
Clears this puzzle of all values |
Puzzle |
clone()
|
(package private) static Puzzle.Cell[][] |
copyGrid(Puzzle.Cell[][] grid)
creates an copy of the grid |
(package private) static Puzzle.Cell[][] |
copyGrid(Puzzle.Cell[][] src,
Puzzle.Cell[][] dest)
Copies this grid to another grid |
int |
countKnownValues()
Counts the number of known values in this puzzle |
boolean |
equals(java.lang.Object obj)
|
Puzzle.Cell[] |
getBlock(int i)
Gets the options block |
Puzzle.Cell[] |
getBlock(int x,
int y)
Gets the options block |
int |
getBlockIndex(int x,
int y)
Gets the options block |
Puzzle.Cell[] |
getColumn(int i)
Gets the options column |
Puzzle.PuzzleDifficulty |
getDifficulty()
Gets an indication of how difficult it is to solve this puzzle |
static int[] |
getFrequencyOfPossibilities(Puzzle.Cell[] sets)
Gets the frequency of possible values. |
Puzzle.Cell[][] |
getGrid()
Gets this puzzle grid |
Puzzle.Cell |
getKnownValues(java.awt.Point p)
Gets the known values from the row, column or block for this point |
java.awt.Point |
getLocation(Puzzle.Cell set)
Gets the zero based x, y coordinates of this set in the grid |
static java.lang.String |
getLocationsAsText(java.util.List<java.awt.Point> loc)
Gets these locations as string of textual coordinates with letters for the x axis and numbers for the y axis |
static java.lang.String |
getNumbersAsText(java.util.Collection<java.lang.Integer> removed)
Gets these numbers as a formatted text string |
static java.lang.String |
getNumbersAsText(Puzzle.Cell cell)
Gets these numbers as a formatted text string |
Puzzle.Cell |
getPossibleValues(java.awt.Point p)
Gets the possible values for this point |
static java.lang.String[] |
getXAxisLabels()
|
static java.lang.String[] |
getYAxisLabels()
|
int |
hashCode()
|
boolean |
isComplete()
Checks to see if the sudoku is complete |
boolean |
isLegal()
Checks all resolved values to check they are legal |
boolean |
isUnique()
Checks to see if the sudoku is unique by using the brute force solver several times and comparing the complete grids |
int |
makeUnique()
Makes the sudoku have a unique solution by adding discrete cell values to the starting point This can only be successfully called on puzzles that have a solution. |
void |
read(java.io.BufferedReader r)
Reads this file from the input stream |
void |
rotate()
Rotates the grid clockwise 90 degrees |
Puzzle.Cell |
set(int i,
int num)
Sets the value at square denoted by the sequential (1 based) location from top left to bottom right. |
Puzzle.Cell |
set(int x,
int y,
int num)
Sets the value at square denoted by the x, y (0 based) location |
Puzzle.Cell |
set(int x,
int y,
Puzzle.Cell nums)
Sets the values at square denoted by the x, y (0 based) location. |
void |
setDifficulty(AbstractSolver.SolverDifficulty solver,
int factor)
Sets an level indicating how difficult it is to solve this puzzle |
void |
setDifficulty(Puzzle.PuzzleDifficulty dif)
Sets an level indicating how difficult it is to solve this puzzle |
void |
setGrid(Puzzle.Cell[][] grid)
Sets the values for each cell of the sudoku grid. |
java.lang.String |
toString()
|
void |
write(java.io.PrintWriter w)
Writes this file to the output stream |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Puzzle.Cell allPossibleNumbers
Constructor Detail |
---|
public Puzzle()
hGrid
- public Puzzle(Puzzle.Cell[][] grid, Puzzle.PuzzleDifficulty dif)
grid
- public Puzzle(java.io.BufferedReader r) throws java.io.IOException, IllegalGridException
IllegalGridException
java.io.IOException
Method Detail |
---|
public static java.lang.String[] getXAxisLabels()
public static java.lang.String[] getYAxisLabels()
public void rotate()
public void clear()
public int makeUnique()
public boolean isUnique()
public boolean isComplete()
public boolean isLegal()
public Puzzle.Cell getPossibleValues(java.awt.Point p)
p
-
public Puzzle.Cell getKnownValues(java.awt.Point p)
p
-
public Puzzle.Cell[] getColumn(int i)
i
- the 0 based column number
public int getBlockIndex(int x, int y)
x
- the 0 based x coordinatey
- the 0 based y coordinate
public Puzzle.Cell[] getBlock(int x, int y)
x
- the 0 based x coordinatey
- the 0 based y coordinate
public Puzzle.Cell[] getBlock(int i)
i
- the 0 based block number
public java.awt.Point getLocation(Puzzle.Cell set)
set
- the set to find
public static java.lang.String getLocationsAsText(java.util.List<java.awt.Point> loc)
loc
-
public static java.lang.String getNumbersAsText(Puzzle.Cell cell)
cell
-
public static java.lang.String getNumbersAsText(java.util.Collection<java.lang.Integer> removed)
removed
-
public static int[] getFrequencyOfPossibilities(Puzzle.Cell[] sets)
sets
- the line of sets to get the frequencies from
public Puzzle clone()
clone
in class java.lang.Object
static Puzzle.Cell[][] copyGrid(Puzzle.Cell[][] grid)
grid
-
static Puzzle.Cell[][] copyGrid(Puzzle.Cell[][] src, Puzzle.Cell[][] dest)
grid
-
public Puzzle.Cell[][] getGrid()
public Puzzle.Cell set(int i, int num)
i
- the 1 based cell numbernum
- the number. If the number is not legal ie < 1 or > Sudoku.GRID_SIZE the call is set to all possible values
public Puzzle.Cell set(int x, int y, int num)
x
- the 0 based x valuey
- the 0 based y valuenum
- the number
public Puzzle.Cell set(int x, int y, Puzzle.Cell nums)
x
- the 0 based x valuey
- the 0 based y valuenum
- the numbers
public void setGrid(Puzzle.Cell[][] grid)
a
- 2D array of all possible values for each cellpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int countKnownValues()
public void write(java.io.PrintWriter w)
w
- the writer to write topublic void read(java.io.BufferedReader r) throws java.io.IOException, IllegalGridException
r
- the reader to read from
java.io.IOException
IllegalGridException
public void setDifficulty(AbstractSolver.SolverDifficulty solver, int factor)
solver
- the solver difficultyfactor
- the difficulty factorpublic void setDifficulty(Puzzle.PuzzleDifficulty dif)
dif
- the difficultypublic Puzzle.PuzzleDifficulty getDifficulty()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |