smithers.logicpuzzles
Class Hanjie

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

public class Hanjie
extends java.lang.Object
implements Puzzle

Class to store a hanjie puzzle.


Constructor Summary
Hanjie(int[][] rowClues, int[][] columnClues)
          Constructs a new black and white puzzle from a grid of clues.
Hanjie(int[][] rowClues, int[][] rowColours, int[][] columnClues, int[][] columnColours, java.awt.Color[] colours)
          Constructs a new colour puzzle from a grid of clues.
Hanjie(int height, int width)
          Constructs a new black and white puzzle of the specified size.
Hanjie(int height, int width, java.awt.Color[] colours)
          Constructs a new colour puzzle of the specified size.
 
Method Summary
 void addClue(boolean isRow, int index, int[] clue)
          Adds a clue to a black and white puzzle.
 void addClue(boolean isRow, int index, int[] clue, int[] colour)
          Adds a clue to a colour puzzle.
 int getColourCount()
          Gets the number of colours.
 java.awt.Color[] getColours()
          Gets the colour array.
 int[] getColumnClue(int column)
          Gets the clue for the specified column.
 int[] getColumnColour(int column)
          Gets the colour information for the clue for the specified column.
 int getHeight()
          Gets the height of the puzzle.
 int[] getRowClue(int row)
          Gets the clue for the specified row.
 int[] getRowColour(int row)
          Gets the colour information for the clue for the specified row.
 int getWidth()
          Gets the width of the puzzle.
 boolean hasColour()
          Gets whether or not this puzzle has colour.
 boolean isMutable()
          Checks whether this puzzle can be modified.
static Hanjie load(java.io.File file)
          Loads a hanjie puzzle from a file.
static void main(java.lang.String[] args)
           
 Hanjie makeImmutableCopy()
          Creates a copy of this puzzle which cannot be modified further.
 void save(java.io.File file)
          Saves the puzzle to a file.
 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

Hanjie

public Hanjie(int height,
              int width)
Constructs a new black and white 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

Hanjie

public Hanjie(int height,
              int width,
              java.awt.Color[] colours)
Constructs a new colour puzzle of the specified size.

Parameters:
height - the height of the puzzle
width - the width of the puzzle
colours - the colours, where colours[0] is the blank colour
Throws:
java.lang.IllegalArgumentException - if the width or height are negative

Hanjie

public Hanjie(int[][] rowClues,
              int[][] columnClues)
Constructs a new black and white puzzle from a grid of clues. The size is inferred from the arrays. Each of the clue arrays should contain an int[] for each row/column, containing the clue for that row/column.

Parameters:
rowClues - the clues for the rows
columnClues - the clues for the columns

Hanjie

public Hanjie(int[][] rowClues,
              int[][] rowColours,
              int[][] columnClues,
              int[][] columnColours,
              java.awt.Color[] colours)
Constructs a new colour puzzle from a grid of clues. The size is inferred from the arrays. The clue and colour arrays must be the same size, and the colours must be positive integers. Each of the clue arrays should contain an int[] for each row/column, containing the clue for that row/column.

Parameters:
rowClues - the clues for the rows
rowColours - the colours for the row clues
columnClues - the clues for the colums
columnColours - the colours for the colum clues
colours - the colours, where colours[0] is the blank colour
Method Detail

load

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

Parameters:
file - the file to load from
Throws:
java.io.IOException - if one occurs
PuzzleFormatException - if the file is not in the right format
See Also:
save(java.io.File)

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
See Also:
load(java.io.File)

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 Hanjie 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

getRowClue

public int[] getRowClue(int row)
Gets the clue for the specified row.

Parameters:
row - the row index (starting from 0)
Returns:
the clue for the rowth row

getRowColour

public int[] getRowColour(int row)
Gets the colour information for the clue for the specified row. Throws an exception if the puzzle does not have colour.

Parameters:
row - the row index (starting from 0)
Returns:
the colours for the clue for the rowth row

getColumnClue

public int[] getColumnClue(int column)
Gets the clue for the specified column.

Parameters:
column - the column index (starting from 0)
Returns:
the clue for the columnth column

getColumnColour

public int[] getColumnColour(int column)
Gets the colour information for the clue for the specified column. Throws an exception if the puzzle does not have colour.

Parameters:
column - the column index (starting from 0)
Returns:
the colours for the clue for the columnth column

hasColour

public boolean hasColour()
Gets whether or not this puzzle has colour.

Returns:
true iff this is a colour puzzle

getColourCount

public int getColourCount()
Gets the number of colours.

Returns:
the number of colours, or 2 if this puzzle is black and white

getColours

public java.awt.Color[] getColours()
Gets the colour array.

Returns:
the colours, or null if this puzzle is black and white

addClue

public void addClue(boolean isRow,
                    int index,
                    int[] clue)
Adds a clue to a black and white puzzle. The clue is an int[] specifying the clue for an enitire row/column. To add a clue to a colour puzzle, use addClue(boolean, int, int[], int[]).

Parameters:
isRow - true if the clue is for a row, false for a column
index - the position of the clue
clue - the clue to add
See Also:
addClue(boolean, int, int[], int[])

addClue

public void addClue(boolean isRow,
                    int index,
                    int[] clue,
                    int[] colour)
Adds a clue to a colour puzzle. The clue is 2 int[]s specifying the clue for an enitire row/column. The clue and colour arguments should have the same length. To add a clue to a black and white puzzle, use addClue(boolean, int, int[]).

Parameters:
isRow - true if the clue is for a row, false for a column
index - the position of the clue
clue - the clue to add
colour - the colours of the clue
See Also:
addClue(boolean, int, int[])

toString

public java.lang.String toString()
Generates a String representing the puzzle's clues.

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