sudoku
Class Field

java.lang.Object
  extended by sudoku.Field

public class Field
extends java.lang.Object

The Sudoku playing field and methods to evaluate and manipulate it.


Field Summary
static int COLUMNS
          Number of columns in playing field
static int LOCATIONS
          Number of locations in playing field
static int MAXVAL
          Maximum value in square (minimum is 1, and 0 indicates vacant
 int[] possibles
          Bit array of possible values for this location, if not assigned.
 int[] possiblesCount
          Count of possible values for this location, if not assigned
static int QUADRANTS
          Number of quadrants
static int ROWS
          Number of rows in playing field
 int[] squares
          Playing location and value 1-9 assigned.
 
Constructor Summary
Field()
          Create a new playing Field with no locations assigned.
Field(Field f)
          Create a Field that is a copy of an existing Field.
 
Method Summary
 void calculatePossibles()
          Fills in possibles, possiblesCount, and _hintValues arrays based.
static int coordinatesToIndex(int x, int y)
          Convert row and column numbers to a location number
 void fillAt(int index, int value)
          Fill in a location.
 GameState getState()
          Examine current field to determine if there are available moves.
 int hints()
          Calculate the total number of hints (locations with values).
 Hints hintValue(int i)
          The hint value is one of NO_HINT, ONE_HINT, or TWO_HINT and should be displayed if hints are enabled.
static int indexToColumn(int index)
          Convert a location number to a column number
static int indexToQuadrant(int index)
          Convert a location number to a quadrant number
static int indexToRow(int index)
          Convert a location number to a row number
 boolean isLocked(int i)
          A locked location is presumably one that was initially hinted.
 void lockArray(boolean flag)
          Either locks locations that have values or unlocks all locations
 void setMarks()
          Correct the mark values after changing or removing a value in a location.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAXVAL

public static final int MAXVAL
Maximum value in square (minimum is 1, and 0 indicates vacant

See Also:
Constant Field Values

ROWS

public static final int ROWS
Number of rows in playing field

See Also:
Constant Field Values

COLUMNS

public static final int COLUMNS
Number of columns in playing field

See Also:
Constant Field Values

LOCATIONS

public static final int LOCATIONS
Number of locations in playing field

See Also:
Constant Field Values

QUADRANTS

public static final int QUADRANTS
Number of quadrants

See Also:
Constant Field Values

possibles

public int[] possibles
Bit array of possible values for this location, if not assigned.


possiblesCount

public int[] possiblesCount
Count of possible values for this location, if not assigned


squares

public int[] squares
Playing location and value 1-9 assigned. Is 0 if not assigned.

Constructor Detail

Field

public Field()
Create a new playing Field with no locations assigned. CalculatePossibles should be called before using.


Field

public Field(Field f)
Create a Field that is a copy of an existing Field.

Parameters:
f - Field to copy
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hints

public int hints()
Calculate the total number of hints (locations with values).

Returns:
number of hints

indexToRow

public static int indexToRow(int index)
Convert a location number to a row number

Parameters:
index - location
Returns:
row

indexToColumn

public static int indexToColumn(int index)
Convert a location number to a column number

Parameters:
index - location
Returns:
column

indexToQuadrant

public static int indexToQuadrant(int index)
Convert a location number to a quadrant number

Parameters:
index - location
Returns:
quadrant

coordinatesToIndex

public static int coordinatesToIndex(int x,
                                     int y)
Convert row and column numbers to a location number

Parameters:
x - column
y - row
Returns:
location

fillAt

public void fillAt(int index,
                   int value)
Fill in a location. Result is valid only if originally unfilled and new value is 1-9. Otherwise call setMarks to correct mark values.

Parameters:
index - location to fill
value - value to fill location with

setMarks

public void setMarks()
Correct the mark values after changing or removing a value in a location.


lockArray

public void lockArray(boolean flag)
Either locks locations that have values or unlocks all locations

Parameters:
flag - true to lock, false to unlock

calculatePossibles

public void calculatePossibles()
Fills in possibles, possiblesCount, and _hintValues arrays based. Execute after fillAt/setMarks and before determining next move.


getState

public GameState getState()
Examine current field to determine if there are available moves.

Returns:
SUCCESS if the field is completely filled, FAIL if not filled but there are no possible moves, or IN_PROGRESS if there are possible moves.

isLocked

public boolean isLocked(int i)
A locked location is presumably one that was initially hinted. Locking changes the way the location is to be displayed, and locked locations locations cannot be changed.

Parameters:
i - location index
Returns:
locked flag

hintValue

public Hints hintValue(int i)
The hint value is one of NO_HINT, ONE_HINT, or TWO_HINT and should be displayed if hints are enabled. Hint values are calculated in calculatePossibles.

Parameters:
i - location index
Returns:
NO_HINT, ONE_HINT, or TWO_HINT