Main Page | Class Hierarchy | Class List | File List | Class Members

Puzzle Class Reference

#include <Puzzle.h>

List of all members.


Detailed Description

A Sudoku Puzzle class.


Public Member Functions

 Puzzle (size_t rows, size_t columns, ifstream &in)
 Constructs this Puzzle with the given number of rows and columns, using the file with the given filestream as input to determine the initial cell values.

 ~Puzzle ()
 Destructor.

 Puzzle (const Puzzle &p)
 Constructs this Puzzle as a deep copy of the given Puzzle.

Puzzleoperator= (const Puzzle &p)
 Assigns the given Puzzle's values to this Puzzle, and returns a reference to this Puzzle.

void setCell (size_t x, size_t y, size_t value)
 Sets the cell having the given coordinates with the given value.

void update ()
 Updates this Puzzle so that cells do not have candidates ruled out by their row, column, or block neighbors.

void saveCandidates (size_t x, size_t y, bool candidates[])
 Saves the candidates of the given cell to the given array.

Cell getCellValue (size_t i, size_t j) const
 Returns the value of the cell at the given coordinates.

size_t getNumCandidates (size_t i, size_t j) const
 Returns the number of candidates for the given Cell.

bool isComplete () const
 Returns true if this Puzzle's cells all have nonzero values.

size_t getRows () const
 Returns the number of rows in this Puzzle.

size_t getColumns () const
 Returns the number of columns in this Puzzle.

size_t getLength () const
 Returns the number of cells along a side in this Puzzle.

bool isValid () const
 Returns true iff this Puzzle is in a valid state.

void print () const
 Prints this Puzzle.

void printCandidates () const
void printCandidates (size_t x, size_t y) const
void debug () const
 Dumps the state of this puzzle.


Private Types

typedef unsigned short int Cell
 For holding cell values, candidate counts, and boolean values determining whether a given value is possible for that cell.


Private Member Functions

void init (Cell ***cells)
 Initializes the cell array.

void setup (ifstream &in)
 Sets up the cell array to have the values read from the given input stream.

void cleanup ()
 Deletes memory allocated for cell array.

bool pruneRow (size_t i, size_t j)
 Given the value of the cell with the given coordinates, removes candidates from each of the cell's row neighbors having that value.

bool pruneColumn (size_t i, size_t j)
 Given the value of the cell with the given coordinates, removes candidates from each of the cell's column neighbors having that value.

bool pruneBlock (size_t i, size_t j)
 Given the value of the cell with the given coordinates, removes candidates from each of the cell's block neighbors having that value.

bool pruneCell (size_t i, size_t j, const Cell &value)
 Removes the candidate with the given value from the candidates of the cell with the given coordinates.

bool isValidRowOrColumn (size_t i, bool row) const
 Returns true iff the given row or column in this Puzzle is in a valid state.

bool isValidRow (size_t i) const
 Returns true iff the given row in this Puzzle is in a valid state.

bool isValidColumn (size_t i) const
 Returns true iff the given column in this Puzzle is in a valid state.

bool isValidBlock (size_t i) const
 Returns true iff the given block in this Puzzle is in a valid state.


Private Attributes

Cell *** cells_
 A 3-d array of cells, for keeping track of the puzzle's values and possible candidates for each cell.

size_t assignedCells_
 The number of cells that have been assigned nonzero values in this Puzzle.

size_t rows_
 The number of rows in this Puzzle.

size_t columns_
 The number of columns in this Puzzle.

size_t length_
 The length of a side in this Puzzle.

size_t VALUE
 A constant indexing the cell's value.

size_t NUM_CANDS
 A constant indexing the number of possible values this cell can have.

char * exceptionMsg
 A string announcing that an error has occurred.


Member Function Documentation

bool Puzzle::isValidRowOrColumn size_t  i,
bool  row
const [private]
 

Returns true iff the given row or column in this Puzzle is in a valid state.

The boolean variable tells whether to look down a column or across a row.

bool Puzzle::pruneCell size_t  i,
size_t  j,
const Cell value
[private]
 

Removes the candidate with the given value from the candidates of the cell with the given coordinates.

If the cell then has only one remaining candidate, the cell is set to have the value of that candidate.

void Puzzle::setCell size_t  x,
size_t  y,
size_t  value
 

Sets the cell having the given coordinates with the given value.

Throws a runtime_exception when the value is outside the accepted range, or when the coordinates are outside the accepted range.


The documentation for this class was generated from the following files:
Generated on Tue Aug 2 12:58:48 2005 for Generalized Sudoku Puzzle Solver by doxygen 1.3.4