uk.co.keang.sudoku.solver
Class AbstractSolver

java.lang.Object
  extended by uk.co.keang.sudoku.solver.AbstractSolver
Direct Known Subclasses:
AssociatedPairsSolver, AsymmetricGroupsSolver, BruteForceSolver, FixedLineSolver, HiddenGroupsSolver, KnownValueSolver, MatchingGroupsSolver, SplitGroupsSolver, ZeroChoiceSolver

public abstract class AbstractSolver
extends java.lang.Object

An abstract sudouku solver pattern

Author:
A.G.Docherty

Nested Class Summary
static class AbstractSolver.SolverDifficulty
           
 
Field Summary
protected  int found
           
protected  Puzzle.Cell[][] hGrid
           
protected  Puzzle puzzle
           
 
Constructor Summary
AbstractSolver(Puzzle p, int factor, AbstractSolver.SolverDifficulty dif)
          Constructs a solver
 
Method Summary
 void addSolverListener(SolverListener l)
          Adds a solver listener.
abstract  int findSolutions()
          Runs the solver once to try to resolve individual squares
protected  void fireSolutionEvent(SolutionEvent event)
          fires the possibilities reduced event to all listeners
 int getDifficultyFactor()
          Gets a difficulty factor for this solver where the higher the number the higher the level of expertise required to solve the puzzle
 AbstractSolver.SolverDifficulty getSolverDifficulty()
          Gets the minimum difficulty of this solver
protected  boolean hasSolverListeners()
          True if there are registered solver listeners
protected  Puzzle.Cell removeAllFromSet(Puzzle.Cell possibleVals, Puzzle.Cell removeVals)
          Removes the values from the possible values
 void removeAllSolverListeners()
          Removes all the solver listeners
 void removeSolverListener(SolverListener l)
          Removes the solver listener
protected  Puzzle.Cell retainAllInSet(Puzzle.Cell possibleVals, Puzzle.Cell retainVals)
          Retains these values removing all other possible values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

found

protected int found

puzzle

protected final Puzzle puzzle

hGrid

protected final Puzzle.Cell[][] hGrid
Constructor Detail

AbstractSolver

AbstractSolver(Puzzle p,
               int factor,
               AbstractSolver.SolverDifficulty dif)
Constructs a solver

Parameters:
hGrid -
Method Detail

findSolutions

public abstract int findSolutions()
                           throws IllegalGridException
Runs the solver once to try to resolve individual squares

Returns:
the number of solutions found
Throws:
IllegalGridException

getSolverDifficulty

public AbstractSolver.SolverDifficulty getSolverDifficulty()
Gets the minimum difficulty of this solver

Returns:
the difficulty

addSolverListener

public void addSolverListener(SolverListener l)
Adds a solver listener.

Parameters:
l - - the listener to add

removeSolverListener

public void removeSolverListener(SolverListener l)
Removes the solver listener

Parameters:
l - - the listener to remove

removeAllSolverListeners

public void removeAllSolverListeners()
Removes all the solver listeners

Parameters:
l - - the listener to remove

hasSolverListeners

protected boolean hasSolverListeners()
True if there are registered solver listeners

Returns:
true of there are solver listeners

fireSolutionEvent

protected void fireSolutionEvent(SolutionEvent event)
fires the possibilities reduced event to all listeners


removeAllFromSet

protected final Puzzle.Cell removeAllFromSet(Puzzle.Cell possibleVals,
                                             Puzzle.Cell removeVals)
Removes the values from the possible values

Parameters:
possibleVals - the set of possible values
removeVals - the values to remove
Returns:
the values removed from this set

retainAllInSet

protected final Puzzle.Cell retainAllInSet(Puzzle.Cell possibleVals,
                                           Puzzle.Cell retainVals)
Retains these values removing all other possible values

Parameters:
possibleVals - the set of possible values
removeVals - the values to remove
Returns:
the values removed from this set

getDifficultyFactor

public int getDifficultyFactor()
Gets a difficulty factor for this solver where the higher the number the higher the level of expertise required to solve the puzzle

Returns:
the difficulty factor