smithers.logicpuzzles
Class HanjieSolver

java.lang.Object
  extended by smithers.logicpuzzles.HanjieSolver
All Implemented Interfaces:
PuzzleSolver<Hanjie,HanjieState>

public class HanjieSolver
extends java.lang.Object
implements PuzzleSolver<Hanjie,HanjieState>

Class containing a solver for hanjie puzzles. This solver uses methods that only look at a single row or column (called a "line") at once. The solving methods print messages on System.out if they find lines which are impossible.


Constructor Summary
HanjieSolver(Hanjie puzzle)
          Constructs a new solver for the given puzzle.
HanjieSolver(HanjieState puzzleState)
          Constructs a new solver to work from a given state.
 
Method Summary
 int getLastChange()
          Returns the location of the last change.
 boolean getLastWasRow()
          Returns whether or not the last change was a row.
 Hanjie getPuzzle()
          Returns the puzzle which is being solved.
 HanjieState getState()
          Returns the state of the solution attempt.
 void nextLine()
          Advances to the next line (row/column).
 boolean pass()
          Performs a single pass through either the rows or columns.
 boolean solve()
          Attempts to completely solve the puzzle.
 int solveLine()
          Solves the current line (row/column) as much as possible.
 void start()
          Restarts the solving process.
 boolean step()
          Performs a single step in the solving process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HanjieSolver

public HanjieSolver(Hanjie puzzle)
Constructs a new solver for the given puzzle.

Parameters:
puzzle - the puzzle to solve

HanjieSolver

public HanjieSolver(HanjieState puzzleState)
Constructs a new solver to work from a given state.

Parameters:
puzzleState - the puzzle state to work from
Method Detail

getPuzzle

public Hanjie getPuzzle()
Description copied from interface: PuzzleSolver
Returns the puzzle which is being solved.

Specified by:
getPuzzle in interface PuzzleSolver<Hanjie,HanjieState>
Returns:
the Puzzle which this PuzzleSolver relates to.

getState

public HanjieState getState()
Description copied from interface: PuzzleSolver
Returns the state of the solution attempt. This method should always return the same object, with updates being made to it as the solution progresses.

Specified by:
getState in interface PuzzleSolver<Hanjie,HanjieState>
Returns:
the Puzzle which this State relates to.

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.

Specified by:
start in interface PuzzleSolver<Hanjie,HanjieState>

step

public boolean step()
Description copied from interface: PuzzleSolver
Performs a single step in the solving process. This method should do the smallest amount of work which results in a change being made to puzzle.

Specified by:
step in interface PuzzleSolver<Hanjie,HanjieState>
Returns:
true iff a change was made

pass

public boolean pass()
Performs a single pass through either the rows or columns.

Specified by:
pass in interface PuzzleSolver<Hanjie,HanjieState>
Returns:
true iff a change was made

solve

public boolean solve()
Description copied from interface: PuzzleSolver
Attempts to completely solve the puzzle. If the puzzle cannot be solved, this ahould solve as much as is possible. Calling this method should be equivalent to while (this.step()); and to while (this.pass());

Specified by:
solve in interface PuzzleSolver<Hanjie,HanjieState>
Returns:
true iff a change was made

getLastChange

public int getLastChange()
Returns the location of the last change.

Returns:
the row or column index of the last change or -1 if not applicable

getLastWasRow

public boolean getLastWasRow()
Returns whether or not the last change was a row.

Returns:
true iff the last change was a row

nextLine

public void nextLine()
Advances to the next line (row/column).


solveLine

public int solveLine()
Solves the current line (row/column) as much as possible.

Returns:
0 if no change was made, 1 if a hidden change was made, 3 if a change was made or -1 if the line was impossible.