smithers.logicpuzzles
Class MosaicState

java.lang.Object
  extended by smithers.logicpuzzles.MosaicState
All Implemented Interfaces:
PuzzleState<Mosaic>

public class MosaicState
extends java.lang.Object
implements PuzzleState<Mosaic>

Represents a state of a mosaic puzzle.


Constructor Summary
MosaicState(Mosaic puzzle)
          Constructs a state for the specified puzzle.
 
Method Summary
 void clearState()
          Clears the state of the puzzle.
 Mosaic getPuzzle()
          Returns the puzzle which this is a state of.
 int getState(int row, int column)
          Gets the state of the specified cell.
 boolean isSolved()
          Determines whether or not the puzzle has been completely solved.
 void setState(int row, int column, int state)
          Adds to the attempt at solving the puzzle.
 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

MosaicState

public MosaicState(Mosaic puzzle)
Constructs a state for the specified puzzle.

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

getPuzzle

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

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

getState

public int getState(int row,
                    int column)
Gets the state of the specified cell.

Parameters:
row - the row index (from 0)
column - the column index (from 0)
Returns:
0 if the cell is white, 1 if black, or -1 if unknown

setState

public void setState(int row,
                     int column,
                     int state)
Adds to the attempt at solving the puzzle.

Parameters:
row - the row index (from 0)
column - the column index (from 0)
state - 1 to set coloured, 0 for not coloured, or -1 to reset

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<Mosaic>
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 filled as '#', unfilled as '.' and unsure as ' '.

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