smithers.logicpuzzles
Class SlitherlinkState

java.lang.Object
  extended by smithers.logicpuzzles.SlitherlinkState
All Implemented Interfaces:
PuzzleState<Slitherlink>

public class SlitherlinkState
extends java.lang.Object
implements PuzzleState<Slitherlink>

Represents a state of a slitherlink puzzle. Note: isSolved() is not implemented yet.


Constructor Summary
SlitherlinkState(Slitherlink puzzle)
          Constructs a state for the specified puzzle.
 
Method Summary
 void clearState()
          Clears the state of the puzzle.
 int getHorizontalState(int row, int column)
          Gets the state of the specified horizontal wall.
 Slitherlink getPuzzle()
          Returns the puzzle which this is a state of.
 int getVerticalState(int row, int column)
          Gets the state of the specified vertical wall.
 boolean isSolved()
          Determines whether or not the puzzle has been completely solved.
 void setHorizontalState(int row, int column, int state)
          Adds or removes a horizontal wall.
 void setVerticalState(int row, int column, int state)
          Adds or removes a vertical wall.
 java.lang.String toString()
          Generates a String representing the current situation of the puzzle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SlitherlinkState

public SlitherlinkState(Slitherlink puzzle)
Constructs a state for the specified puzzle.

Parameters:
puzzle - the puzzle that this is a state of
Method Detail

getPuzzle

public Slitherlink getPuzzle()
Description copied from interface: PuzzleState
Returns the puzzle which this is a state of.

Specified by:
getPuzzle in interface PuzzleState<Slitherlink>
Returns:
the Puzzle which this PuzzleState relates to.

getHorizontalState

public int getHorizontalState(int row,
                              int column)
Gets the state of the specified horizontal wall.

Parameters:
row - the row index (from 0)
column - the column index (from 0)
Returns:
1 if the wall is present, 0 if not present, or -1 if unknown

getVerticalState

public int getVerticalState(int row,
                            int column)
Gets the state of the specified vertical wall.

Parameters:
row - the row index (from 0)
column - the column index (from 0)
Returns:
1 if the wall is present, 0 if not present, or -1 if unknown

setHorizontalState

public void setHorizontalState(int row,
                               int column,
                               int state)
Adds or removes a horizontal wall.

Parameters:
row - the row index (from 0)
column - the column index (from 0)
state - 1 to add the wall, 0 to remove, or -1 to set unknown

setVerticalState

public void setVerticalState(int row,
                             int column,
                             int state)
Adds or removes a vertical wall.

Parameters:
row - the row index (from 0)
column - the column index (from 0)
state - 1 to add the wall, 0 to remove, or -1 to set unknown

clearState

public void clearState()
Clears the state of the puzzle.


isSolved

public boolean isSolved()
Description copied from interface: PuzzleState
Determines whether or not the puzzle has been completely solved.

Specified by:
isSolved in interface PuzzleState<Slitherlink>
Returns:
true iff the puzzle has been completely solved

toString

public java.lang.String toString()
Generates a String representing the current situation of the puzzle. Represents a wall as '|' or '-', corners as '+', no wall as ' ', and unsure as '?'.

Specified by:
toString in interface PuzzleState<Slitherlink>
Overrides:
toString in class java.lang.Object
Returns:
a String representing the state