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

Puzzle.h

00001 #include <iostream.h>
00002 #include <fstream.h>
00003 using namespace std;
00004 
00005 #ifndef PUZZLE_H
00006 #define PUZZLE_H
00007 
00011 class Puzzle {
00012 
00013   private:
00014 
00020     typedef unsigned short int Cell;
00021 
00026     Cell ***cells_;
00027 
00032     size_t assignedCells_;
00033 
00037     size_t rows_;
00038 
00042     size_t columns_;
00043 
00047     size_t length_;
00048 
00052     size_t VALUE;
00053 
00057     size_t NUM_CANDS;
00058 
00062     char *exceptionMsg;
00063 
00067     void init(Cell*** cells);
00068 
00073     void setup(ifstream &in);
00074 
00078     void cleanup();
00079 
00085     bool pruneRow(size_t i, size_t j);
00086     
00092     bool pruneColumn(size_t i, size_t j);
00093 
00099     bool pruneBlock(size_t i, size_t j);
00100 
00107     bool pruneCell(size_t i, size_t j, const Cell &value);
00108 
00114     bool isValidRowOrColumn(size_t i, bool row) const;
00115 
00119     bool isValidRow(size_t i) const;
00120 
00124     bool isValidColumn(size_t i) const;
00125 
00129     bool isValidBlock(size_t i) const;
00130 
00131   public:
00132 
00138     Puzzle(size_t rows, size_t columns, ifstream &in);
00139 
00143     ~Puzzle();
00144 
00148     Puzzle(const Puzzle &p);
00149 
00154     Puzzle& operator=(const Puzzle &p);
00155 
00161     void setCell(size_t x, size_t y, size_t value);
00162 
00167     void update();
00168 
00172     void saveCandidates(size_t x, size_t y, bool candidates[]);
00173 
00177     Cell getCellValue(size_t i, size_t j) const { return cells_[i][j][VALUE]; }
00178     
00182     size_t getNumCandidates(size_t i, size_t j) const { return cells_[i][j][NUM_CANDS]; }
00183 
00187     bool isComplete() const { return assignedCells_ == (length_ * length_); }
00188 
00192     size_t getRows() const { return rows_; }
00193 
00197     size_t getColumns() const { return columns_; }
00198 
00202     size_t getLength() const { return length_; }
00203 
00207     bool isValid() const;
00208 
00212     void print() const;
00213 
00214     void printCandidates() const;
00215 
00216     void printCandidates(size_t x, size_t y) const;
00217 
00221     void debug() const;
00222 };
00223 
00224 #endif

Generated on Tue Aug 2 12:58:47 2005 for Generalized Sudoku Puzzle Solver by doxygen 1.3.4