smithers.logicpuzzles
Class Slitherlink

java.lang.Object
  extended by smithers.logicpuzzles.Slitherlink
All Implemented Interfaces:
Puzzle

public class Slitherlink
extends java.lang.Object
implements Puzzle

Represents a slitherlink puzzle.


Constructor Summary
Slitherlink(int[][] clues)
          Constructs a puzzle from a grid of clues.
Slitherlink(int height, int width)
          Constructs a blank puzzle of the specified size.
 
Method Summary
 int getClue(int row, int column)
          Gets the clue for the specified cell.
 int getHeight()
          Gets the height of the puzzle.
 int getWidth()
          Gets the width of the puzzle.
 boolean isMutable()
          Checks whether this puzzle can be modified.
static Slitherlink load(java.io.File file)
          Loads a puzzle from a file.
static void main(java.lang.String[] args)
           
 Slitherlink makeImmutableCopy()
          Creates a copy of this puzzle which cannot be modified further.
 void save(java.io.File file)
          Saves the puzzle to a file.
 void setClue(int row, int column, int clue)
          Sets the clue for the specified cell.
 java.lang.String toString()
          Generates a String representing the puzzle's clues.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Slitherlink

public Slitherlink(int height,
                   int width)
Constructs a blank puzzle of the specified size.

Parameters:
height - the height of the puzzle
width - the width of the puzzle
Throws:
java.lang.IllegalArgumentException - if the width or height are negative

Slitherlink

public Slitherlink(int[][] clues)
Constructs a puzzle from a grid of clues. The size is inferred from the array.

Parameters:
clues - an array of the clues, with -1 representing no clue
Throws:
java.lang.IllegalArgumentException - if any of the clues are out of range
Method Detail

load

public static Slitherlink load(java.io.File file)
                        throws java.io.IOException
Loads a puzzle from a file.

Parameters:
file - the file to load from
Throws:
java.io.IOException - if one occurs

save

public void save(java.io.File file)
          throws java.io.IOException
Saves the puzzle to a file.

Parameters:
file - the file to save to
Throws:
java.io.IOException - if one occurs

isMutable

public boolean isMutable()
Description copied from interface: Puzzle
Checks whether this puzzle can be modified.

Specified by:
isMutable in interface Puzzle
Returns:
true iff this puzzle is mutable

makeImmutableCopy

public Slitherlink makeImmutableCopy()
Description copied from interface: Puzzle
Creates a copy of this puzzle which cannot be modified further. If a mutable instance of Puzzle is used to construct a State or Solver, the constructer should call this method to get an immutable copy. Copies created by this method should return false to Puzzle.isMutable() and throw ImmutablePuzzleException when a method attempts to modify them.

Specified by:
makeImmutableCopy in interface Puzzle
Returns:
a copy of this puzzle which cannot be modified. This copy should be an instance of the same class as the object which created it.

getHeight

public int getHeight()
Gets the height of the puzzle.

Returns:
the height of the puzzle

getWidth

public int getWidth()
Gets the width of the puzzle.

Returns:
the width of the puzzle

getClue

public int getClue(int row,
                   int column)
Gets the clue for the specified cell.

Parameters:
row - the row index (from 0)
column - the column index (from 0)
Returns:
the clue in the cell in row row, column column, or -1 if the cell is blank

setClue

public void setClue(int row,
                    int column,
                    int clue)
Sets the clue for the specified cell.

Parameters:
row - the row index (from 0)
column - the column index (from 0)
clue - the clue to place in the cell, or -1 to clear

toString

public java.lang.String toString()
Generates a String representing the puzzle's clues. Uses spaces to represent no clue.

Specified by:
toString in interface Puzzle
Overrides:
toString in class java.lang.Object
Returns:
a String representing the puzzle

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException