com.act365.sudoku
Class MaskFactory

java.lang.Object
  extended bycom.act365.sudoku.MaskFactory
All Implemented Interfaces:
java.util.Enumeration

public class MaskFactory
extends java.lang.Object
implements java.util.Enumeration

The MaskFactory class iterates through the complete set of possible masks (a mask is a boolean[][] array that indicates whether the corresponding cells in Su Doku grids should have their initial values exposed) of a given size. The masks are guaranteed to have rotational symmetry of order two, as demanded by the Su Doku puzzle. No mask will be a reflection of a mask that appeared earlier in the sequence.


Constructor Summary
MaskFactory(int cellsInRow, int filledCells)
          Creates a new MaskFactory.
MaskFactory(int cellsInRow, int filledCells, boolean randomize)
          Creates a new MaskFactory.
MaskFactory(int cellsInRow, int filledCells, boolean[][] mask)
          Creates a new MaskFactory.
MaskFactory(int cellsInRow, int filledCells, int boxesAcross)
          Creates a new MaskFactory.
MaskFactory(int cellsInRow, int filledCells, int[] gaps)
          Creates a new MaskFactory.
MaskFactory(java.lang.String s)
          Creates a new MaskFactory.
 
Method Summary
 int getCellsInRow()
          Returns the mask dimension.
 int getFilledCells()
          Returns the number of filled cells in the mask.
 boolean hasMoreElements()
          Indicates whether the MaskFactory has cycled through the complete set of all possible masks.
static boolean isSymmetricLeftRight(boolean[][] mask)
          Determines whether the mask is symmetric in a line that extends from the left centre of the grid to the right centre.
static boolean isSymmetricOrder2(boolean[][] mask)
          Determines whether a mask has rotational symmetry of order 2.
static boolean isSymmetricOrder4(boolean[][] mask)
          Determines whether a mask has rotational symmetry of order 4.
static boolean isSymmetricTopBottom(boolean[][] mask)
          Determines whether the mask is symmetric in a line that extends from the top centre of the grid to the bottom centre.
static boolean isSymmetricTopLeftBottomRight(boolean[][] mask)
          Determines whether the mask is symmetric in a line that extends from the top-left corner of the grid to the bottom-right.
static boolean isSymmetricTopRightBottomLeft(boolean[][] mask)
          Determines whether the mask is symmetric in a line that extends from the top-right corner of the grid to the bottom-left.
static void main(java.lang.String[] args)
          Class test program takes the form MaskFactory [-c cellsInRow] [-r|-i|-a boxes across] [-d] filledCells.
 java.lang.Object nextElement()
          Returns the next mask.
 java.lang.String toString()
          Writes the mask as a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MaskFactory

public MaskFactory(int cellsInRow,
                   int filledCells)
            throws java.lang.Exception
Creates a new MaskFactory. The sequence starts in its natural start position, which is usually some distance from the masks that are likely to lead to successful puzzles.

Parameters:
cellsInRow - size of grid
filledCells - number of true elements to appear in mask
Throws:
java.lang.Exception - thrown if cellsInRow and filledCells are incompatible

MaskFactory

public MaskFactory(int cellsInRow,
                   int filledCells,
                   boolean randomize)
            throws java.lang.Exception
Creates a new MaskFactory. The sequence starts at an optionally random position.

Parameters:
cellsInRow - size of grid
filledCells - number of true elements to appear in mask
randomize - whether the start position should be randomized
Throws:
java.lang.Exception - thrown if cellsInRow and filledCells are incompatible

MaskFactory

public MaskFactory(int cellsInRow,
                   int filledCells,
                   boolean[][] mask)
            throws java.lang.Exception
Creates a new MaskFactory. The sequence starts at the given mask.

Parameters:
cellsInRow - size of grid
filledCells - number of true elements to appear in mask
mask - start mask
Throws:
java.lang.Exception - thrown if cellsInRow and filledCells are incompatible

MaskFactory

public MaskFactory(int cellsInRow,
                   int filledCells,
                   int[] gaps)
            throws java.lang.Exception
Creates a new MaskFactory. The sequence starts at the mask specified by a given gap sequence.

Parameters:
cellsInRow - size of grid
filledCells - number of true elements to appear in mask
gaps - gap sequence that defines the start mask
Throws:
java.lang.Exception - thrown if cellsInRow and filledCells are incompatible

MaskFactory

public MaskFactory(java.lang.String s)
            throws java.lang.Exception
Creates a new MaskFactory. The sequence starts at the mask specified by the string, which should be in the format used by toString().

Parameters:
s - string representation of start mask
Throws:
java.lang.Exception - thrown if cellsInRow and filledCells are incompatible

MaskFactory

public MaskFactory(int cellsInRow,
                   int filledCells,
                   int boxesAcross)
            throws java.lang.Exception
Creates a new MaskFactory. The sequence will start from a mask with uniformly-distributed filled cells.

Parameters:
cellsInRow - size of grid
filledCells - number of true elements to appear in mask
boxesAcross - grid dimension
Throws:
java.lang.Exception - thrown if cellsInRow and filledCells are incompatible
Method Detail

toString

public java.lang.String toString()
Writes the mask as a string.


hasMoreElements

public boolean hasMoreElements()
Indicates whether the MaskFactory has cycled through the complete set of all possible masks.

Specified by:
hasMoreElements in interface java.util.Enumeration

nextElement

public java.lang.Object nextElement()
Returns the next mask. The returned mask will simply be a reference to a member of the MaskFactory object, so the caller might well have to clone.

Specified by:
nextElement in interface java.util.Enumeration

getCellsInRow

public int getCellsInRow()
Returns the mask dimension.


getFilledCells

public int getFilledCells()
Returns the number of filled cells in the mask.


isSymmetricLeftRight

public static boolean isSymmetricLeftRight(boolean[][] mask)
Determines whether the mask is symmetric in a line that extends from the left centre of the grid to the right centre.


isSymmetricTopBottom

public static boolean isSymmetricTopBottom(boolean[][] mask)
Determines whether the mask is symmetric in a line that extends from the top centre of the grid to the bottom centre.


isSymmetricTopLeftBottomRight

public static boolean isSymmetricTopLeftBottomRight(boolean[][] mask)
Determines whether the mask is symmetric in a line that extends from the top-left corner of the grid to the bottom-right.


isSymmetricTopRightBottomLeft

public static boolean isSymmetricTopRightBottomLeft(boolean[][] mask)
Determines whether the mask is symmetric in a line that extends from the top-right corner of the grid to the bottom-left.


isSymmetricOrder2

public static boolean isSymmetricOrder2(boolean[][] mask)
Determines whether a mask has rotational symmetry of order 2.


isSymmetricOrder4

public static boolean isSymmetricOrder4(boolean[][] mask)
Determines whether a mask has rotational symmetry of order 4.


main

public static void main(java.lang.String[] args)
Class test program takes the form MaskFactory [-c cellsInRow] [-r|-i|-a boxes across] [-d] filledCells. When the -a option is stipulated, the factory will ensure that the sequence starts at a mask where the filled cells are distributed evenly across the grid. When -r is selected, the sequence will start at a random position while when -i is selected, the initial mask will be read from standard input. The option -t requests trace output. Defaults are nine cells in a row and no debug.