com.act365.sudoku
Class LeastCandidatesHybrid

java.lang.Object
  extended bycom.act365.sudoku.StrategyBase
      extended bycom.act365.sudoku.LeastCandidatesHybrid
All Implemented Interfaces:
IStrategy

public class LeastCandidatesHybrid
extends StrategyBase
implements IStrategy

LeastCandidatesHybrid combines the Least Candidates Cell and Least Candidates Number strategies.


Constructor Summary
LeastCandidatesHybrid(boolean randomize, boolean explain)
          Sets up a LeastCandidatesHybrid I strategy with an optional random element.
LeastCandidatesHybrid(boolean randomize, boolean checkInvulnerable, boolean useAllLogicalMethods, boolean explain)
          Sets up a LeastCandidatesHybrid II strategy with an optional random element.
 
Method Summary
 int findCandidates()
          Finds candidates for the next move.
 int getLastWrittenMove()
          Determines the last move for which two or more alternatives existed.
 java.lang.String printState(int stateType)
          Prints the current state grid of the given type.
 void setup(Grid grid)
          Sets up the strategy to solve the given grid.
 java.lang.String toString()
          Dumps the thread to the given output stream.
 boolean unwind(int newNMoves, boolean reset, boolean eliminate)
          Unwind the stack.
 boolean updateState(int x, int y, int value, java.lang.String reason, boolean writeState)
          Updates state variables.
 
Methods inherited from class com.act365.sudoku.StrategyBase
explainsReasoning, getBestReason, getBestValue, getBestX, getBestY, getNumberOfCandidates, getReason, getReasonCandidate, getScore, getThreadLength, getThreadX, getThreadY, getValueCandidate, getXCandidate, getYCandidate, reset, reset, selectCandidate, setCandidate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.act365.sudoku.IStrategy
explainsReasoning, getBestReason, getBestValue, getBestX, getBestY, getNumberOfCandidates, getReason, getReasonCandidate, getScore, getThreadLength, getThreadX, getThreadY, getValueCandidate, getXCandidate, getYCandidate, reset, reset, selectCandidate, setCandidate
 

Constructor Detail

LeastCandidatesHybrid

public LeastCandidatesHybrid(boolean randomize,
                             boolean checkInvulnerable,
                             boolean useAllLogicalMethods,
                             boolean explain)
Sets up a LeastCandidatesHybrid II strategy with an optional random element.

Parameters:
randomize - whether the final candidates should be chosen randomly from its peers
checkInvulnerable - indicates whether the moves should be post-filtered using the Invulnerable state grid.
useAllLogicalMethods - whether the solver should look for X-Wings and Nishio
explain - whether explanatory debug should be produced

LeastCandidatesHybrid

public LeastCandidatesHybrid(boolean randomize,
                             boolean explain)
Sets up a LeastCandidatesHybrid I strategy with an optional random element.

Method Detail

setup

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

Specified by:
setup in interface IStrategy
Throws:
java.lang.Exception
See Also:
IStrategy.setup(Grid)

findCandidates

public int findCandidates()
Finds candidates for the next move. The LeastCandidatesCell search is performed before the LeastCandidatesNumber search because it will find a result much quicker in the very common case that very few candidates exist.

Specified by:
findCandidates in interface IStrategy
Returns:
number of candidates
See Also:
IStrategy.findCandidates()

updateState

public boolean updateState(int x,
                           int y,
                           int value,
                           java.lang.String reason,
                           boolean writeState)
                    throws java.lang.Exception
Updates state variables.

Specified by:
updateState in interface IStrategy
Overrides:
updateState in class StrategyBase
Throws:
java.lang.Exception
See Also:
IStrategy.updateState(int,int,int,String,boolean)

unwind

public boolean unwind(int newNMoves,
                      boolean reset,
                      boolean eliminate)
Unwind the stack.

Specified by:
unwind in interface IStrategy
Overrides:
unwind in class StrategyBase
See Also:
IStrategy.unwind(int,boolean,boolean)

getLastWrittenMove

public int getLastWrittenMove()
Determines the last move for which two or more alternatives existed.

Specified by:
getLastWrittenMove in interface IStrategy
Overrides:
getLastWrittenMove in class StrategyBase

printState

public java.lang.String printState(int stateType)
Prints the current state grid of the given type.


toString

public java.lang.String toString()
Dumps the thread to the given output stream.

Specified by:
toString in interface IStrategy
Overrides:
toString in class StrategyBase