smithers.logicpuzzles
Class MosaicSolver

java.lang.Object
  extended by smithers.logicpuzzles.AbstractPuzzleSolver<Mosaic,MosaicState>
      extended by smithers.logicpuzzles.MosaicSolver
All Implemented Interfaces:
PuzzleSolver<Mosaic,MosaicState>

public class MosaicSolver
extends AbstractPuzzleSolver<Mosaic,MosaicState>

Solves mosaic puzzles. The method employed here uses two modes: simple logic and advanced logic. Simple logic attempts to solve the puzzle only looking at one clue at a time, whereas advanced logic looks at up to two clues at once.


Field Summary
 
Fields inherited from class smithers.logicpuzzles.AbstractPuzzleSolver
puzzle, state
 
Constructor Summary
MosaicSolver(Mosaic puzzle)
          Creates a new solver for the specified puzzle.
MosaicSolver(Mosaic puzzle, boolean advanced)
          Creates a new solver for the specified puzzle.
MosaicSolver(MosaicState state)
          Creates a new solver to work from the specified state.
MosaicSolver(MosaicState state, boolean advanced)
          Creates a new solver to work from the specified state.
 
Method Summary
 int[] getLastChange()
          Finds the last change that was made to the puzzle.
 MosaicState makeState(Mosaic puzzle)
          Makes a new state for the specified puzzle.
 boolean nextStep()
          Advances to the next step of solving the puzzle.
 int solveStep()
          Solves the current clue as much as possible.
 void start()
          Restarts the solving process.
 
Methods inherited from class smithers.logicpuzzles.AbstractPuzzleSolver
getPuzzle, getState, pass, solve, step
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MosaicSolver

public MosaicSolver(Mosaic puzzle)
Creates a new solver for the specified puzzle.

Parameters:
puzzle - the puzzle to solve

MosaicSolver

public MosaicSolver(MosaicState state)
Creates a new solver to work from the specified state.

Parameters:
state - the puzzle state to work from

MosaicSolver

public MosaicSolver(Mosaic puzzle,
                    boolean advanced)
Creates a new solver for the specified puzzle.

Parameters:
puzzle - the puzzle to solve
advanced - whether or not to use advanced logic

MosaicSolver

public MosaicSolver(MosaicState state,
                    boolean advanced)
Creates a new solver to work from the specified state.

Parameters:
state - the puzzle state to work from
advanced - whether or not to use advanced logic
Method Detail

makeState

public MosaicState makeState(Mosaic puzzle)
Description copied from class: AbstractPuzzleSolver
Makes a new state for the specified puzzle. Usually this will simply call a constructor which takes puzzle as an argument.

Specified by:
makeState in class AbstractPuzzleSolver<Mosaic,MosaicState>
Parameters:
puzzle - the puzzle to create a state for
Returns:
a state for the given puzzle

start

public void start()
Description copied from interface: PuzzleSolver
Restarts the solving process. This method should set the solver's internal status to reflect any changes made to the state.


getLastChange

public int[] getLastChange()
Finds the last change that was made to the puzzle. If the last call to step() or pass() resulted in no change, this returns null.

Returns:
an array containing the row and column indices of the clues used

nextStep

public boolean nextStep()
Description copied from class: AbstractPuzzleSolver
Advances to the next step of solving the puzzle.

Specified by:
nextStep in class AbstractPuzzleSolver<Mosaic,MosaicState>
Returns:
true iff the solver has started a new 'pass'

solveStep

public int solveStep()
Solves the current clue as much as possible. This will first check if anything can be deduced from the current clue and then move on (if advanced logic is enabled) to deductions from this clue and another clue tested earlier in the pass.

Specified by:
solveStep in class AbstractPuzzleSolver<Mosaic,MosaicState>
Returns:
2 if a change was made, 0 otherwise