com.act365.sudoku
Interface IStrategy

All Known Implementing Classes:
FirstAvailable, LeastCandidatesCell, LeastCandidatesHybrid, LeastCandidatesNumber, MostCandidates

public interface IStrategy

A strategy is an algorithm that solves Su Doku problems. At each timestep, a strategy has to calculate a 'best' move (x,y):=z, which means that it will almost certainly choose to iterate over a three-dimensional space. Most strategies follow a least-candidates principle, which means that they will iterate over two dimensions (not necessarily x and y - any two abstract dimensions of the solver's choice will do) and select the value that gives rise to the smallest number of candidates in the third dimension.


Method Summary
 boolean explainsReasoning()
          Indicates whether the strategy explains its reasoning.
 int findCandidates()
          Finds a set of candidates for the next move.
 java.lang.String getBestReason()
          Returns the reason behind the best candidate move.
 int getBestValue()
          Returns the value of the best candidate move.
 int getBestX()
          Returns the x-coordinate of the best candidate move.
 int getBestY()
          Returns the y-coordinate of the best candidate move.
 int getLastWrittenMove()
          Returns the number of moves made at the last point where two or more alternatives had existed.
 int getNumberOfCandidates()
          Returns the number of candidates generated by findCandidates().
 java.lang.String getReason(int move)
          Returns all the reasoning behind the thread.
 java.lang.String getReasonCandidate(int n)
          Returns the reason behind the candidate generated by findCandidates().
 int getScore()
          Returns a measure of the confidence the strategy has in its candidates.
 int getThreadLength()
          Returns the number of moves stored on the thread.
 int getThreadX(int move)
          Returns the x-coordinate of the move at the given thread position.
 int getThreadY(int move)
          Returns the y-coordinate of the move at the given thread position.
 int getValueCandidate(int n)
          Returns the value-coordinates of the candidates generated by findCandidates().
 int getXCandidate(int n)
          Returns the x-coordinates of the candidates generated by findCandidates().
 int getYCandidate(int n)
          Returns the y-coordinates of the candidates generated by findCandidates().
 void reset()
          Resets the grid to its state before the strategy had been invoked.
 void reset(int move)
          Resets the grid to its state before the given move.
 void selectCandidate()
          Selects a single candidate from the set generated by findCandidates(), which it stores internally to be accessed by the functions getBestX(), getBestY() and getBestValue().
 void setCandidate()
          Sets the move chosen by selectCandidate() in the grid.
 void setup(Grid grid)
          Sets up the strategy state variables to solve the given grid.
 java.lang.String toString()
          Lists the moves in the current thread.
 boolean unwind(int newNMoves, boolean reset)
          Unwinds the most recent move and reverts the state grids.
 void updateState(int x, int y, int value, java.lang.String reason, boolean writeState)
          Tells the strategy to update its internal state variables to account for the move (x,y):= value.
 

Method Detail

setup

public void setup(Grid grid)
           throws java.lang.Exception
Sets up the strategy state variables to solve the given grid.

Parameters:
grid - grid to be solved
Throws:
java.lang.Exception

findCandidates

public int findCandidates()
Finds a set of candidates for the next move. The candidates are stored internally to be accessed by the functions getXCandidates(), getYCandidates() and getValueCandidates(). The function does not alter the grid or the stack. The 'score' is set to signal the confidence in the candidates.

Returns:
number of candidates
See Also:
getXCandidate(int), getYCandidate(int), getValueCandidate(int), getReasonCandidate(int)

getScore

public int getScore()
Returns a measure of the confidence the strategy has in its candidates.


selectCandidate

public void selectCandidate()
Selects a single candidate from the set generated by findCandidates(), which it stores internally to be accessed by the functions getBestX(), getBestY() and getBestValue().

See Also:
findCandidates(), getBestX(), getBestY(), getBestValue(), getBestReason()

setCandidate

public void setCandidate()
Sets the move chosen by selectCandidate() in the grid.

See Also:
selectCandidate()

updateState

public void updateState(int x,
                        int y,
                        int value,
                        java.lang.String reason,
                        boolean writeState)
                 throws java.lang.Exception
Tells the strategy to update its internal state variables to account for the move (x,y):= value.

Parameters:
writeState - whether the updated state should be written to the stack
Throws:
java.lang.Exception

unwind

public boolean unwind(int newNMoves,
                      boolean reset)
Unwinds the most recent move and reverts the state grids.

Parameters:
newNMoves - the point to which the stack should unwind
reset - whether to erase intervening moves from the grid
Returns:
whether moves remain to be unwound further

reset

public void reset()
Resets the grid to its state before the strategy had been invoked.


reset

public void reset(int move)
Resets the grid to its state before the given move.


getBestX

public int getBestX()
Returns the x-coordinate of the best candidate move.


getBestY

public int getBestY()
Returns the y-coordinate of the best candidate move.


getBestValue

public int getBestValue()
Returns the value of the best candidate move.


getBestReason

public java.lang.String getBestReason()
Returns the reason behind the best candidate move.


getNumberOfCandidates

public int getNumberOfCandidates()
Returns the number of candidates generated by findCandidates().

See Also:
findCandidates()

getXCandidate

public int getXCandidate(int n)
Returns the x-coordinates of the candidates generated by findCandidates().

See Also:
findCandidates()

getYCandidate

public int getYCandidate(int n)
Returns the y-coordinates of the candidates generated by findCandidates().

See Also:
findCandidates()

getValueCandidate

public int getValueCandidate(int n)
Returns the value-coordinates of the candidates generated by findCandidates().

See Also:
findCandidates()

getReasonCandidate

public java.lang.String getReasonCandidate(int n)
Returns the reason behind the candidate generated by findCandidates().

See Also:
findCandidates()

getThreadLength

public int getThreadLength()
Returns the number of moves stored on the thread.


getThreadX

public int getThreadX(int move)
Returns the x-coordinate of the move at the given thread position.


getThreadY

public int getThreadY(int move)
Returns the y-coordinate of the move at the given thread position.


getReason

public java.lang.String getReason(int move)
Returns all the reasoning behind the thread.


explainsReasoning

public boolean explainsReasoning()
Indicates whether the strategy explains its reasoning.


getLastWrittenMove

public int getLastWrittenMove()
Returns the number of moves made at the last point where two or more alternatives had existed.


toString

public java.lang.String toString()
Lists the moves in the current thread.